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
setparitg(ITG * iva1,ITG iva2,ITG isize,ITG num_cpus)32 void setparitg(ITG *iva1,ITG iva2,ITG isize,ITG num_cpus){
33
34 /* set elements of ITG array var1 to scalar var2 */
35
36 ITG i,idelta,isum;
37
38 /* variables for multithreading procedure */
39
40 ITG *ithread=NULL;
41
42 pthread_t tid[num_cpus];
43
44 /* determining the element bounds in each thread */
45
46 NNEW(neapar,ITG,num_cpus);
47 NNEW(nebpar,ITG,num_cpus);
48
49 /* dividing the element number range into num_cpus equal numbers of
50 active entries. */
51
52 idelta=(ITG)floor(isize/(double)(num_cpus));
53 isum=0;
54 for(i=0;i<num_cpus;i++){
55 neapar[i]=isum;
56 if(i!=num_cpus-1){
57 isum+=idelta;
58 }else{
59 isum=isize;
60 }
61 nebpar[i]=isum;
62 }
63
64 /* create threads and wait */
65 iva11=iva1;iva21=&iva2;
66 NNEW(ithread,ITG,num_cpus);
67
68 for(i=0; i<num_cpus; i++) {
69 ithread[i]=i;
70 pthread_create(&tid[i], NULL, (void *)setparitgmt, (void *)&ithread[i]);
71 }
72 for(i=0; i<num_cpus; i++) pthread_join(tid[i], NULL);
73
74 SFREE(ithread);SFREE(neapar);SFREE(nebpar);
75
76 }
77
78 /* subroutine for multithreading of copyarray*/
79
setparitgmt(ITG * i)80 void *setparitgmt(ITG *i){
81
82 ITG nea,neb,j;
83
84 nea=neapar[*i];
85 neb=nebpar[*i];
86
87 for(j=nea;j<neb;j++){
88 iva11[j]=*iva21;
89 }
90
91 return NULL;
92 }
93