CalculiX  2.13
A Free Software Three-Dimensional Structural Finite Element Program
biosav.c File Reference
#include <unistd.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <pthread.h>
#include "CalculiX.h"
Include dependency graph for biosav.c:

Go to the source code of this file.

Functions

void biosav (ITG *ipkon, ITG *kon, char *lakon, ITG *ne, double *co, double *qfx, double *h0, ITG *mi, ITG *inomat, ITG *nk)
 
void * biotsavartmt (ITG *i)
 

Variables

static char * lakon1
 
static ITGkon1
 
static ITGipkon1
 
static ITGne1
 
static ITGmi1
 
static ITG num_cpus
 
static ITGnkapar =NULL
 
static ITGnkepar =NULL
 
static double * co1
 
static double * qfx1
 
static double * h01
 

Function Documentation

◆ biosav()

void biosav ( ITG ipkon,
ITG kon,
char *  lakon,
ITG ne,
double *  co,
double *  qfx,
double *  h0,
ITG mi,
ITG inomat,
ITG nk 
)
32  {
33 
34  ITG i,j,*ithread=NULL,nkphi,idelta,isum;
35 
36  /* calculates the magnetic intensity due to currents in the phi-
37  domain of an electromagnetic calculation */
38 
39  /* variables for multithreading procedure */
40 
41  ITG sys_cpus;
42  char *env,*envloc,*envsys;
43 
44  num_cpus = 0;
45  sys_cpus=0;
46 
47  /* explicit user declaration prevails */
48 
49  envsys=getenv("NUMBER_OF_CPUS");
50  if(envsys){
51  sys_cpus=atoi(envsys);
52  if(sys_cpus<0) sys_cpus=0;
53  }
54 
55  /* automatic detection of available number of processors */
56 
57  if(sys_cpus==0){
58  sys_cpus = getSystemCPUs();
59  if(sys_cpus<1) sys_cpus=1;
60  }
61 
62  /* local declaration prevails, if strictly positive */
63 
64  envloc = getenv("CCX_NPROC_BIOTSAVART");
65  if(envloc){
66  num_cpus=atoi(envloc);
67  if(num_cpus<0){
68  num_cpus=0;
69  }else if(num_cpus>sys_cpus){
70  num_cpus=sys_cpus;
71  }
72  }
73 
74  /* else global declaration, if any, applies */
75 
76  env = getenv("OMP_NUM_THREADS");
77  if(num_cpus==0){
78  if (env)
79  num_cpus = atoi(env);
80  if (num_cpus < 1) {
81  num_cpus=1;
82  }else if(num_cpus>sys_cpus){
83  num_cpus=sys_cpus;
84  }
85  }
86 
87  /* determining the nodal bounds in each thread */
88 
91 
92  /* n1 is the number of nodes in the phi(magnetostatic)-domain in
93  an electromagnetic calculation */
94 
95  nkphi=0;
96  for(i=0;i<*nk;i++){
97  if(inomat[i]==1) nkphi++;
98  }
99  if(nkphi<num_cpus) num_cpus=nkphi;
100 
101  idelta=nkphi/num_cpus;
102 
103  /* dividing the range from 1 to the number of phi-nodes */
104 
105  isum=0;
106  for(i=0;i<num_cpus;i++){
107  nkapar[i]=isum;
108  if(i!=num_cpus-1){
109  isum+=idelta;
110  }else{
111  isum=nkphi;
112  }
113  nkepar[i]=isum-1;
114  }
115 
116  /* translating the bounds of the ranges to real node numbers */
117 
118 // i=0;
119  i=-1;
120  j=0;
121  nkphi=-1;
122 
123  do{
124  if(j==num_cpus) break;
125  do{
126  if(nkapar[j]==nkphi){
127  nkapar[j]=i;
128  break;
129  }else{
130  do{
131  i++;
132  if(inomat[i]==1){
133  nkphi++;
134  break;
135  }
136  }while(1);
137  }
138  }while(1);
139 
140  do{
141  if(nkepar[j]==nkphi){
142  nkepar[j]=i;
143  j++;
144  break;
145  }else{
146  do{
147  i++;
148  if(inomat[i]==1){
149  nkphi++;
150  break;
151  }
152  }while(1);
153  }
154  }while(1);
155  }while(1);
156 
157  ipkon1=ipkon;kon1=kon;lakon1=lakon;ne1=ne;co1=co;qfx1=qfx;
158  h01=h0;mi1=mi;
159 
160  printf(" Using up to %" ITGFORMAT " cpu(s) for the Biot-Savart calculation.\n\n", num_cpus);
161 
162  /* create threads and wait */
163 
164  pthread_t tid[num_cpus];
165 
166  NNEW(ithread,ITG,num_cpus);
167  for(i=0;i<num_cpus;i++){
168  ithread[i]=i;
169  pthread_create(&tid[i],NULL,(void *)biotsavartmt,(void *)&ithread[i]);
170  }
171  for(i=0;i<num_cpus;i++)pthread_join(tid[i], NULL);
172 
173  SFREE(ithread);SFREE(nkapar);SFREE(nkepar);
174 
175  return;
176 
177 }
#define ITGFORMAT
Definition: CalculiX.h:52
int pthread_create(pthread_t *thread_id, const pthread_attr_t *attributes, void *(*thread_function)(void *), void *arguments)
static ITG num_cpus
Definition: biosav.c:27
static ITG * ne1
Definition: biosav.c:27
static char * lakon1
Definition: biosav.c:25
static ITG * mi1
Definition: biosav.c:27
void * biotsavartmt(ITG *i)
Definition: biosav.c:181
static ITG * ipkon1
Definition: biosav.c:27
ITG getSystemCPUs()
Definition: getSystemCPUs.c:40
static double * qfx1
Definition: biosav.c:29
static double * co1
Definition: biosav.c:29
static ITG * nkapar
Definition: biosav.c:27
#define SFREE(a)
Definition: CalculiX.h:41
int pthread_join(pthread_t thread, void **status_ptr)
#define ITG
Definition: CalculiX.h:51
static ITG * kon1
Definition: biosav.c:27
static ITG * nkepar
Definition: biosav.c:27
#define NNEW(a, b, c)
Definition: CalculiX.h:39
static double * h01
Definition: biosav.c:29

