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 /*     A parallel copy of arrays which depent on active element 	 */
19 
20 
21 #include <unistd.h>
22 #include <stdio.h>
23 #include <math.h>
24 #include <stdlib.h>
25 #include <pthread.h>
26 #include "CalculiX.h"
27 
28 static ITG *neapar=NULL,*nebpar=NULL;
29 
30 static ITG *iva11=NULL,*iva21=NULL;
31 
cpyparitg(ITG * iva1,ITG * iva2,ITG * isize,ITG * num_cpus)32 void cpyparitg(ITG *iva1,ITG *iva2,ITG *isize,ITG *num_cpus){
33 
34 
35 //    static ITG i,num_cpus,nepar,idelta,isum,*ipar=NULL;
36 
37     ITG i,idelta,isum;
38 
39     /* variables for multithreading procedure */
40 
41     ITG *ithread=NULL;
42 
43     pthread_t tid[*num_cpus];
44 
45     /* determining the element bounds in each thread */
46 
47     NNEW(neapar,ITG,*num_cpus);
48     NNEW(nebpar,ITG,*num_cpus);
49 
50     /* dividing the element number range into num_cpus equal numbers of
51        active entries.  */
52 
53     idelta=(ITG)floor(*isize/(double)(*num_cpus));
54     isum=0;
55     for(i=0;i<*num_cpus;i++){
56 	neapar[i]=isum;
57 	if(i!=*num_cpus-1){
58 	    isum+=idelta;
59 	}else{
60 	    isum=*isize;
61 	}
62 	nebpar[i]=isum;
63     }
64 
65     /* create threads and wait */
66     iva11=iva1;iva21=iva2;
67     NNEW(ithread,ITG,*num_cpus);
68 
69     for(i=0; i<*num_cpus; i++)  {
70       ithread[i]=i;
71       pthread_create(&tid[i], NULL, (void *)cpyparitgmt, (void *)&ithread[i]);
72     }
73     for(i=0; i<*num_cpus; i++)  pthread_join(tid[i], NULL);
74 
75     SFREE(ithread);SFREE(neapar);SFREE(nebpar);
76 
77 }
78 
79 /* subroutine for multithreading of copyarray*/
80 
cpyparitgmt(ITG * i)81 void *cpyparitgmt(ITG *i){
82 
83     ITG nea,neb,j;
84 
85     nea=neapar[*i];
86     neb=nebpar[*i];
87 
88     for(j=nea;j<neb;j++){
89     	iva11[j]=iva21[j];
90     }
91 
92     return NULL;
93 }
94