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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1265 - (show annotations)
Tue Aug 21 06:00:46 2007 UTC (12 years, 9 months ago) by gross
File MIME type: text/plain
File size: 5180 byte(s)
an array was initialized too long.
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
15 /* Finley: Mesh */
16
17 /* at input the element nodes refers to the numbering defined the global Id assigned to the nodes in the */
18 /* NodeFile. It is also not ensured that all nodes refered by an element is actually available */
19 /* on the process. At the output, a local node labeling is used and all nodes are available */
20 /* In particular the numbering of the element nodes is between 0 and in->NodeFile->numNodes */
21 /* The function does not create a distribution of the degrees of freedom. */
22
23 /**************************************************************/
24
25 /* Author: gross@access.edu.au */
26 /* Version: $Id$ */
27
28 /**************************************************************/
29
30 #include "Mesh.h"
31 #include "Util.h"
32
33 /**************************************************************/
34
35 void Finley_Mesh_resolveNodeIds(Finley_Mesh* in) {
36
37 index_t min_id, max_id, min_id2, max_id2, global_min_id, global_max_id,
38 *globalToNewLocalNodeLabels=NULL, *newLocalToGlobalNodeLabels=NULL;
39 dim_t len, n, newNumNodes, numDim;
40 Finley_NodeFile *newNodeFile=NULL;
41 #ifdef PASO_MPI
42 index_t id_range[2], global_id_range[2];
43 #endif
44 numDim=Finley_Mesh_getDim(in);
45 /* find the minimum and maximum id used by elements: */
46 min_id=INDEX_T_MAX;
47 max_id=-INDEX_T_MAX;
48 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Elements);
49 max_id=MAX(max_id,max_id2);
50 min_id=MIN(min_id,min_id2);
51 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->FaceElements);
52 max_id=MAX(max_id,max_id2);
53 min_id=MIN(min_id,min_id2);
54 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->ContactElements);
55 max_id=MAX(max_id,max_id2);
56 min_id=MIN(min_id,min_id2);
57 Finley_ElementFile_setNodeRange(&min_id2,&max_id2,in->Points);
58 max_id=MAX(max_id,max_id2);
59 min_id=MIN(min_id,min_id2);
60 #ifdef PASO_MPI
61 id_range[0]=-min_id;
62 id_range[1]=max_id;
63 MPI_Allreduce( id_range, global_id_range, 2, MPI_INT, MPI_MAX, in->MPIInfo->comm );
64 global_min_id=-global_id_range[0];
65 global_max_id=global_id_range[1];
66 #else
67 global_min_id=min_id;
68 global_max_id=max_id;
69 #endif
70 #ifdef Finley_TRACE
71 printf("Node id range used by elements is %d:%d\n",global_min_id,global_max_id);
72 #endif
73
74
75
76 /* allocate mappings for new local node labeling to global node labeling (newLocalToGlobalNodeLabels)
77 and global node labeling to the new local node labeling (globalToNewLocalNodeLabels[i-min_id] is the
78 new local id of global node i) */
79 len=max_id-min_id+1;
80 globalToNewLocalNodeLabels=TMPMEMALLOC(len,index_t); /* local mask for used nodes */
81 newLocalToGlobalNodeLabels=TMPMEMALLOC(len,index_t);
82 if (! ( (Finley_checkPtr(globalToNewLocalNodeLabels) && Finley_checkPtr(newLocalToGlobalNodeLabels) ) ) ) {
83
84 #pragma omp parallel
85 {
86 #pragma omp for private(n) schedule(static)
87 for (n=0;n<len;n++) newLocalToGlobalNodeLabels[n]=-1;
88 #pragma omp for private(n) schedule(static)
89 for (n=0;n<len;n++) globalToNewLocalNodeLabels[n]=-1;
90 }
91
92 /* mark the nodes referred by elements in globalToNewLocalNodeLabels which is currently used as a mask: */
93
94 Finley_Mesh_markNodes(globalToNewLocalNodeLabels,min_id,in,FALSE);
95
96 /* create a local labeling newLocalToGlobalNodeLabels of the local nodes by packing the mask globalToNewLocalNodeLabels*/
97
98 newNumNodes=Finley_Util_packMask(len,globalToNewLocalNodeLabels,newLocalToGlobalNodeLabels);
99
100 /* invert the new labeling and shift the index newLocalToGlobalNodeLabels to global node ids */
101 #pragma omp parallel for private(n) schedule(static)
102 for (n=0;n<newNumNodes;n++) {
103 globalToNewLocalNodeLabels[newLocalToGlobalNodeLabels[n]]=n;
104 newLocalToGlobalNodeLabels[n]+=min_id;
105 }
106 /* create a new table */
107 newNodeFile=Finley_NodeFile_alloc(numDim,in->MPIInfo);
108 if (Finley_noError()) {
109 Finley_NodeFile_allocTable(newNodeFile,newNumNodes);
110 }
111 if (Finley_noError())
112 Finley_NodeFile_gather_global(newLocalToGlobalNodeLabels,in->Nodes, newNodeFile);
113 if (Finley_noError()) {
114 Finley_NodeFile_free(in->Nodes);
115 in->Nodes=newNodeFile;
116 /* relable nodes of the elements: */
117 Finley_Mesh_relableElementNodes(globalToNewLocalNodeLabels,min_id,in);
118 }
119 }
120 TMPMEMFREE(globalToNewLocalNodeLabels);
121 TMPMEMFREE(newLocalToGlobalNodeLabels);
122 if (! Finley_noError()) {
123 Finley_NodeFile_free(newNodeFile);
124 }
125 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26