CalculiX  2.8
A Free Software Three-Dimensional Structural Finite Element Program
 All Classes Files Functions Variables Macros
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

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

Definition at line 31 of file biosav.c.

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  j=0;
120  nkphi=-1;
121 
122  do{
123  if(j==num_cpus) break;
124  do{
125  if(nkapar[j]==nkphi){
126  nkapar[j]=i;
127  break;
128  }else{
129  do{
130  i++;
131  if(inomat[i]==1){
132  nkphi++;
133  break;
134  }
135  }while(1);
136  }
137  }while(1);
138 
139  do{
140  if(nkepar[j]==nkphi){
141  nkepar[j]=i;
142  j++;
143  break;
144  }else{
145  do{
146  i++;
147  if(inomat[i]==1){
148  nkphi++;
149  break;
150  }
151  }while(1);
152  }
153  }while(1);
154  }while(1);
155 
156  ipkon1=ipkon;kon1=kon;lakon1=lakon;ne1=ne;co1=co;qfx1=qfx;
157  h01=h0;mi1=mi;
158 
159  printf(" Using up to %" ITGFORMAT " cpu(s) for the Biot-Savart calculation.\n\n", num_cpus);
160 
161  /* create threads and wait */
162 
163  pthread_t tid[num_cpus];
164 
165  NNEW(ithread,ITG,num_cpus);
166  for(i=0;i<num_cpus;i++){
167  ithread[i]=i;
168  pthread_create(&tid[i],NULL,(void *)biotsavartmt,(void *)&ithread[i]);
169  }
170  for(i=0;i<num_cpus;i++)pthread_join(tid[i], NULL);
171 
172  SFREE(ithread);SFREE(nkapar);SFREE(nkepar);
173 
174  return;
175 
176 }
#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:180
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
void* biotsavartmt ( ITG i)

Definition at line 180 of file biosav.c.

180  {
181 
182  ITG nka,nkb;
183 
184  nka=nkapar[*i]+1;
185  nkb=nkepar[*i]+1;
186 
188  &nkb));
189 
190  return NULL;
191 }
subroutine biotsavart(ipkon, kon, lakon, ne, co, qfx, h0, mi, nka, nkb)
Definition: biotsavart.f:19
static ITG * ne1
Definition: biosav.c:27
static char * lakon1
Definition: biosav.c:25
void FORTRAN(addimdnodecload,(ITG *nodeforc, ITG *i, ITG *imdnode, ITG *nmdnode, double *xforc, ITG *ikmpc, ITG *ilmpc, ITG *ipompc, ITG *nodempc, ITG *nmpc, ITG *imddof, ITG *nmddof, ITG *nactdof, ITG *mi, ITG *imdmpc, ITG *nmdmpc, ITG *imdboun, ITG *nmdboun, ITG *ikboun, ITG *nboun, ITG *ilboun, ITG *ithermal))
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

double* co1
static

Definition at line 29 of file biosav.c.

double * h01
static

Definition at line 29 of file biosav.c.

ITG * ipkon1
static

Definition at line 27 of file biosav.c.

ITG* kon1
static

Definition at line 27 of file biosav.c.

char* lakon1
static

Definition at line 25 of file biosav.c.

ITG * mi1
static

Definition at line 27 of file biosav.c.

ITG * ne1
static

Definition at line 27 of file biosav.c.

ITG * nkapar =NULL
static

Definition at line 27 of file biosav.c.

ITG * nkepar =NULL
static

Definition at line 27 of file biosav.c.

ITG num_cpus
static

Definition at line 27 of file biosav.c.

double * qfx1
static

Definition at line 29 of file biosav.c.

Hosted by OpenAircraft.com, (Michigan UAV, LLC)