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,*ipnei1,*neifa1,*neiel1,*ielfa1,*ifabou1,*ielmatf1,
26   *mi1,*ntmat1_,*num_cpus1,*inlet1;
27 
28 static double *flux1,*vfa1,*advfa1,*area1,*vel1,*alet1,*ale1,*shcon1,
29   *xxnj1,*gradpcfa1;
30 
correctfluxcompmain(ITG * nef,ITG * ipnei,ITG * neifa,ITG * neiel,double * flux,double * vfa,double * advfa,double * area,double * vel,double * alet,ITG * ielfa,double * ale,ITG * ifabou,ITG * ielmatf,ITG * mi,double * shcon,ITG * ntmat_,ITG * num_cpus,double * xxnj,double * gradpcfa,ITG * inlet)31 void correctfluxcompmain(ITG *nef,ITG *ipnei,ITG *neifa,ITG *neiel,double *flux,
32 			 double *vfa,double *advfa,double *area,double *vel,
33 			 double *alet,ITG *ielfa,double *ale,ITG *ifabou,
34 			 ITG *ielmatf,ITG *mi,double *shcon,ITG *ntmat_,
35 			 ITG *num_cpus,double *xxnj,double *gradpcfa,
36 			 ITG *inlet){
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;ipnei1=ipnei;neifa1=neifa;neiel1=neiel;flux1=flux;vfa1=vfa;
49     advfa1=advfa;area1=area;vel1=vel;alet1=alet;ielfa1=ielfa;ale1=ale;
50     ifabou1=ifabou;ielmatf1=ielmatf;mi1=mi;shcon1=shcon;ntmat1_=ntmat_;
51     num_cpus1=num_cpus;xxnj1=xxnj;gradpcfa1=gradpcfa;inlet1=inlet;
52 
53     /* create threads and wait */
54 
55     NNEW(ithread,ITG,*num_cpus);
56     for(i=0; i<*num_cpus; i++)  {
57 	ithread[i]=i;
58 	pthread_create(&tid[i], NULL, (void *)correctfluxcomp1mt, (void *)&ithread[i]);
59     }
60     for(i=0; i<*num_cpus; i++)  pthread_join(tid[i], NULL);
61 
62     SFREE(ithread);
63 
64   return;
65 
66 }
67 
68 /* subroutine for multithreading of materialdatacfd1 */
69 
correctfluxcomp1mt(ITG * i)70 void *correctfluxcomp1mt(ITG *i){
71 
72     ITG nefa,nefb,nefdelta;
73 
74     nefdelta=(ITG)floor(*nef1/(double)(*num_cpus1));
75     nefa=*i*nefdelta+1;
76     nefb=(*i+1)*nefdelta;
77     if((*i==*num_cpus1-1)&&(nefb<*nef1)) nefb=*nef1;
78 
79     FORTRAN(correctfluxcomp,(nef1,ipnei1,neifa1,neiel1,flux1,vfa1,advfa1,
80 			     area1,vel1,alet1,ielfa1,ale1,ifabou1,ielmatf1,
81 			     mi1,shcon1,ntmat1_,&nefa,&nefb,xxnj1,gradpcfa1,
82 			     inlet1));
83 
84     return NULL;
85 }
86