/[escript]/trunk/finley/src/NodeMapping.c
ViewVC logotype

Annotation of /trunk/finley/src/NodeMapping.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (hide annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years ago) by ksteube
File MIME type: text/plain
File size: 2488 byte(s)
Copyright updated in all files

1 ksteube 1313
2     /*******************************************************
3 ksteube 1811 *
4     * Copyright (c) 2003-2008 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 ksteube 1313
14 ksteube 1811
15 ksteube 1313 #include "NodeMapping.h"
16     #include "Util.h"
17    
18     Finley_NodeMapping* Finley_NodeMapping_alloc(dim_t numNodes, index_t* target, index_t unused)
19     {
20     dim_t i;
21 gross 1766 index_t min_target, numTargets, max_target;
22 ksteube 1313 Finley_NodeMapping* out=NULL;
23     /* allocate the return value */
24     min_target=Finley_Util_getFlaggedMinInt(1,numNodes,target,unused);
25     if (min_target<0) {
26     Finley_setError(VALUE_ERROR,"Finley_NodeMapping_alloc: target has negative entry.");
27     return NULL;
28     }
29 gross 1766 /* now we assume min_target=0! */
30     max_target=Finley_Util_getFlaggedMaxInt(1,numNodes,target,unused);
31     numTargets= min_target<max_target ? max_target+1 :0;
32 ksteube 1313 out=MEMALLOC(1,Finley_NodeMapping);
33     if (!Finley_checkPtr(out)) {
34     out->reference_counter=1;
35     out->unused=unused;
36     out->numNodes=numNodes;
37     out->numTargets=numTargets;
38     out->map=MEMALLOC(numTargets,index_t);
39     out->target=MEMALLOC(numNodes,index_t);
40     if (! (Finley_checkPtr(out->target) || Finley_checkPtr(out->map) ) ) {
41     #pragma omp parallel
42     {
43     #pragma omp for private(i)
44     for (i=0; i<numTargets; ++i)out-> map[i]=-1;
45     #pragma omp for private(i)
46     for (i=0;i<numNodes;++i) {
47     out->target[i]=target[i];
48     if (target[i] != unused) out->map[out->target[i]]=i;
49     }
50     #pragma omp for private(i)
51     for (i=0; i<numTargets; ++i) {
52     if (out->map[i]==-1) {
53     Finley_setError(VALUE_ERROR,"Finley_NodeMapping_alloc: target does not define a continuous labeling.");
54     }
55     }
56     }
57     }
58     if (!Finley_noError()) {
59     Finley_NodeMapping_free(out) ;
60     }
61    
62     }
63     return out;
64     }
65    
66     void Finley_NodeMapping_free(Finley_NodeMapping* in) {
67     if (in != NULL) {
68     in->reference_counter--;
69     if (in->reference_counter<=0) {
70     MEMFREE(in->target);
71     MEMFREE(in->map);
72     MEMFREE(in);
73     }
74     }
75     }
76     Finley_NodeMapping* NodeMapping_getReference(Finley_NodeMapping *in )
77     {
78     if (in != NULL)
79     in->reference_counter++;
80     return in;
81     }

  ViewVC Help
Powered by ViewVC 1.1.26