/[escript]/branches/domexper/dudley/src/ElementFile.c
ViewVC logotype

Contents of /branches/domexper/dudley/src/ElementFile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3247 - (show annotations)
Wed Oct 6 05:53:06 2010 UTC (8 years, 6 months ago) by caltinay
File MIME type: text/plain
File size: 4444 byte(s)
Fixed name clashes between dudley and finley so both can be used
simultaneously.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14 /**************************************************************/
15
16 /* Dudley: ElementFile */
17
18 /* allocates an element file to hold elements of type id and with integration order order. */
19 /* use Dudley_Mesh_allocElementTable to allocate the element table (Id,Nodes,Tag,Owner). */
20
21 /**************************************************************/
22
23 #include "ElementFile.h"
24 #include "ShapeTable.h"
25
26 /**************************************************************/
27
28 Dudley_ElementFile *Dudley_ElementFile_alloc(Dudley_ElementTypeId etype, Esys_MPIInfo * MPIInfo)
29 {
30 Dudley_ElementFile *out;
31
32 if (!Dudley_noError())
33 return NULL;
34
35 /* allocate the return value */
36
37 out = MEMALLOC(1, Dudley_ElementFile);
38 if (Dudley_checkPtr(out))
39 return NULL;
40 out->numElements = 0;
41 out->Id = NULL;
42 out->Nodes = NULL;
43 out->Tag = NULL;
44 out->Color = NULL;
45 out->minColor = 0;
46 out->maxColor = -1;
47 out->jacobeans = NULL;
48 out->jacobeans_reducedQ = NULL;
49
50 out->Owner = NULL;
51 out->numTagsInUse = 0;
52 out->tagsInUse = NULL;
53
54 out->MPIInfo = Esys_MPIInfo_getReference(MPIInfo);
55
56 out->jacobeans = Dudley_ElementFile_Jacobeans_alloc();
57 out->jacobeans_reducedQ = Dudley_ElementFile_Jacobeans_alloc();
58
59 if (!Dudley_noError())
60 {
61 Dudley_ElementFile_free(out);
62 return NULL;
63 }
64 out->etype = etype;
65 out->numDim = Dims[out->etype];
66 out->numNodes = out->numDim + 1;
67 out->numLocalDim = localDims[out->etype];
68 out->numShapes = out->numLocalDim + 1;
69 out->ename = getElementName(out->etype);
70 return out;
71 }
72
73 /* deallocates an element file: */
74
75 void Dudley_ElementFile_free(Dudley_ElementFile * in)
76 {
77 if (in != NULL)
78 {
79 Dudley_ElementFile_freeTable(in);
80 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans);
81 Dudley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedQ);
82 Esys_MPIInfo_free(in->MPIInfo);
83 MEMFREE(in);
84 }
85 }
86
87 void Dudley_ElementFile_setElementDistribution(Dudley_ElementFile * in, dim_t * distribution)
88 {
89 dim_t local_num_elements, e, num_elements = 0, size;
90 Esys_MPI_rank myRank;
91 if (in == NULL)
92 {
93 distribution[0] = num_elements;
94 }
95 else
96 {
97 if (in->MPIInfo->size > 1)
98 {
99 num_elements = 0;
100 myRank = in->MPIInfo->rank;
101 size = in->MPIInfo->size;
102 #pragma omp parallel private(local_num_elements)
103 {
104 local_num_elements = 0;
105 #pragma omp for private(e)
106 for (e = 0; e < in->numElements; e++)
107 {
108 if (in->Owner[e] == myRank)
109 local_num_elements++;
110 }
111 #pragma omp critical
112 num_elements += local_num_elements;
113 }
114 #ifdef ESYS_MPI
115 MPI_Allgather(&num_elements, 1, MPI_INT, distribution, 1, MPI_INT, in->MPIInfo->comm);
116 #else
117 distribution[0] = num_elements;
118 #endif
119 }
120 else
121 {
122 distribution[0] = in->numElements;
123 }
124 }
125 }
126
127 dim_t Dudley_ElementFile_getGlobalNumElements(Dudley_ElementFile * in)
128 {
129 dim_t size, *distribution = NULL, out, p;
130 if (in == NULL)
131 {
132 return 0;
133 }
134 else
135 {
136 size = in->MPIInfo->size;
137 distribution = TMPMEMALLOC(size, dim_t);
138 Dudley_ElementFile_setElementDistribution(in, distribution);
139 out = 0;
140 for (p = 0; p < size; ++p)
141 out += distribution[p];
142 TMPMEMFREE(distribution);
143 return out;
144 }
145 }
146
147 dim_t Dudley_ElementFile_getMyNumElements(Dudley_ElementFile * in)
148 {
149 dim_t size, *distribution = NULL, out;
150 if (in == NULL)
151 {
152 return 0;
153 }
154 else
155 {
156 size = in->MPIInfo->size;
157 distribution = TMPMEMALLOC(size, dim_t);
158 Dudley_ElementFile_setElementDistribution(in, distribution);
159 out = distribution[in->MPIInfo->rank];
160 TMPMEMFREE(distribution);
161 return out;
162 }
163
164 }
165
166 index_t Dudley_ElementFile_getFirstElement(Dudley_ElementFile * in)
167 {
168 dim_t size, *distribution = NULL, out, p;
169 if (in == NULL)
170 {
171 return 0;
172 }
173 else
174 {
175 size = in->MPIInfo->size;
176 distribution = TMPMEMALLOC(size, dim_t);
177 Dudley_ElementFile_setElementDistribution(in, distribution);
178 out = 0;
179 for (p = 0; p < in->MPIInfo->rank; ++p)
180 out += distribution[p];
181 TMPMEMFREE(distribution);
182 return out;
183 }
184 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26