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 *iamorig1,*nz_num1,*num_cpus1;
26 
27 static double *au1,*am1;
28 
reorderlhsmain(double * au,double * am,ITG * iamorig,ITG * nz_num,ITG * num_cpus)29 void reorderlhsmain(double *au,double *am,ITG *iamorig,ITG *nz_num,
30 		    ITG *num_cpus){
31 
32     ITG i;
33 
34     /* variables for multithreading procedure */
35 
36     ITG *ithread=NULL;;
37 
38     pthread_t tid[*num_cpus];
39 
40     /* calculation of the density at the cell centers */
41 
42     au1=au;am1=am;iamorig1=iamorig;nz_num1=nz_num;num_cpus1=num_cpus;
43 
44     /* create threads and wait */
45 
46     NNEW(ithread,ITG,*num_cpus);
47     for(i=0; i<*num_cpus; i++)  {
48 	ithread[i]=i;
49 	pthread_create(&tid[i], NULL, (void *)reorderlhs1mt, (void *)&ithread[i]);
50     }
51     for(i=0; i<*num_cpus; i++)  pthread_join(tid[i], NULL);
52 
53     SFREE(ithread);
54 
55   return;
56 
57 }
58 
59 /* subroutine for multithreading of calcgammav1 */
60 
reorderlhs1mt(ITG * i)61 void *reorderlhs1mt(ITG *i){
62 
63     ITG nz_numa,nz_numb,nz_numdelta;
64 
65     nz_numdelta=(ITG)floor(*nz_num1/(double)(*num_cpus1));
66     nz_numa=*i*nz_numdelta+1;
67     nz_numb=(*i+1)*nz_numdelta;
68     if((*i==*num_cpus1-1)&&(nz_numb<*nz_num1)) nz_numb=*nz_num1;
69 
70     FORTRAN(reorderlhs,(au1,am1,iamorig1,&nz_numa,&nz_numb));
71 
72     return NULL;
73 }
74