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

Contents of /trunk-mpi-branch/finley/src/NodeMapping.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1251 - (show annotations)
Thu Aug 16 06:39:17 2007 UTC (11 years, 8 months ago) by gross
File MIME type: text/plain
File size: 2737 byte(s)
node mapping is working now. the coupler is still missing.
1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12 /**************************************************************/
13
14 /* Author: gross@access.edu.au */
15 /* Version: $Id$ */
16
17 /**************************************************************/
18
19 #include "NodeMapping.h"
20 #include "Util.h"
21
22 Finley_NodeMapping* Finley_NodeMapping_alloc(dim_t numNodes, index_t* target, index_t unused)
23 {
24 dim_t i;
25 index_t min_target, numTargets;
26 Finley_NodeMapping* out=NULL;
27 /* allocate the return value */
28 min_target=Finley_Util_getFlaggedMinInt(1,numNodes,target,unused);
29 numTargets=Finley_Util_getFlaggedMaxInt(1,numNodes,target,unused)+1;
30 if (min_target<0) {
31 Finley_setError(VALUE_ERROR,"Finley_NodeMapping_alloc: target has negative entry.");
32 return NULL;
33 }
34 out=MEMALLOC(1,Finley_NodeMapping);
35 if (!Finley_checkPtr(out)) {
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 (! (Finley_checkPtr(out->target) || Finley_checkPtr(out->map) ) ) {
43 #pragma omp parallel
44 {
45 #pragma omp for private(i)
46 for (i=0; i<numTargets; ++i)out-> map[i]=-1;
47 #pragma omp for private(i)
48 for (i=0;i<numNodes;++i) {
49 out->target[i]=target[i];
50 if (target[i] != unused) out->map[out->target[i]]=i;
51 }
52 #pragma omp for private(i)
53 for (i=0; i<numTargets; ++i) {
54 if (out->map[i]==-1) {
55 Finley_setError(VALUE_ERROR,"Finley_NodeMapping_alloc: target does not define a continuous labeling.");
56 }
57 }
58 }
59 }
60 if (!Finley_noError()) {
61 Finley_NodeMapping_free(out) ;
62 }
63
64 }
65 return out;
66 }
67
68 void Finley_NodeMapping_free(Finley_NodeMapping* in) {
69 if (in != NULL) {
70 in->reference_counter--;
71 if (in->reference_counter<=0) {
72 MEMFREE(in->target);
73 MEMFREE(in->map);
74 MEMFREE(in);
75 }
76 }
77 }
78 Finley_NodeMapping* NodeMapping_getReference(Finley_NodeMapping *in )
79 {
80 if (in != NULL)
81 in->reference_counter++;
82 return in;
83 }

  ViewVC Help
Powered by ViewVC 1.1.26