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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3079 - (show annotations)
Tue Aug 3 04:04:51 2010 UTC (9 years, 4 months ago) by jfenwick
File MIME type: text/plain
File size: 5052 byte(s)
Some experiments on finley

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, Paso_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 = Paso_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 Paso_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, size;
89 Paso_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 size=in->MPIInfo->size;
97 #pragma omp parallel private(local_num_elements)
98 {
99 local_num_elements=0;
100 #pragma omp for private(e)
101 for (e=0;e<in->numElements;e++) {
102 if (in->Owner[e] == myRank) local_num_elements++;
103 }
104 #pragma omp critical
105 num_elements+=local_num_elements;
106 }
107 #ifdef PASO_MPI
108 MPI_Allgather(&num_elements,1,MPI_INT,distribution,1,MPI_INT,in->MPIInfo->comm);
109 #else
110 distribution[0]=num_elements;
111 #endif
112 } else {
113 distribution[0]=in->numElements;
114 }
115 }
116 }
117
118 dim_t Finley_ElementFile_getGlobalNumElements(Finley_ElementFile* in) {
119 dim_t size, *distribution=NULL, out, p;
120 if (in == NULL) {
121 return 0;
122 } else {
123 size=in->MPIInfo->size;
124 distribution=TMPMEMALLOC(size,dim_t);
125 Finley_ElementFile_setElementDistribution(in,distribution);
126 out=0;
127 for (p=0;p<size;++p) out+=distribution[p];
128 TMPMEMFREE(distribution);
129 return out;
130 }
131 }
132 dim_t Finley_ElementFile_getMyNumElements(Finley_ElementFile* in) {
133 dim_t size, *distribution=NULL, out;
134 if (in == NULL) {
135 return 0;
136 } else {
137 size=in->MPIInfo->size;
138 distribution=TMPMEMALLOC(size,dim_t);
139 Finley_ElementFile_setElementDistribution(in,distribution);
140 out=distribution[in->MPIInfo->rank];
141 TMPMEMFREE(distribution);
142 return out;
143 }
144
145 }
146 index_t Finley_ElementFile_getFirstElement(Finley_ElementFile* in){
147 dim_t size, *distribution=NULL, out, p;
148 if (in == NULL) {
149 return 0;
150 } else {
151 size=in->MPIInfo->size;
152 distribution=TMPMEMALLOC(size,dim_t);
153 Finley_ElementFile_setElementDistribution(in,distribution);
154 out=0;
155 for (p=0;p<in->MPIInfo->rank;++p) out+=distribution[p];
156 TMPMEMFREE(distribution);
157 return out;
158 }
159 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26