◆ biotsavartmt()

void* biotsavartmt ( ITG i)
181  {
182 
183  ITG nka,nkb;
184 
185  nka=nkapar[*i]+1;
186  nkb=nkepar[*i]+1;
187 
189  &nkb));
190 
191  return NULL;
192 }
subroutine biotsavart(ipkon, kon, lakon, ne, co, qfx, h0, mi, nka, nkb)
Definition: biotsavart.f:20
static ITG * ne1
Definition: biosav.c:27
static char * lakon1
Definition: biosav.c:25
void FORTRAN(actideacti,(char *set, ITG *nset, ITG *istartset, ITG *iendset, ITG *ialset, char *objectset, ITG *ipkon, ITG *ibject, ITG *ne))
static ITG * mi1
Definition: biosav.c:27
static ITG * ipkon1
Definition: biosav.c:27
static double * qfx1
Definition: biosav.c:29
static double * co1
Definition: biosav.c:29
static ITG * nkapar
Definition: biosav.c:27
#define ITG
Definition: CalculiX.h:51
static ITG * kon1
Definition: biosav.c:27
static ITG * nkepar
Definition: biosav.c:27
static double * h01
Definition: biosav.c:29

Variable Documentation

◆ co1

double* co1
static

◆ h01

double * h01
static

◆ ipkon1

ITG * ipkon1
static

◆ kon1

ITG* kon1
static

◆ lakon1

char* lakon1
static

◆ mi1

ITG * mi1
static

◆ ne1

ITG * ne1
static

◆ nkapar

ITG * nkapar =NULL
static

◆ nkepar

ITG * nkepar =NULL
static

◆ num_cpus

ITG num_cpus
static

◆ qfx1

double * qfx1
static
Hosted by OpenAircraft.com, (Michigan UAV, LLC)