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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3490 - (hide annotations)
Wed Mar 30 02:24:33 2011 UTC (8 years, 5 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 jgs 150
2 ksteube 1312 /*******************************************************
3 ksteube 1811 *
4 jfenwick 2881 * Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1811 * 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 ksteube 1312
14 ksteube 1811
15 jgs 82 /**************************************************************/
16    
17     /* Finley: ElementFile */
18    
19     /* allocates an element file to hold elements of type id and with integration order order. */
20 ksteube 1312 /* use Finley_Mesh_allocElementTable to allocate the element table (Id,Nodes,Tag,Owner). */
21 jgs 82
22     /**************************************************************/
23    
24     #include "ElementFile.h"
25    
26     /**************************************************************/
27    
28 jfenwick 3259 Finley_ElementFile* Finley_ElementFile_alloc(Finley_ReferenceElementSet* referenceElementSet, Esys_MPIInfo *MPIInfo)
29 bcumming 730 {
30 jgs 82 Finley_ElementFile *out;
31    
32    
33 jgs 150 if (! Finley_noError()) return NULL;
34 jgs 82
35     /* allocate the return value */
36    
37 jgs 102 out=MEMALLOC(1,Finley_ElementFile);
38 jgs 82 if (Finley_checkPtr(out)) return NULL;
39 gross 2748 out->referenceElementSet=Finley_ReferenceElementSet_reference(referenceElementSet);
40 jgs 82 out->numElements=0;
41     out->Id=NULL;
42     out->Nodes=NULL;
43     out->Tag=NULL;
44     out->Color=NULL;
45 jgs 123 out->minColor=0;
46     out->maxColor=-1;
47 gross 777 out->jacobeans=NULL;
48     out->jacobeans_reducedQ=NULL;
49     out->jacobeans_reducedS=NULL;
50     out->jacobeans_reducedS_reducedQ=NULL;
51 jgs 82
52 ksteube 1312 out->Owner=NULL;
53 gross 1716 out->numTagsInUse=0;
54     out->tagsInUse=NULL;
55    
56 jfenwick 3259 out->MPIInfo = Esys_MPIInfo_getReference( MPIInfo );
57 gross 2748
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 gross 532
63 gross 777
64 ksteube 1312
65 jgs 150 if (! Finley_noError()) {
66 ksteube 1312 Finley_ElementFile_free(out);
67 jgs 82 return NULL;
68     }
69 gross 2748 out->numNodes=out->referenceElementSet->numNodes;
70 jgs 82 return out;
71     }
72    
73     /* deallocates an element file: */
74    
75 ksteube 1312 void Finley_ElementFile_free(Finley_ElementFile* in) {
76 jgs 82 if (in!=NULL) {
77 ksteube 1312 Finley_ElementFile_freeTable(in);
78 gross 2748 Finley_ReferenceElementSet_dealloc(in->referenceElementSet);
79 gross 776 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 jfenwick 3259 Esys_MPIInfo_free( in->MPIInfo );
84 jgs 82 MEMFREE(in);
85     }
86     }
87 ksteube 1312 void Finley_ElementFile_setElementDistribution(Finley_ElementFile* in, dim_t* distribution) {
88 caltinay 3490 dim_t local_num_elements,e,num_elements=0;
89 jfenwick 3259 Esys_MPI_rank myRank;
90 ksteube 1312 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 jfenwick 3259 #ifdef ESYS_MPI
107 ksteube 1312 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 phornby 1628 dim_t size, *distribution=NULL, out;
133 ksteube 1312 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