/[escript]/trunk/finley/src/ElementFile.c
ViewVC logotype

Contents of /trunk/finley/src/ElementFile.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3490 - (show annotations)
Wed Mar 30 02:24:33 2011 UTC (8 years, 4 months ago) by caltinay
File MIME type: text/plain
File size: 5013 byte(s)
More gcc-4.6 fixes (mostly initialized-but-unused-var warnings)

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
17 /* Finley: ElementFile */
18
19 /* allocates an element file to hold elements of type id and with integration order order. */
20 /* use Finley_Mesh_allocElementTable to allocate the element table (Id,Nodes,Tag,Owner). */
21
22 /**************************************************************/
23
24 #include "ElementFile.h"
25
26 /**************************************************************/
27
28 Finley_ElementFile* Finley_ElementFile_alloc(Finley_ReferenceElementSet* referenceElementSet, Esys_MPIInfo *MPIInfo)
29 {
30 Finley_ElementFile *out;
31
32
33 if (! Finley_noError()) return NULL;
34
35 /* allocate the return value */
36
37 out=MEMALLOC(1,Finley_ElementFile);
38 if (Finley_checkPtr(out)) return NULL;
39 out->referenceElementSet=Finley_ReferenceElementSet_reference(referenceElementSet);
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 out->jacobeans_reducedS=NULL;
50 out->jacobeans_reducedS_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=Finley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElement->BasisFunctions);
59 out->jacobeans_reducedQ=Finley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElementReducedQuadrature->BasisFunctions);
60 out->jacobeans_reducedS=Finley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElement->LinearBasisFunctions);
61 out->jacobeans_reducedS_reducedQ=Finley_ElementFile_Jacobeans_alloc(referenceElementSet->referenceElementReducedQuadrature->LinearBasisFunctions);
62
63
64
65 if (! Finley_noError()) {
66 Finley_ElementFile_free(out);
67 return NULL;
68 }
69 out->numNodes=out->referenceElementSet->numNodes;
70 return out;
71 }
72
73 /* deallocates an element file: */
74
75 void Finley_ElementFile_free(Finley_ElementFile* in) {
76 if (in!=NULL) {
77 Finley_ElementFile_freeTable(in);
78 Finley_ReferenceElementSet_dealloc(in->referenceElementSet);
79 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans);
80 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS);
81 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedQ);
82 Finley_ElementFile_Jacobeans_dealloc(in->jacobeans_reducedS_reducedQ);
83 Esys_MPIInfo_free( in->MPIInfo );
84 MEMFREE(in);
85 }
86 }
87 void Finley_ElementFile_setElementDistribution(Finley_ElementFile* in, dim_t* distribution) {
88 dim_t local_num_elements,e,num_elements=0;
89 Esys_MPI_rank myRank;
90 if (in == NULL) {
91 distribution[0]=num_elements;
92 } else {
93 if (in->MPIInfo->size>1) {
94 num_elements=0;
95 myRank=in->MPIInfo->rank;
96 #pragma omp parallel private(local_num_elements)
97 {
98 local_num_elements=0;
99 #pragma omp for private(e)
100 for (e=0;e<in->numElements;e++) {
101 if (in->Owner[e] == myRank) local_num_elements++;
102 }
103 #pragma omp critical
104 num_elements+=local_num_elements;
105 }
106 #ifdef ESYS_MPI
107 MPI_Allgather(&num_elements,1,MPI_INT,distribution,1,MPI_INT,in->MPIInfo->comm);
108 #else
109 distribution[0]=num_elements;
110 #endif
111 } else {
112 distribution[0]=in->numElements;
113 }
114 }
115 }
116
117 dim_t Finley_ElementFile_getGlobalNumElements(Finley_ElementFile* in) {
118 dim_t size, *distribution=NULL, out, p;
119 if (in == NULL) {
120 return 0;
121 } else {
122 size=in->MPIInfo->size;
123 distribution=TMPMEMALLOC(size,dim_t);
124 Finley_ElementFile_setElementDistribution(in,distribution);
125 out=0;
126 for (p=0;p<size;++p) out+=distribution[p];
127 TMPMEMFREE(distribution);
128 return out;
129 }
130 }
131 dim_t Finley_ElementFile_getMyNumElements(Finley_ElementFile* in) {
132 dim_t size, *distribution=NULL, out;
133 if (in == NULL) {
134 return 0;
135 } else {
136 size=in->MPIInfo->size;
137 distribution=TMPMEMALLOC(size,dim_t);
138 Finley_ElementFile_setElementDistribution(in,distribution);
139 out=distribution[in->MPIInfo->rank];
140 TMPMEMFREE(distribution);
141 return out;
142 }
143
144 }
145 index_t Finley_ElementFile_getFirstElement(Finley_ElementFile* in){
146 dim_t size, *distribution=NULL, out, p;
147 if (in == NULL) {
148 return 0;
149 } else {
150 size=in->MPIInfo->size;
151 distribution=TMPMEMALLOC(size,dim_t);
152 Finley_ElementFile_setElementDistribution(in,distribution);
153 out=0;
154 for (p=0;p<in->MPIInfo->rank;++p) out+=distribution[p];
155 TMPMEMFREE(distribution);
156 return out;
157 }
158 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26