FORM  4.1
parallel.h
Go to the documentation of this file.
1 #ifndef __PARALLEL__
2 #define __PARALLEL__
3 
9 /* #[ License : */
10 /*
11  * Copyright (C) 1984-2013 J.A.M. Vermaseren
12  * When using this file you are requested to refer to the publication
13  * J.A.M.Vermaseren "New features of FORM" math-ph/0010025
14  * This is considered a matter of courtesy as the development was paid
15  * for by FOM the Dutch physics granting agency and we would like to
16  * be able to track its scientific use to convince FOM of its value
17  * for the community.
18  *
19  * This file is part of FORM.
20  *
21  * FORM is free software: you can redistribute it and/or modify it under the
22  * terms of the GNU General Public License as published by the Free Software
23  * Foundation, either version 3 of the License, or (at your option) any later
24  * version.
25  *
26  * FORM is distributed in the hope that it will be useful, but WITHOUT ANY
27  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
28  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
29  * details.
30  *
31  * You should have received a copy of the GNU General Public License along
32  * with FORM. If not, see <http://www.gnu.org/licenses/>.
33  */
34 /* #] License : */
35 
36 /*
37  #[ macros & definitions :
38 */
39 #define MASTER 0
40 
41 #define PF_RESET 0
42 #define PF_TIME 1
43 
44 #define PF_TERM_MSGTAG 10 /* master -> slave: sending terms */
45 #define PF_ENDSORT_MSGTAG 11 /* master -> slave: no more terms to be distributed, slave -> master: after EndSort() */
46 #define PF_DOLLAR_MSGTAG 12 /* slave -> master: sending $-variables */
47 #define PF_BUFFER_MSGTAG 20 /* slave -> master: sending sorted terms, or in PF_SendFile()/PF_RecvFile() */
48 #define PF_ENDBUFFER_MSGTAG 21 /* same as PF_BUFFER_MSGTAG, but indicates the end of operation */
49 #define PF_READY_MSGTAG 30 /* slave -> master: slave is idle and can accept terms */
50 #define PF_DATA_MSGTAG 50 /* InParallel, DoCheckpoint() */
51 #define PF_EMPTY_MSGTAG 52 /* InParallel, DoCheckpoint(), PF_SendFile(), PF_RecvFile() */
52 #define PF_STDOUT_MSGTAG 60 /* slave -> master: sending text to the stdout */
53 #define PF_LOG_MSGTAG 61 /* slave -> master: sending text to the log file */
54 #define PF_OPT_MCTS_MSGTAG 70 /* master <-> slave: optimization */
55 #define PF_OPT_HORNER_MSGTAG 71 /* master <-> slave: optimization */
56 #define PF_OPT_COLLECT_MSGTAG 72 /* slave -> master: optimization */
57 #define PF_MISC_MSGTAG 100
58 
59 /*
60  * A macro for checking the version of gcc.
61  */
62 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
63 # define GNUC_PREREQ(major, minor, patchlevel) \
64  ((__GNUC__ << 16) + (__GNUC_MINOR__ << 8) + __GNUC_PATCHLEVEL__ >= \
65  ((major) << 16) + ((minor) << 8) + (patchlevel))
66 #else
67 # define GNUC_PREREQ(major, minor, patchlevel) 0
68 #endif
69 
70 /*
71  * The macro "indices" defined in variable.h collides with some function
72  * argument names in the MPI-3.0 standard.
73  */
74 #undef indices
75 
76 /* Avoid messy padding warnings which may appear in mpi.h. */
77 #if GNUC_PREREQ(4, 6, 0)
78 # pragma GCC diagnostic push
79 # pragma GCC diagnostic ignored "-Wpadded"
80 #endif
81 
82 # ifdef __cplusplus
83  /*
84  * form3.h (which includes parallel.h) is included from newpoly.h as
85  * extern "C" {
86  * #include "form3.h"
87  * }
88  * On the other hand, C++ interfaces to MPI are defined in mpi.h if it is
89  * included from C++ sources. We first leave from the C-linkage, include
90  * mpi.h, and then go back to the C-linkage.
91  * (TU 7 Jun 2011)
92  */
93 }
94 # include <mpi.h>
95 extern "C" {
96 # else
97 # include <mpi.h>
98 # endif
99 
100 /* Now redefine "indices" in the same way as in variable.h. */
101 #define indices ((INDICES)(AC.IndexList.lijst))
102 
103 /* Restore the warning settings. */
104 #if GNUC_PREREQ(4, 6, 0)
105 # pragma GCC diagnostic pop
106 #endif
107 
108 # define PF_ANY_SOURCE MPI_ANY_SOURCE
109 # define PF_ANY_MSGTAG MPI_ANY_TAG
110 # define PF_COMM MPI_COMM_WORLD
111 # define PF_BYTE MPI_BYTE
112 # define PF_INT MPI_INT
113 # if defined(ILP32)
114 # define PF_WORD MPI_SHORT
115 # define PF_LONG MPI_LONG
116 # elif defined(LLP64)
117 # define PF_WORD MPI_INT
118 # define PF_LONG MPI_LONG_LONG_INT
119 # elif defined(LP64)
120 # define PF_WORD MPI_INT
121 # define PF_LONG MPI_LONG
122 # endif
123 
124 /*
125  #] macros & definitions :
126  #[ s/r-bufs :
127 */
128 
133 typedef struct {
134  WORD **buff;
135  WORD **fill;
136  WORD **full;
137  WORD **stop;
138  MPI_Status *status;
139  MPI_Status *retstat;
140  MPI_Request *request;
141  MPI_Datatype *type; /* this is needed in PF_Wait for Get_count */
142  int *index; /* dummies for returnvalues */
143  int *tag; /* for the version with blocking send/receives */
144  int *from;
145  int numbufs; /* number of cyclic buffers */
146  int active; /* flag telling which buffer is active */
147  PADPOINTER(0,2,0,0);
148 } PF_BUFFER;
149 
150 /*
151  #] s/r-bufs :
152  #[ global variables used by the PF_functions : need to be known everywhere
153 */
154 
155 typedef struct ParallelVars {
156  FILEHANDLE slavebuf; /* (slave) allocated if there are RHS expressions */
157  /* special buffers for nonblocking, unbuffered send/receives */
158  PF_BUFFER *sbuf; /* set of cyclic send buffers for master _and_ slave */
159  PF_BUFFER **rbufs; /* array of sets of cyclic receive buffers for master */
160  int me; /* Internal number of task: master is 0 */
161  int numtasks; /* total number of tasks */
162  int parallel; /* flags telling the master and slaves to do the sorting parallel */
163  /* [05nov2003 mt] This flag must be set to 0 in iniModule! */
164  int rhsInParallel; /* flag for parallel executing even if there are RHS expressions */
165  int mkSlaveInfile; /* flag tells that slavebuf is used on the slaves */
166  int exprbufsize; /* buffer size in WORDs to be used for transferring expressions */
167  int exprtodo; /* >= 0: the expression to do in InParallel, -1: otherwise */
168  int log; /* flag for logging mode */
169  WORD numsbufs; /* number of cyclic send buffers (PF.sbuf->numbufs) */
170  WORD numrbufs; /* number of cyclic receive buffers (PF.rbufs[i]->numbufs, i=1,...numtasks-1) */
171  PADPOSITION(2,0,8,2,0);
172 } PARALLELVARS;
173 
174 extern PARALLELVARS PF;
175 /*[04oct2005 mt]:*/
176 /*for broadcasting dollarvars, see parallel.c:PF_BroadcastPreDollar():*/
177 extern LONG PF_maxDollarChunkSize;
178 /*:[04oct2005 mt]*/
179 
180 /*
181  #] global variables used by the PF_functions :
182  #[ Function prototypes :
183 */
184 
185 /* mpi.c */
186 extern int PF_ISendSbuf(int,int);
187 extern int PF_Bcast(void *buffer, int count);
188 extern int PF_RawSend(int,void *,LONG,int);
189 extern LONG PF_RawRecv(int *,void *,LONG,int *);
190 
191 extern int PF_PreparePack(void);
192 extern int PF_Pack(const void *buffer, size_t count, MPI_Datatype type);
193 extern int PF_Unpack(void *buffer, size_t count, MPI_Datatype type);
194 extern int PF_PackString(const UBYTE *str);
195 extern int PF_UnpackString(UBYTE *str);
196 extern int PF_Send(int to, int tag);
197 extern int PF_Receive(int src, int tag, int *psrc, int *ptag);
198 extern int PF_Broadcast(void);
199 
200 extern int PF_PrepareLongSinglePack(void);
201 extern int PF_LongSinglePack(const void *buffer, size_t count, MPI_Datatype type);
202 extern int PF_LongSingleUnpack(void *buffer, size_t count, MPI_Datatype type);
203 extern int PF_LongSingleSend(int to, int tag);
204 extern int PF_LongSingleReceive(int src, int tag, int *psrc, int *ptag);
205 
206 extern int PF_PrepareLongMultiPack(void);
207 extern int PF_LongMultiPackImpl(const void *buffer, size_t count, size_t eSize, MPI_Datatype type);
208 extern int PF_LongMultiUnpackImpl(void *buffer, size_t count, size_t eSize, MPI_Datatype type);
209 extern int PF_LongMultiBroadcast(void);
210 
211 static inline size_t sizeof_datatype(MPI_Datatype type)
212 {
213  if ( type == PF_BYTE ) return sizeof(char);
214  if ( type == PF_INT ) return sizeof(int);
215  if ( type == PF_WORD ) return sizeof(WORD);
216  if ( type == PF_LONG ) return sizeof(LONG);
217  return(0);
218 }
219 
220 #define PF_LongMultiPack(buffer, count, type) PF_LongMultiPackImpl(buffer, count, sizeof_datatype(type), type)
221 #define PF_LongMultiUnpack(buffer, count, type) PF_LongMultiUnpackImpl(buffer, count, sizeof_datatype(type), type)
222 
223 /* parallel.c */
224 extern int PF_EndSort(void);
225 extern WORD PF_Deferred(WORD *,WORD);
226 extern int PF_Processor(EXPRESSIONS,WORD,WORD);
227 extern int PF_Init(int*,char ***);
228 extern int PF_Terminate(int);
229 extern LONG PF_GetSlaveTimes(void);
230 extern LONG PF_BroadcastNumber(LONG);
231 extern void PF_BroadcastBuffer(WORD **buffer, LONG *length);
232 extern int PF_BroadcastString(UBYTE *);
233 extern int PF_BroadcastPreDollar(WORD **, LONG *,int *);
234 extern int PF_CollectModifiedDollars(void);
235 extern int PF_BroadcastModifiedDollars(void);
236 extern int PF_BroadcastRedefinedPreVars(void);
237 extern int PF_BroadcastCBuf(int bufnum);
238 extern int PF_BroadcastExpFlags(void);
239 extern int PF_StoreInsideInfo(void);
240 extern int PF_RestoreInsideInfo(void);
241 extern int PF_BroadcastExpr(EXPRESSIONS e, FILEHANDLE *file);
242 extern int PF_BroadcastRHS(void);
243 extern int PF_InParallelProcessor(void);
244 extern int PF_SendFile(int to, FILE *fd);
245 extern int PF_RecvFile(int from, FILE *fd);
246 extern void PF_MLock(void);
247 extern void PF_MUnlock(void);
248 extern LONG PF_WriteFileToFile(int,UBYTE *,LONG);
249 extern void PF_FlushStdOutBuffer(void);
250 
251 /*
252  #] Function prototypes :
253 */
254 
255 #endif
int PF_LongMultiUnpackImpl(void *buffer, size_t count, size_t eSize, MPI_Datatype type)
Definition: mpi.c:1721
int PF_BroadcastExpFlags(void)
Definition: parallel.c:3257
LONG PF_BroadcastNumber(LONG)
Definition: parallel.c:2096
LONG PF_GetSlaveTimes(void)
Definition: parallel.c:2076
int PF_BroadcastExpr(EXPRESSIONS e, FILEHANDLE *file)
Definition: parallel.c:3549
int PF_CollectModifiedDollars(void)
Definition: parallel.c:2508
int PF_PreparePack(void)
Definition: mpi.c:624
int PF_PrepareLongSinglePack(void)
Definition: mpi.c:1451
int PF_Init(int *, char ***)
Definition: parallel.c:1945
Definition: structs.h:618
void PF_MUnlock(void)
Definition: parallel.c:4346
int PF_Bcast(void *buffer, int count)
Definition: mpi.c:440
LONG PF_RawRecv(int *, void *, LONG, int *)
Definition: mpi.c:484
int PF_BroadcastRHS(void)
Definition: parallel.c:3577
int PF_SendFile(int to, FILE *fd)
Definition: parallel.c:4211
int PF_BroadcastPreDollar(WORD **, LONG *, int *)
Definition: parallel.c:2220
int PF_LongSingleReceive(int src, int tag, int *psrc, int *ptag)
Definition: mpi.c:1583
int PF_Processor(EXPRESSIONS, WORD, WORD)
Definition: parallel.c:1534
int PF_UnpackString(UBYTE *str)
Definition: mpi.c:774
int PF_Receive(int src, int tag, int *psrc, int *ptag)
Definition: mpi.c:848
int PF_PrepareLongMultiPack(void)
Definition: mpi.c:1643
void PF_MLock(void)
Definition: parallel.c:4330
void PF_FlushStdOutBuffer(void)
Definition: parallel.c:4469
int PF_Send(int to, int tag)
Definition: mpi.c:822
int PF_LongSingleSend(int to, int tag)
Definition: mpi.c:1540
int PF_RecvFile(int from, FILE *fd)
Definition: parallel.c:4249
int PF_InParallelProcessor(void)
Definition: parallel.c:3624
WORD PF_Deferred(WORD *, WORD)
Definition: parallel.c:1202
void PF_BroadcastBuffer(WORD **buffer, LONG *length)
Definition: parallel.c:2123
LONG PF_WriteFileToFile(int, UBYTE *, LONG)
Definition: parallel.c:4375
int PF_LongSinglePack(const void *buffer, size_t count, MPI_Datatype type)
Definition: mpi.c:1469
int PF_RawSend(int, void *, LONG, int)
Definition: mpi.c:463
int PF_Pack(const void *buffer, size_t count, MPI_Datatype type)
Definition: mpi.c:642
int PF_PackString(const UBYTE *str)
Definition: mpi.c:706
int PF_Unpack(void *buffer, size_t count, MPI_Datatype type)
Definition: mpi.c:671
int PF_BroadcastCBuf(int bufnum)
Definition: parallel.c:3146
int PF_EndSort(void)
Definition: parallel.c:864
int PF_BroadcastModifiedDollars(void)
Definition: parallel.c:2787
int PF_LongMultiPackImpl(const void *buffer, size_t count, size_t eSize, MPI_Datatype type)
Definition: mpi.c:1662
int PF_Broadcast(void)
Definition: mpi.c:883
int PF_LongMultiBroadcast(void)
Definition: mpi.c:1807
int PF_BroadcastRedefinedPreVars(void)
Definition: parallel.c:3004
int PF_LongSingleUnpack(void *buffer, size_t count, MPI_Datatype type)
Definition: mpi.c:1503
int PF_ISendSbuf(int, int)
Definition: mpi.c:261
int PF_Terminate(int)
Definition: parallel.c:2060
int PF_BroadcastString(UBYTE *)
Definition: parallel.c:2165