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,*ielfa1,*ipnei1,*nef1,*num_cpus1;
26 
27 static double *vel1,*gradvel1,*xlet1,*xxj1,*flux1,*vfa1;
28 
hrv_mod_smartmain(ITG * nface,ITG * ielfa,double * vel,double * gradvel,double * xlet,double * xxj,ITG * ipnei,ITG * nef,double * flux,double * vfa,ITG * num_cpus)29 void hrv_mod_smartmain(ITG *nface,ITG *ielfa,double *vel,double *gradvel,
30 		       double *xlet,double *xxj,ITG *ipnei,ITG *nef,
31 		       double *flux,double *vfa,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     ielfa1=ielfa;vel1=vel;gradvel1=gradvel;xlet1=xlet;xxj1=xxj;
44     ipnei1=ipnei;nef1=nef;flux1=flux;vfa1=vfa;num_cpus1=num_cpus;
45     nface1=nface;
46 
47     /* create threads and wait */
48 
49     NNEW(ithread,ITG,*num_cpus);
50     for(i=0; i<*num_cpus; i++)  {
51 	ithread[i]=i;
52 	pthread_create(&tid[i], NULL, (void *)hrv_mod_smart1mt, (void *)&ithread[i]);
53     }
54     for(i=0; i<*num_cpus; i++)  pthread_join(tid[i], NULL);
55 
56     SFREE(ithread);
57 
58   return;
59 
60 }
61 
62 /* subroutine for multithreading of hrv_mod_smart */
63 
hrv_mod_smart1mt(ITG * i)64 void *hrv_mod_smart1mt(ITG *i){
65 
66     ITG nfacea,nfaceb,nfacedelta;
67 
68     nfacedelta=(ITG)floor(*nface1/(double)(*num_cpus1));
69     nfacea=*i*nfacedelta+1;
70     nfaceb=(*i+1)*nfacedelta;
71     if((*i==*num_cpus1-1)&&(nfaceb<*nface1)) nfaceb=*nface1;
72 
73     FORTRAN(hrv_mod_smart,(ielfa1,vel1,gradvel1,xlet1,xxj1,ipnei1,
74 			    nef1,flux1,vfa1,&nfacea,&nfaceb));
75 
76     return NULL;
77 }
78