/[escript]/branches/domexper/dudley/src/NodeMapping.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/NodeMapping.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3247 - (show annotations)
Wed Oct 6 05:53:06 2010 UTC (8 years, 6 months ago) by caltinay
File MIME type: text/plain
File size: 2419 byte(s)
Fixed name clashes between dudley and finley so both can be used
simultaneously.

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

  ViewVC Help
Powered by ViewVC 1.1.26