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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4346 - (show annotations)
Tue Apr 2 04:46:45 2013 UTC (6 years, 4 months ago) by jfenwick
File size: 4548 byte(s)
Bringing the changes from doubleplusgood branch.
Can't merge directly because svn doesn't transfer changes to renamed files (mutter grumble).
1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 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 since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16 /************************************************************************************/
17
18 /* Dudley: ElementFile */
19
20 /* allocates an element file to hold elements of type id and with integration order order. */
21 /* use Dudley_Mesh_allocElementTable to allocate the element table (Id,Nodes,Tag,Owner). */
22
23 /************************************************************************************/
24
25 #include "ElementFile.h"
26 #include "ShapeTable.h"
27
28 /************************************************************************************/
29
30 Dudley_ElementFile *Dudley_ElementFile_alloc(Dudley_ElementTypeId etype, Esys_MPIInfo * MPIInfo)
31 {
32 Dudley_ElementFile *out;
33
34 if (!Dudley_noError())
35 return NULL;
36
37 /* allocate the return value */
38
39 out = new Dudley_ElementFile;
40 if (Dudley_checkPtr(out))
41 return NULL;
42 out->numElements = 0;
43 out->Id = NULL;
44 out->Nodes = NULL;
45 out->Tag = NULL;
46 out->Color = NULL;
47 out->minColor = 0;
48 out->maxColor = -1;
49 out->jacobeans = NULL;
50 out->jacobeans_reducedQ = NULL;
51
52 out->Owner = NULL;
53 out->numTagsInUse = 0;
54 out->tagsInUse = NULL;
55
56 out->MPIInfo = Esys_MPIInfo_getReference(MPIInfo);
57
58 out->jacobeans = Dudley_ElementFile_Jacobeans_alloc();
59 out->jacobeans_reducedQ = Dudley_ElementFile_Jacobeans_alloc();
60
61 if (!Dudley_noError())
62 {
63 Dudley_ElementFile_free(out);
64 return NULL;
65 }
66 out->etype = etype;
67 out->numDim = Dims[out->etype];
68 out->numNodes = out->numDim + 1;
69 out->numLocalDim = localDims[out->etype];
70 out->numShapes = out->numLocalDim + 1;
71 out->ename = getElementName(out->etype);
72 return out;
73 }
74
75 /* deallocates an element file: */
76
77 void Dudley_ElementFile_free(Dudley_ElementFile * in)
78 {
79 if (in != NULL)
80 {
81 Dudley_ElementFile_freeTable(in);
82 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans);
83 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedQ);
84 Esys_MPIInfo_free(in->MPIInfo);
85 delete in;
86 }
87 }
88
89 void Dudley_ElementFile_setElementDistribution(Dudley_ElementFile * in, dim_t * distribution)
90 {
91 dim_t local_num_elements, e, num_elements = 0;
92 Esys_MPI_rank myRank;
93 if (in == NULL)
94 {
95 distribution[0] = num_elements;
96 }
97 else
98 {
99 if (in->MPIInfo->size > 1)
100 {
101 num_elements = 0;
102 myRank = in->MPIInfo->rank;
103 #pragma omp parallel private(local_num_elements)
104 {
105 local_num_elements = 0;
106 #pragma omp for private(e)
107 for (e = 0; e < in->numElements; e++)
108 {
109 if (in->Owner[e] == myRank)
110 local_num_elements++;
111 }
112 #pragma omp critical
113 num_elements += local_num_elements;
114 }
115 #ifdef ESYS_MPI
116 MPI_Allgather(&num_elements, 1, MPI_INT, distribution, 1, MPI_INT, in->MPIInfo->comm);
117 #else
118 distribution[0] = num_elements;
119 #endif
120 }
121 else
122 {
123 distribution[0] = in->numElements;
124 }
125 }
126 }
127
128 dim_t Dudley_ElementFile_getGlobalNumElements(Dudley_ElementFile * in)
129 {
130 dim_t size, *distribution = NULL, out, p;
131 if (in == NULL)
132 {
133 return 0;
134 }
135 else
136 {
137 size = in->MPIInfo->size;
138 distribution = new dim_t[size];
139 Dudley_ElementFile_setElementDistribution(in, distribution);
140 out = 0;
141 for (p = 0; p < size; ++p)
142 out += distribution[p];
143 delete[] distribution;
144 return out;
145 }
146 }
147
148 dim_t Dudley_ElementFile_getMyNumElements(Dudley_ElementFile * in)
149 {
150 dim_t size, *distribution = NULL, out;
151 if (in == NULL)
152 {
153 return 0;
154 }
155 else
156 {
157 size = in->MPIInfo->size;
158 distribution = new dim_t[size];
159 Dudley_ElementFile_setElementDistribution(in, distribution);
160 out = distribution[in->MPIInfo->rank];
161 delete[] distribution;
162 return out;
163 }
164
165 }
166
167 index_t Dudley_ElementFile_getFirstElement(Dudley_ElementFile * in)
168 {
169 dim_t size, *distribution = NULL, out, p;
170 if (in == NULL)
171 {
172 return 0;
173 }
174 else
175 {
176 size = in->MPIInfo->size;
177 distribution = new dim_t[size];
178 Dudley_ElementFile_setElementDistribution(in, distribution);
179 out = 0;
180 for (p = 0; p < in->MPIInfo->rank; ++p)
181 out += distribution[p];
182 delete[] distribution;
183 return out;
184 }
185 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26