1 /* CalculiX - A 3-dimensional finite element program */
2 /* Copyright (C) 1998-2021 Guido Dhondt */
3
4 /* This program is free software; you can redistribute it and/or */
5 /* modify it under the terms of the GNU General Public License as */
6 /* published by the Free Software Foundation(version 2); */
7 /* */
8
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program; if not, write to the Free Software */
16 /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
17
18 #include <unistd.h>
19 #include <stdio.h>
20 #include <math.h>
21 #include <stdlib.h>
22 #include <pthread.h>
23 #include "CalculiX.h"
24
25 static ITG *nef1,*nshcon1,*ielmatf1,*ntmat1_,*mi1,*ithermal1,*nrhcon1,
26 *ncocon1,*ielfa1,*num_cpus1,*nface1;
27
28 static double *vel1,*shcon1,*cvel1,*physcon1,*umel1,*rhcon1,*vfa1,*cocon1,
29 *cvfa1,*umfa1,*hcfa1;
30
materialdata_cfdmain(ITG * nef,double * vel,double * shcon,ITG * nshcon,ITG * ielmatf,ITG * ntmat_,ITG * mi,double * cvel,double * vfa,double * cocon,ITG * ncocon,double * physcon,double * cvfa,ITG * ithermal,ITG * nface,double * umel,double * umfa,ITG * ielfa,double * hcfa,double * rhcon,ITG * nrhcon,ITG * num_cpus)31 void materialdata_cfdmain(ITG *nef,double *vel,double *shcon,ITG *nshcon,
32 ITG *ielmatf,ITG *ntmat_,ITG *mi,double *cvel,
33 double *vfa,double *cocon,ITG *ncocon,
34 double *physcon,double *cvfa,ITG *ithermal,
35 ITG *nface,double *umel,double *umfa,ITG *ielfa,
36 double *hcfa,double *rhcon,ITG *nrhcon,ITG *num_cpus){
37
38 ITG i;
39
40 /* variables for multithreading procedure */
41
42 ITG *ithread=NULL;;
43
44 pthread_t tid[*num_cpus];
45
46 /* calculation of the density at the cell centers */
47
48 nef1=nef;vel1=vel;shcon1=shcon;nshcon1=nshcon;ielmatf1=ielmatf;
49 ntmat1_=ntmat_;mi1=mi;cvel1=cvel;physcon1=physcon;ithermal1=ithermal;
50 umel1=umel;rhcon1=rhcon;nrhcon1=nrhcon;num_cpus1=num_cpus;
51
52 /* create threads and wait */
53
54 NNEW(ithread,ITG,*num_cpus);
55 for(i=0; i<*num_cpus; i++) {
56 ithread[i]=i;
57 pthread_create(&tid[i], NULL, (void *)materialdata_cfd1mt, (void *)&ithread[i]);
58 }
59 for(i=0; i<*num_cpus; i++) pthread_join(tid[i], NULL);
60
61 SFREE(ithread);
62
63 /* calculate the density at the face centers */
64
65 shcon1=shcon;nshcon1=nshcon;ielmatf1=ielmatf;ntmat1_=ntmat_;mi1=mi;vfa1=vfa;
66 cocon1=cocon;ncocon1=ncocon;physcon1=physcon;cvfa1=cvfa;ithermal1=ithermal;
67 umfa1=umfa;ielfa1=ielfa;hcfa1=hcfa;rhcon1=rhcon;nrhcon1=nrhcon;
68 num_cpus1=num_cpus;nface1=nface;
69
70 /* create threads and wait */
71
72 NNEW(ithread,ITG,*num_cpus);
73 for(i=0; i<*num_cpus; i++) {
74 ithread[i]=i;
75 pthread_create(&tid[i], NULL, (void *)materialdata_cfd2mt, (void *)&ithread[i]);
76 }
77 for(i=0; i<*num_cpus; i++) pthread_join(tid[i], NULL);
78
79 SFREE(ithread);
80
81 return;
82
83 }
84
85 /* subroutine for multithreading of materialdatacfd1 */
86
materialdata_cfd1mt(ITG * i)87 void *materialdata_cfd1mt(ITG *i){
88
89 ITG nefa,nefb,nefdelta;
90
91 nefdelta=(ITG)floor(*nef1/(double)(*num_cpus1));
92 nefa=*i*nefdelta+1;
93 nefb=(*i+1)*nefdelta;
94 if((*i==*num_cpus1-1)&&(nefb<*nef1)) nefb=*nef1;
95
96 FORTRAN(materialdata_cfd1,(nef1,vel1,shcon1,nshcon1,ielmatf1,
97 ntmat1_,mi1,cvel1,physcon1,ithermal1,
98 umel1,rhcon1,nrhcon1,&nefa,&nefb));
99
100 return NULL;
101 }
102
103 /* subroutine for multithreading of materialdata_cfd2 */
104
materialdata_cfd2mt(ITG * i)105 void *materialdata_cfd2mt(ITG *i){
106
107 ITG nfacea,nfaceb,nfacedelta;
108
109 nfacedelta=(ITG)floor(*nface1/(double)(*num_cpus1));
110 nfacea=*i*nfacedelta+1;
111 nfaceb=(*i+1)*nfacedelta;
112 if((*i==*num_cpus1-1)&&(nfaceb<*nface1)) nfaceb=*nface1;
113
114 FORTRAN(materialdata_cfd2,(shcon1,nshcon1,ielmatf1,ntmat1_,
115 mi1,vfa1,cocon1,ncocon1,physcon1,
116 cvfa1,ithermal1,umfa1,ielfa1,hcfa1,
117 rhcon1,nrhcon1,&nfacea,&nfaceb));
118
119 return NULL;
120 }
121