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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1766 - (show annotations)
Mon Sep 8 02:51:14 2008 UTC (10 years, 7 months ago) by gross
File MIME type: text/plain
File size: 2523 byte(s)
code formatting
1
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, max_target;
23 Finley_NodeMapping* out=NULL;
24 /* allocate the return value */
25 min_target=Finley_Util_getFlaggedMinInt(1,numNodes,target,unused);
26 if (min_target<0) {
27 Finley_setError(VALUE_ERROR,"Finley_NodeMapping_alloc: target has negative entry.");
28 return NULL;
29 }
30 /* now we assume min_target=0! */
31 max_target=Finley_Util_getFlaggedMaxInt(1,numNodes,target,unused);
32 numTargets= min_target<max_target ? max_target+1 :0;
33 out=MEMALLOC(1,Finley_NodeMapping);
34 if (!Finley_checkPtr(out)) {
35 out->reference_counter=1;
36 out->unused=unused;
37 out->numNodes=numNodes;
38 out->numTargets=numTargets;
39 out->map=MEMALLOC(numTargets,index_t);
40 out->target=MEMALLOC(numNodes,index_t);
41 if (! (Finley_checkPtr(out->target) || Finley_checkPtr(out->map) ) ) {
42 #pragma omp parallel
43 {
44 #pragma omp for private(i)
45 for (i=0; i<numTargets; ++i)out-> map[i]=-1;
46 #pragma omp for private(i)
47 for (i=0;i<numNodes;++i) {
48 out->target[i]=target[i];
49 if (target[i] != unused) out->map[out->target[i]]=i;
50 }
51 #pragma omp for private(i)
52 for (i=0; i<numTargets; ++i) {
53 if (out->map[i]==-1) {
54 Finley_setError(VALUE_ERROR,"Finley_NodeMapping_alloc: target does not define a continuous labeling.");
55 }
56 }
57 }
58 }
59 if (!Finley_noError()) {
60 Finley_NodeMapping_free(out) ;
61 }
62
63 }
64 return out;
65 }
66
67 void Finley_NodeMapping_free(Finley_NodeMapping* in) {
68 if (in != NULL) {
69 in->reference_counter--;
70 if (in->reference_counter<=0) {
71 MEMFREE(in->target);
72 MEMFREE(in->map);
73 MEMFREE(in);
74 }
75 }
76 }
77 Finley_NodeMapping* NodeMapping_getReference(Finley_NodeMapping *in )
78 {
79 if (in != NULL)
80 in->reference_counter++;
81 return in;
82 }

  ViewVC Help
Powered by ViewVC 1.1.26