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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 853 - (show annotations)
Wed Sep 20 05:56:36 2006 UTC (13 years, 1 month ago) by gross
File MIME type: text/plain
File size: 8085 byte(s)
some performance problems wit openmp fixed.
1 /*
2 ************************************************************
3 * Copyright 2006 by ACcESS MNRF *
4 * *
5 * http://www.access.edu.au *
6 * Primary Business: Queensland, Australia *
7 * Licensed under the Open Software License version 3.0 *
8 * http://www.opensource.org/licenses/osl-3.0.php *
9 * *
10 ************************************************************
11 */
12
13 /**************************************************************/
14
15 /* assembles the system of numEq PDEs into the stiffness matrix S right hand side F */
16
17 /* D_{k,m} u_m and Y_k */
18
19 /* u has p.numComp components in a 3D domain. The shape functions for test and solution must be identical */
20 /* and 2* row_NS == row_NN (contact elements) */
21
22 /* Shape of the coefficients: */
23
24 /* D = p.numEqu x p.numComp */
25 /* Y = p.numEqu */
26
27
28 /**************************************************************/
29
30 /* Author: gross@access.edu.au */
31 /* Version: $Id:$ */
32
33 /**************************************************************/
34
35
36 #include "Assemble.h"
37 #include "Util.h"
38 #ifdef _OPENMP
39 #include <omp.h>
40 #endif
41
42
43 /**************************************************************/
44
45 void Finley_Assemble_PDE_System2_C(Assemble_Parameters p, Finley_ElementFile* elements,
46 Paso_SystemMatrix* Mat, escriptDataC* F, escriptDataC* D, escriptDataC* Y) {
47
48 index_t color;
49 dim_t e;
50 double *EM_S, *EM_F, *Vol, *D_p, *Y_p;
51 index_t *row_index;
52 register dim_t q, s,r,k,m;
53 register double rtmp, rtmp_D;
54 bool_t add_EM_F, add_EM_S;
55
56 bool_t extendedD=isExpanded(D);
57 bool_t extendedY=isExpanded(Y);
58 double *F_p=getSampleData(F,0);
59 double *S=p.row_jac->ReferenceElement->S;
60
61
62 #pragma omp parallel private(color,EM_S, EM_F, Vol, D_p, Y_p,row_index,q, s,r,k,m,rtmp, rtmp_D,add_EM_F, add_EM_S)
63 {
64 EM_S=THREAD_MEMALLOC(p.row_NN*p.col_NN*p.numEqu*p.numComp,double);
65 EM_F=THREAD_MEMALLOC(p.row_NN*p.numEqu,double);
66 row_index=THREAD_MEMALLOC(p.row_NN,index_t);
67
68 if (!Finley_checkPtr(EM_S) && !Finley_checkPtr(EM_F) && !Finley_checkPtr(row_index) ) {
69
70 #ifndef PASO_MPI
71 for (color=elements->minColor;color<=elements->maxColor;color++) {
72 /* open loop over all elements: */
73 #pragma omp for private(e) schedule(static)
74 for(e=0;e<elements->numElements;e++){
75 if (elements->Color[e]==color) {
76 #else
77 {
78 for(e=0;e<elements->numElements;e++) {
79 {
80 #endif
81 Vol=&(p.row_jac->volume[INDEX2(0,e,p.numQuad)]);
82 add_EM_F=FALSE;
83 add_EM_S=FALSE;
84 /************************************************************* */
85 /* process D */
86 /**************************************************************/
87 D_p=getSampleData(D,e);
88 if (NULL!=D_p) {
89 add_EM_S=TRUE;
90 if (extendedD) {
91 for (s=0;s<p.row_NS;s++) {
92 for (r=0;r<p.col_NS;r++) {
93 for (k=0;k<p.numEqu;k++) {
94 for (m=0;m<p.numComp;m++) {
95 rtmp=0;
96 for (q=0;q<p.numQuad;q++) {
97 rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*D_p[INDEX3(k,m,q,p.numEqu,p.numComp)]*S[INDEX2(r,q,p.row_NS)];
98 }
99 EM_S[INDEX4(k,m,s ,r ,p.numEqu,p.numComp,p.row_NN)]= rtmp;
100 EM_S[INDEX4(k,m,s ,r+p.col_NS,p.numEqu,p.numComp,p.row_NN)]=-rtmp;
101 EM_S[INDEX4(k,m,s+p.row_NS,r ,p.numEqu,p.numComp,p.row_NN)]=-rtmp;
102 EM_S[INDEX4(k,m,s+p.row_NS,r+p.col_NS,p.numEqu,p.numComp,p.row_NN)]= rtmp;
103 }
104 }
105 }
106 }
107 } else {
108 for (s=0;s<p.row_NS;s++) {
109 for (r=0;r<p.col_NS;r++) {
110 rtmp=0;
111 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*S[INDEX2(r,q,p.row_NS)];
112 for (k=0;k<p.numEqu;k++) {
113 for (m=0;m<p.numComp;m++) {
114 rtmp_D=rtmp*D_p[INDEX2(k,m,p.numEqu)];
115 EM_S[INDEX4(k,m,s ,r ,p.numEqu,p.numComp,p.row_NN)]= rtmp_D;
116 EM_S[INDEX4(k,m,s ,r+p.col_NS,p.numEqu,p.numComp,p.row_NN)]=-rtmp_D;
117 EM_S[INDEX4(k,m,s+p.row_NS,r ,p.numEqu,p.numComp,p.row_NN)]=-rtmp_D;
118 EM_S[INDEX4(k,m,s+p.row_NS,r+p.col_NS,p.numEqu,p.numComp,p.row_NN)]= rtmp_D;
119 }
120 }
121 }
122 }
123 }
124 }
125 /**************************************************************/
126 /* process Y: */
127 /**************************************************************/
128 Y_p=getSampleData(Y,e);
129 if (NULL!=Y_p) {
130 add_EM_F=TRUE;
131 if (extendedY) {
132 for (s=0;s<p.row_NS;s++) {
133 for (k=0;k<p.numEqu;k++) {
134 rtmp=0;
135 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)]*Y_p[INDEX2(k,q,p.numEqu)];
136 EM_F[INDEX2(k,s ,p.numEqu)]=-rtmp;
137 EM_F[INDEX2(k,s+p.row_NS,p.numEqu)]= rtmp;
138 }
139 }
140 } else {
141 for (s=0;s<p.row_NS;s++) {
142 rtmp=0;
143 for (q=0;q<p.numQuad;q++) rtmp+=Vol[q]*S[INDEX2(s,q,p.row_NS)];
144 for (k=0;k<p.numEqu;k++) {
145 rtmp_D=rtmp*Y_p[k];
146 EM_F[INDEX2(k,s ,p.numEqu)]=-rtmp_D;
147 EM_F[INDEX2(k,s+p.row_NS,p.numEqu)]= rtmp_D;
148 }
149 }
150 }
151 }
152 /***********************************************************************************************/
153 /* add the element matrices onto the matrix and right hand side */
154 /***********************************************************************************************/
155 for (q=0;q<p.row_NN;q++) row_index[q]=p.row_DOF[elements->Nodes[INDEX2(p.row_node[q],e,p.row_NN)]];
156 if (add_EM_F) Finley_Util_AddScatter(p.row_NN,row_index,p.numEqu,EM_F,F_p, p.row_DOF_UpperBound);
157 if (add_EM_S) Finley_Assemble_addToSystemMatrix(Mat,p.row_NN,row_index,p.numEqu,p.col_NN,row_index,p.numComp,EM_S);
158
159 } /* end color check */
160 } /* end element loop */
161 } /* end color loop */
162
163 THREAD_MEMFREE(EM_S);
164 THREAD_MEMFREE(EM_F);
165 THREAD_MEMFREE(row_index);
166
167 } /* end of pointer check */
168 } /* end parallel region */
169 }
170 /*
171 * $Log$
172 */

  ViewVC Help
Powered by ViewVC 1.1.26