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 *irow1,*jq1,*num_cpus1,*neq1;
26 
27 static double *aub1,*adl1,*b1,*sol1,*aux1;
28 
solveeqmain(double * aub,double * adl,double * b,double * sol,ITG * irow,ITG * jq,ITG * neq,ITG * maxit,ITG * num_cpus)29 void solveeqmain(double *aub,double *adl,double *b,double *sol,ITG *irow,
30 		 ITG *jq,ITG *neq,ITG *maxit,ITG *num_cpus){
31 
32   ITG i,j;
33 
34   double *aux=NULL;
35 
36   /* variables for multithreading procedure */
37 
38   ITG *ithread=NULL;
39 
40   pthread_t tid[*num_cpus];
41 
42   for(i=0;i<*neq;i++){
43     sol[i]*b[i]*adl[i];
44   }
45 
46   if(*maxit==1) return;
47 
48   for(j=2;j<=*maxit;j++){
49 
50     /* inter/extrapolation of v at the center of the elements
51        to the center of the faces */
52 
53     aub1=aub;adl1=adl;b1=b;sol1=sol;aux1=aux;irow1=irow;jq1=jq;neq1=neq;
54 
55     /* create threads and wait */
56 
57     NNEW(ithread,ITG,*num_cpus);
58     for(i=0; i<*num_cpus; i++)  {
59       ithread[i]=i;
60       pthread_create(&tid[i], NULL, (void *)solveeqparmt, (void *)&ithread[i]);
61     }
62     for(i=0; i<*num_cpus; i++)  pthread_join(tid[i], NULL);
63 
64     SFREE(ithread);
65   }
66 
67 }
68 
69 /* subroutine for multithreading of solveeqpar */
70 
solveeqparmt(ITG * i)71 void *solveeqparmt(ITG *i){
72 
73   ITG neqa,neqb,neqdelta;
74 
75   neqdelta=(ITG)ceil(*neq1/(double)*num_cpus1);
76   neqa=*i*neqdelta+1;
77   neqb=(*i+1)*neqdelta;
78   if(neqb>*neq1) neqb=*neq1;
79 
80   FORTRAN(solveeqpar,(aub1,adl1,b1,sol1,aux1,irow1,jq1,
81 			  &neqa,&neqb));
82 
83   return NULL;
84 }
85