/[escript]/trunk/dudley/src/Mesh_optimizeDOFLabeling.cpp
ViewVC logotype

Contents of /trunk/dudley/src/Mesh_optimizeDOFLabeling.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4803 - (show annotations)
Wed Mar 26 06:52:28 2014 UTC (5 years, 9 months ago) by caltinay
File size: 4855 byte(s)
Removed obsolete wrappers for malloc and friends.
Paso_Pattern -> paso::Pattern

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 /**********************************************************************************************/
18
19 /* Dudley: Mesh: optimizes the labeling of the DOFs on each processor */
20
21 /**********************************************************************************************/
22
23 #include "Mesh.h"
24 #include "IndexList.h"
25
26 /************************************************************************************/
27
28 void Dudley_Mesh_optimizeDOFLabeling(Dudley_Mesh * in, dim_t * distribution)
29 {
30
31 index_t myFirstVertex, myLastVertex, *newGlobalDOFID = NULL, firstVertex, lastVertex;
32 register index_t k;
33 dim_t mpiSize, myNumVertices, len, p, i;
34 paso::Pattern *pattern = NULL;
35 Esys_MPI_rank myRank, current_rank;
36 Dudley_IndexList *index_list = NULL;
37 #ifdef ESYS_MPI
38 Esys_MPI_rank dest, source;
39 MPI_Status status;
40 #endif
41
42 if (in == NULL)
43 return;
44 if (in->Nodes == NULL)
45 return;
46
47 myRank = in->MPIInfo->rank;
48 mpiSize = in->MPIInfo->size;
49 myFirstVertex = distribution[myRank];
50 myLastVertex = distribution[myRank + 1];
51 myNumVertices = myLastVertex - myFirstVertex;
52 len = 0;
53 for (p = 0; p < mpiSize; ++p)
54 len = MAX(len, distribution[p + 1] - distribution[p]);
55
56 index_list = new Dudley_IndexList[myNumVertices];
57 newGlobalDOFID = new index_t[len];
58 /* create the adjacency structure xadj and adjncy */
59 if (!(Dudley_checkPtr(index_list) || Dudley_checkPtr(newGlobalDOFID)))
60 {
61 #pragma omp parallel private(i)
62 {
63 #pragma omp for schedule(static)
64 for (i = 0; i < myNumVertices; ++i)
65 {
66 index_list[i].extension = NULL;
67 index_list[i].n = 0;
68 }
69 /* insert contributions from element matrices into columns index index_list: */
70 Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list, myFirstVertex, myLastVertex,
71 in->Elements, in->Nodes->globalDegreesOfFreedom,
72 in->Nodes->globalDegreesOfFreedom);
73 Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list, myFirstVertex, myLastVertex,
74 in->FaceElements,
75 in->Nodes->globalDegreesOfFreedom,
76 in->Nodes->globalDegreesOfFreedom);
77 Dudley_IndexList_insertElementsWithRowRangeNoMainDiagonal(index_list, myFirstVertex, myLastVertex,
78 in->Points, in->Nodes->globalDegreesOfFreedom,
79 in->Nodes->globalDegreesOfFreedom);
80 }
81 /* create the local matrix pattern */
82 pattern =
83 Dudley_IndexList_createPattern(0, myNumVertices, index_list, myFirstVertex, myLastVertex, -myFirstVertex);
84
85 /* clean up index list */
86 if (index_list != NULL)
87 {
88 #pragma omp parallel for private(i)
89 for (i = 0; i < myNumVertices; ++i)
90 Dudley_IndexList_free(index_list[i].extension);
91 }
92
93 if (Dudley_noError())
94 paso::Pattern_reduceBandwidth(pattern, newGlobalDOFID);
95
96 paso::Pattern_free(pattern);
97 }
98 Esys_MPIInfo_noError(in->MPIInfo);
99 if (Dudley_noError())
100 {
101 /* shift new labeling to create a global id */
102 #pragma omp parallel for private(i)
103 for (i = 0; i < myNumVertices; ++i)
104 newGlobalDOFID[i] += myFirstVertex;
105
106 /* distribute new labeling to other processors */
107 #ifdef ESYS_MPI
108 dest = Esys_MPIInfo_mod(mpiSize, myRank + 1);
109 source = Esys_MPIInfo_mod(mpiSize, myRank - 1);
110 #endif
111 current_rank = myRank;
112 for (p = 0; p < mpiSize; ++p)
113 {
114 firstVertex = distribution[current_rank];
115 lastVertex = distribution[current_rank + 1];
116 #pragma omp parallel for private(i,k)
117 for (i = 0; i < in->Nodes->numNodes; ++i)
118 {
119 k = in->Nodes->globalDegreesOfFreedom[i];
120 if ((firstVertex <= k) && (k < lastVertex))
121 {
122 in->Nodes->globalDegreesOfFreedom[i] = newGlobalDOFID[k - firstVertex];
123 }
124 }
125
126 if (p < mpiSize - 1)
127 { /* the final send can be skipped */
128 #ifdef ESYS_MPI
129 MPI_Sendrecv_replace(newGlobalDOFID, len, MPI_INT,
130 dest, in->MPIInfo->msg_tag_counter,
131 source, in->MPIInfo->msg_tag_counter, in->MPIInfo->comm, &status);
132 #endif
133 in->MPIInfo->msg_tag_counter++;
134 current_rank = Esys_MPIInfo_mod(mpiSize, current_rank - 1);
135 }
136 }
137 }
138 delete[] index_list;
139 delete[] newGlobalDOFID;
140 #if 0
141 for (i = 0; i < in->Nodes->numNodes; ++i)
142 printf("%d ", in->Nodes->globalDegreesOfFreedom[i]);
143 printf("\n");
144 #endif
145 return;
146 }

Properties

Name Value
svn:mergeinfo /branches/lapack2681/finley/src/Mesh_optimizeDOFLabeling.cpp:2682-2741 /branches/pasowrap/dudley/src/Mesh_optimizeDOFLabeling.cpp:3661-3674 /branches/py3_attempt2/dudley/src/Mesh_optimizeDOFLabeling.cpp:3871-3891 /branches/restext/finley/src/Mesh_optimizeDOFLabeling.cpp:2610-2624 /branches/ripleygmg_from_3668/dudley/src/Mesh_optimizeDOFLabeling.cpp:3669-3791 /branches/stage3.0/finley/src/Mesh_optimizeDOFLabeling.cpp:2569-2590 /branches/symbolic_from_3470/dudley/src/Mesh_optimizeDOFLabeling.cpp:3471-3974 /branches/symbolic_from_3470/ripley/test/python/dudley/src/Mesh_optimizeDOFLabeling.cpp:3517-3974 /release/3.0/finley/src/Mesh_optimizeDOFLabeling.cpp:2591-2601 /trunk/dudley/src/Mesh_optimizeDOFLabeling.cpp:4257-4344 /trunk/ripley/test/python/dudley/src/Mesh_optimizeDOFLabeling.cpp:3480-3515

  ViewVC Help
Powered by ViewVC 1.1.26