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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1384 - (hide annotations)
Fri Jan 11 02:29:38 2008 UTC (11 years, 9 months ago) by phornby
Original Path: temp_trunk_copy/finley/src/NodeMapping.c
File MIME type: text/plain
File size: 2422 byte(s)
Make a temp copy of the trunk before checking in the windows changes


1 ksteube 1313
2     /* $Id$ */
3    
4     /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16     #include "NodeMapping.h"
17     #include "Util.h"
18    
19     Finley_NodeMapping* Finley_NodeMapping_alloc(dim_t numNodes, index_t* target, index_t unused)
20     {
21     dim_t i;
22     index_t min_target, numTargets;
23     Finley_NodeMapping* out=NULL;
24     /* allocate the return value */
25     min_target=Finley_Util_getFlaggedMinInt(1,numNodes,target,unused);
26     numTargets=Finley_Util_getFlaggedMaxInt(1,numNodes,target,unused)+1;
27     if (min_target<0) {
28     Finley_setError(VALUE_ERROR,"Finley_NodeMapping_alloc: target has negative entry.");
29     return NULL;
30     }
31     out=MEMALLOC(1,Finley_NodeMapping);
32     if (!Finley_checkPtr(out)) {
33     out->reference_counter=1;
34     out->unused=unused;
35     out->numNodes=numNodes;
36     out->numTargets=numTargets;
37     out->map=MEMALLOC(numTargets,index_t);
38     out->target=MEMALLOC(numNodes,index_t);
39     if (! (Finley_checkPtr(out->target) || Finley_checkPtr(out->map) ) ) {
40     #pragma omp parallel
41     {
42     #pragma omp for private(i)
43     for (i=0; i<numTargets; ++i)out-> map[i]=-1;
44     #pragma omp for private(i)
45     for (i=0;i<numNodes;++i) {
46     out->target[i]=target[i];
47     if (target[i] != unused) out->map[out->target[i]]=i;
48     }
49     #pragma omp for private(i)
50     for (i=0; i<numTargets; ++i) {
51     if (out->map[i]==-1) {
52     Finley_setError(VALUE_ERROR,"Finley_NodeMapping_alloc: target does not define a continuous labeling.");
53     }
54     }
55     }
56     }
57     if (!Finley_noError()) {
58     Finley_NodeMapping_free(out) ;
59     }
60    
61     }
62     return out;
63     }
64    
65     void Finley_NodeMapping_free(Finley_NodeMapping* in) {
66     if (in != NULL) {
67     in->reference_counter--;
68     if (in->reference_counter<=0) {
69     MEMFREE(in->target);
70     MEMFREE(in->map);
71     MEMFREE(in);
72     }
73     }
74     }
75     Finley_NodeMapping* NodeMapping_getReference(Finley_NodeMapping *in )
76     {
77     if (in != NULL)
78     in->reference_counter++;
79     return in;
80     }

  ViewVC Help
Powered by ViewVC 1.1.26