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,*nrhcon1,*ielmatf1,*ntmat1_,*ithermal1,*mi1,*num_cpus1;
26
27 static double *vel1,*rhcon1;
28
calcrhoelmain(ITG * nef,double * vel,double * rhcon,ITG * nrhcon,ITG * ielmatf,ITG * ntmat_,ITG * ithermal,ITG * mi,ITG * num_cpus)29 void calcrhoelmain(ITG *nef,double *vel,double *rhcon,ITG *nrhcon,
30 ITG *ielmatf,ITG *ntmat_,ITG *ithermal,ITG *mi,
31 ITG *num_cpus){
32
33 ITG i;
34
35 /* variables for multithreading procedure */
36
37 ITG *ithread=NULL;;
38
39 pthread_t tid[*num_cpus];
40
41 /* calculation of the density at the cell centers */
42
43 nef1=nef;vel1=vel;rhcon1=rhcon;nrhcon1=nrhcon;ielmatf1=ielmatf;
44 ntmat1_=ntmat_;ithermal1=ithermal;mi1=mi;num_cpus1=num_cpus;
45
46 /* create threads and wait */
47
48 NNEW(ithread,ITG,*num_cpus);
49 for(i=0; i<*num_cpus; i++) {
50 ithread[i]=i;
51 pthread_create(&tid[i], NULL, (void *)calcrhoel1mt, (void *)&ithread[i]);
52 }
53 for(i=0; i<*num_cpus; i++) pthread_join(tid[i], NULL);
54
55 SFREE(ithread);
56
57 return;
58
59 }
60
61 /* subroutine for multithreading of materialdatacfd1 */
62
calcrhoel1mt(ITG * i)63 void *calcrhoel1mt(ITG *i){
64
65 ITG nefa,nefb,nefdelta;
66
67 nefdelta=(ITG)floor(*nef1/(double)(*num_cpus1));
68 nefa=*i*nefdelta+1;
69 nefb=(*i+1)*nefdelta;
70 if((*i==*num_cpus1-1)&&(nefb<*nef1)) nefb=*nef1;
71
72 FORTRAN(calcrhoel1,(nef1,vel1,rhcon1,nrhcon1,ielmatf1,ntmat1_,
73 ithermal1,mi1,&nefa,&nefb));
74
75 return NULL;
76 }
77