/[escript]/branches/doubleplusgood/dudley/src/NodeMapping.cpp
ViewVC logotype

Contents of /branches/doubleplusgood/dudley/src/NodeMapping.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4332 - (show annotations)
Thu Mar 21 04:21:14 2013 UTC (5 years, 11 months ago) by jfenwick
File size: 2517 byte(s)
like sand though the hourglass
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16 #include "NodeMapping.h"
17 #include "Util.h"
18 #include "esysUtils/mem.h"
19
20 Dudley_NodeMapping *Dudley_NodeMapping_alloc(dim_t numNodes, index_t * target, index_t unused)
21 {
22 dim_t i;
23 index_t min_target, numTargets, max_target;
24 Dudley_NodeMapping *out = NULL;
25 /* allocate the return value */
26 min_target = Dudley_Util_getFlaggedMinInt(1, numNodes, target, unused);
27 if (min_target < 0)
28 {
29 Dudley_setError(VALUE_ERROR, "Dudley_NodeMapping_alloc: target has negative entry.");
30 return NULL;
31 }
32 /* now we assume min_target=0! */
33 max_target = Dudley_Util_getFlaggedMaxInt(1, numNodes, target, unused);
34 numTargets = min_target <= max_target ? max_target + 1 : 0;
35 out = new Dudley_NodeMapping;
36 if (!Dudley_checkPtr(out))
37 {
38 out->reference_counter = 1;
39 out->unused = unused;
40 out->numNodes = numNodes;
41 out->numTargets = numTargets;
42 out->map = new index_t[numTargets];
43 out->target = new index_t[numNodes];
44 if (!(Dudley_checkPtr(out->target) || Dudley_checkPtr(out->map)))
45 {
46 #pragma omp parallel
47 {
48 #pragma omp for private(i)
49 for (i = 0; i < numTargets; ++i)
50 out->map[i] = -1;
51 #pragma omp for private(i)
52 for (i = 0; i < numNodes; ++i)
53 {
54 out->target[i] = target[i];
55 if (target[i] != unused)
56 out->map[out->target[i]] = i;
57 }
58 #pragma omp for private(i)
59 for (i = 0; i < numTargets; ++i)
60 {
61 if (out->map[i] == -1)
62 {
63 Dudley_setError(VALUE_ERROR,
64 "Dudley_NodeMapping_alloc: target does not define a continuous labeling.");
65 }
66 }
67 }
68 }
69 if (!Dudley_noError())
70 {
71 Dudley_NodeMapping_free(out);
72 }
73
74 }
75 return out;
76 }
77
78 void Dudley_NodeMapping_free(Dudley_NodeMapping * in)
79 {
80 if (in != NULL)
81 {
82 in->reference_counter--;
83 if (in->reference_counter <= 0)
84 {
85 delete[] in->target;
86 delete[] in->map;
87 delete in;
88 }
89 }
90 }
91
92 Dudley_NodeMapping *Dudley_NodeMapping_getReference(Dudley_NodeMapping * in)
93 {
94 if (in != NULL)
95 in->reference_counter++;
96 return in;
97 }
98

  ViewVC Help
Powered by ViewVC 1.1.26