genericParallelization.h
1 #ifndef _GENERIC_PARALL_H
2 #define _GENERIC_PARALL_H
3 
4 
5 extern double *globalResult;
6 
7 
8 /**********/
9 /* CONFIG */
10 /**********/
11 
12 /* #define MEASURE_TIME_PARALLEL */
13 #define _PORTABLE_PTHREADS
14 /* #define DEBUG_PARALLEL */
15 /* #define DEBUG_MPI_EACH_SEND */
16 /* #define _REPRODUCIBLE_MPI_OR_PTHREADS */
17 #ifdef _USE_PTHREADS
18 #ifndef _PORTABLE_PTHREADS
19 void pinToCore(int tid);
20 #endif
21 #endif
22 
23 
24 #define NOT !
25 #define IS_PARALLEL (defined(_USE_PTHREADS) || defined(_FINE_GRAIN_MPI))
26 
27 
28 
29 #ifdef MEASURE_TIME_PARALLEL
30 #define NUM_PAR_JOBS 16
31 extern double masterTimePerPhase;
32 #endif
33 
34 
35 /******************/
36 /* MPI SPECIFIC */
37 /******************/
38 #ifdef _FINE_GRAIN_MPI
39 #include <mpi.h>
40 #ifdef DEBUG_MPI_EACH_SEND
41 #define DEBUG_PRINT(text, elem) printf(text, elem)
42 #else
43 #define DEBUG_PRINT(text, elem) NULL
44 #endif
45 
46 /* for the broadcast of traversal descriptor */
47 #define TRAVERSAL_LENGTH 5
48 #define traversalSize sizeof(traversalInfo)
49 #define messageSize(x) (3 * sizeof(int) + x * (sizeof(int)+ sizeof(double)) + TRAVERSAL_LENGTH * traversalSize)
50 
51 #define VOLATILE_PAR
52 #define MASTER_P (processID == 0)
53 #define POP_OR_PUT_BYTES(bufPtr, elem, type) (MASTER_P ? (bufPtr = addBytes((bufPtr), &(elem), sizeof(type))) : (bufPtr = popBytes((bufPtr), &(elem), sizeof(type))))
54 
55 #define ASSIGN_INT(x,y) (MPI_Bcast(&y,1,MPI_INT,0,MPI_COMM_WORLD),DEBUG_PRINT("\tSEND/RECV %d\n", y))
56 #define ASSIGN_BUF(x,y,type) (POP_OR_PUT_BYTES(bufPtr, y,type))
57 #define ASSIGN_BUF_DBL(x,y) (POP_OR_PUT_BYTES(bufPtrDbl,y, double))
58 #define ASSIGN_DBL(x,y) (MPI_Bcast(&y,1,MPI_DOUBLE, 0, MPI_COMM_WORLD), DEBUG_PRINT("\tSEND/RECV %f\n", y))
59 #define ASSIGN_DBLS(tar,src,length) MPI_Bcast(tar, length, MPI_DOUBLE, 0, MPI_COMM_WORLD)
60 #define DOUBLE MPI_DOUBLE
61 #define ASSIGN_GATHER(tar,src,length,type,tid) MPI_Gather(src,length,type,tar,length,type,0, MPI_COMM_WORLD)
62 #define SEND_BUF(buf, bufSize,type) if(MASTER_P) MPI_Bcast(buf, bufSize, type, 0, MPI_COMM_WORLD)
63 #define RECV_BUF(buf, bufSize,type) if(NOT MASTER_P) MPI_Bcast(buf, bufSize, type, 0, MPI_COMM_WORLD)
64 #define BCAST_BUF(buf, bufSize,type,who) MPI_Bcast(buf, bufSize, type, who,MPI_COMM_WORLD )
65 
66 
67 
68 extern int processes;
69 extern int processID;
70 #endif
71 
72 /*********************/
73 /* PTHREAD SPECIFIC */
74 /*********************/
75 #ifdef _USE_PTHREADS
76 #include <pthread.h>
77 #define _REPRODUCIBLE_MPI_OR_PTHREADS
78 #define VOLATILE_PAR volatile
79 #define MASTER_P (tid == 0)
80 #define ASSIGN_INT(x,y) (x = y)
81 #define ASSIGN_BUF(x,y,type) (x = y)
82 #define ASSIGN_BUF_DBL(x,y) (x = y)
83 #define ASSIGN_DBL(x,y) (x = y)
84 #define ASSIGN_DBLS(tar,src,length) memmove(tar, src, length * sizeof(double))
85 #define DOUBLE double /* just rededining that to make the source code less confusing */
86 #define ASSIGN_GATHER(tar,src,length,type,tid) (memmove((tar) + (tid) * (length) ,src, length * sizeof(type)))
87 #define SEND_BUF(buf, bufSize, type)
88 #define RECV_BUF(buf, bufSize, type)
89 #define BCAST_BUF(buf, bufSize,type,who)
90 #define TRAVERSAL_LENGTH 5
91 #define messageSize(x) 0
92 #endif
93 
94 
95 #endif /* end include guard */
void pinToCore(int tid)
Pins a thread to a core (for efficiency).
Definition: genericParallelization.c:292