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 *nface1,*ielmatf1,*ntmat1_,*mi1,*ielfa1,*ipnei1,*nef1,*num_cpus1,
26     *nface1,*neij1;
27 
28 static double *vfa1,*shcon1,*vel1,*flux1,*xxi1,*xle1,*gradpel1,*gradtel1;
29 
hrr_udmain(ITG * nface,double * vfa,double * shcon,ITG * ielmatf,ITG * ntmat_,ITG * mi,ITG * ielfa,ITG * ipnei,double * vel,ITG * nef,double * flux,ITG * num_cpus,double * xxi,double * xle,double * gradpel,double * gradtel,ITG * neij)30 void hrr_udmain(ITG *nface,double *vfa,double *shcon,ITG *ielmatf,ITG *ntmat_,
31 			  ITG *mi,ITG *ielfa,ITG *ipnei,double *vel,ITG *nef,
32 			  double *flux,ITG *num_cpus,double *xxi,double *xle,
33                           double *gradpel,double *gradtel,ITG *neij){
34 
35     ITG i;
36 
37     /* variables for multithreading procedure */
38 
39     ITG *ithread=NULL;;
40 
41     pthread_t tid[*num_cpus];
42 
43     /* calculation of the density at the cell centers */
44 
45     vfa1=vfa;shcon1=shcon;ielmatf1=ielmatf;ntmat1_=ntmat_;mi1=mi;ielfa1=ielfa;
46     ipnei1=ipnei;vel1=vel;nef1=nef;flux1=flux;num_cpus1=num_cpus;nface1=nface;
47     xxi1=xxi;xle1=xle;gradpel1=gradpel;gradtel1=gradtel;neij1=neij;
48 
49     /* create threads and wait */
50 
51     NNEW(ithread,ITG,*num_cpus);
52     for(i=0; i<*num_cpus; i++)  {
53 	ithread[i]=i;
54 	pthread_create(&tid[i], NULL, (void *)hrr_ud1mt, (void *)&ithread[i]);
55     }
56     for(i=0; i<*num_cpus; i++)  pthread_join(tid[i], NULL);
57 
58     SFREE(ithread);
59 
60   return;
61 
62 }
63 
64 /* subroutine for multithreading of calcgammav1 */
65 
hrr_ud1mt(ITG * i)66 void *hrr_ud1mt(ITG *i){
67 
68     ITG nfacea,nfaceb,nfacedelta;
69 
70     nfacedelta=(ITG)floor(*nface1/(double)(*num_cpus1));
71     nfacea=*i*nfacedelta+1;
72     nfaceb=(*i+1)*nfacedelta;
73     if((*i==*num_cpus1-1)&&(nfaceb<*nface1)) nfaceb=*nface1;
74 
75     FORTRAN(hrr_ud,(vfa1,shcon1,ielmatf1,ntmat1_,mi1,ielfa1,
76 			      ipnei1,vel1,nef1,flux1,&nfacea,&nfaceb,
77                               xxi1,xle1,gradpel1,gradtel1,neij1));
78 
79     return NULL;
80 }
81