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 *ipnei1,*nef1,*neifa1,*ielfa1,*neiel1,*ifabou1,*num_cpus1;
26
27 static double *area1,*vfa1,*xxna1,*flux1,*xxj1,*gradpfa1,*xlet1,*xle1,
28 *vel1,*advfa1,*hfa1;
29
calcfluxmain(double * area,double * vfa,double * xxna,ITG * ipnei,ITG * nef,ITG * neifa,double * flux,double * xxj,double * gradpfa,double * xlet,double * xle,double * vel,double * advfa,ITG * ielfa,ITG * neiel,ITG * ifabou,double * hfa,ITG * num_cpus)30 void calcfluxmain(double *area,double *vfa,double *xxna,ITG *ipnei,
31 ITG *nef,ITG *neifa,double *flux,double *xxj,
32 double *gradpfa,double *xlet,double *xle,double *vel,
33 double *advfa,ITG *ielfa,ITG *neiel,ITG *ifabou,
34 double *hfa,ITG *num_cpus){
35
36 ITG i;
37
38 /* variables for multithreading procedure */
39
40 ITG *ithread=NULL;;
41
42 pthread_t tid[*num_cpus];
43
44 /* calculation of the density at the cell centers */
45
46 area1=area;vfa1=vfa;xxna1=xxna;ipnei1=ipnei;nef1=nef;neifa1=neifa;
47 flux1=flux;xxj1=xxj;gradpfa1=gradpfa;xlet1=xlet;xle1=xle;vel1=vel;
48 advfa1=advfa;ielfa1=ielfa;neiel1=neiel;ifabou1=ifabou;hfa1=hfa;
49 num_cpus1=num_cpus;
50
51 /* create threads and wait */
52
53 NNEW(ithread,ITG,*num_cpus);
54 for(i=0; i<*num_cpus; i++) {
55 ithread[i]=i;
56 pthread_create(&tid[i], NULL, (void *)calcflux1mt, (void *)&ithread[i]);
57 }
58 for(i=0; i<*num_cpus; i++) pthread_join(tid[i], NULL);
59
60 SFREE(ithread);
61
62 return;
63
64 }
65
66 /* subroutine for multithreading of materialdatacfd1 */
67
calcflux1mt(ITG * i)68 void *calcflux1mt(ITG *i){
69
70 ITG nefa,nefb,nefdelta;
71
72 nefdelta=(ITG)floor(*nef1/(double)(*num_cpus1));
73 nefa=*i*nefdelta+1;
74 nefb=(*i+1)*nefdelta;
75 if((*i==*num_cpus1-1)&&(nefb<*nef1)) nefb=*nef1;
76
77 FORTRAN(calcflux,(area1,vfa1,xxna1,ipnei1,nef1,neifa1,flux1,xxj1,
78 gradpfa1,xlet1,xle1,vel1,advfa1,ielfa1,neiel1,
79 ifabou1,hfa1,&nefa,&nefb));
80
81 return NULL;
82 }
83