FORM  4.3
parallel.h
Go to the documentation of this file.
1 #ifndef __PARALLEL__
2 #define __PARALLEL__
3 
9 /* #[ License : */
10 /*
11  * Copyright (C) 1984-2022 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 # pragma GCC diagnostic ignored "-Wunused-parameter"
81 #endif
82 #if defined(__clang__) && defined(__has_warning)
83 # pragma clang diagnostic push
84 # if __has_warning("-Wpadded")
85 # pragma clang diagnostic ignored "-Wpadded"
86 # endif
87 # if __has_warning("-Wunused-parameter")
88 # pragma clang diagnostic ignored "-Wunused-parameter"
89 # endif
90 #endif
91 
92 # ifdef __cplusplus
93  /*
94  * form3.h (which includes parallel.h) is included from newpoly.h as
95  * extern "C" {
96  * #include "form3.h"
97  * }
98  * On the other hand, C++ interfaces to MPI are defined in mpi.h if it is
99  * included from C++ sources. We first leave from the C-linkage, include
100  * mpi.h, and then go back to the C-linkage.
101  * (TU 7 Jun 2011)
102  */
103 }
104 # include <mpi.h>
105 extern "C" {
106 # else
107 # include <mpi.h>
108 # endif
109 
110 /* Now redefine "indices" in the same way as in variable.h. */
111 #define indices ((INDICES)(AC.IndexList.lijst))
112 
113 /* Restore the warning settings. */
114 #if GNUC_PREREQ(4, 6, 0)
115 # pragma GCC diagnostic pop
116 #endif
117 #if defined(__clang__) && defined(__has_warning)
118 # pragma clang diagnostic pop
119 #endif
120 
121 # define PF_ANY_SOURCE MPI_ANY_SOURCE
122 # define PF_ANY_MSGTAG MPI_ANY_TAG
123 # define PF_COMM MPI_COMM_WORLD
124 # define PF_BYTE MPI_BYTE
125 # define PF_INT MPI_INT
126 # if defined(ILP32)
127 # define PF_WORD MPI_SHORT
128 # define PF_LONG MPI_LONG
129 # elif defined(LLP64)
130 # define PF_WORD MPI_INT
131 # define PF_LONG MPI_LONG_LONG_INT
132 # elif defined(LP64)
133 # define PF_WORD MPI_INT
134 # define PF_LONG MPI_LONG
135 # endif
136 
137 /*
138  #] macros & definitions :
139  #[ s/r-bufs :
140 */
141 
146 typedef struct {
147  WORD **buff;
148  WORD **fill;
149  WORD **full;
150  WORD **stop;
151  MPI_Status *status;
152  MPI_Status *retstat;
153  MPI_Request *request;
154  MPI_Datatype *type; /* this is needed in PF_Wait for Get_count */
155  int *index; /* dummies for returnvalues */
156  int *tag; /* for the version with blocking send/receives */
157  int *from;
158  int numbufs; /* number of cyclic buffers */
159  int active; /* flag telling which buffer is active */
160  PADPOINTER(0,2,0,0);
161 } PF_BUFFER;
162 
163 /*
164  #] s/r-bufs :
165  #[ global variables used by the PF_functions : need to be known everywhere
166 */
167 
168 typedef struct ParallelVars {
169  FILEHANDLE slavebuf; /* (slave) allocated if there are RHS expressions */
170  /* special buffers for nonblocking, unbuffered send/receives */
171  PF_BUFFER *sbuf; /* set of cyclic send buffers for master _and_ slave */
172  PF_BUFFER **rbufs; /* array of sets of cyclic receive buffers for master */
173  int me; /* Internal number of task: master is 0 */
174  int numtasks; /* total number of tasks */
175  int parallel; /* flags telling the master and slaves to do the sorting parallel */
176  /* [05nov2003 mt] This flag must be set to 0 in iniModule! */
177  int rhsInParallel; /* flag for parallel executing even if there are RHS expressions */
178  int mkSlaveInfile; /* flag tells that slavebuf is used on the slaves */
179  int exprbufsize; /* buffer size in WORDs to be used for transferring expressions */
180  int exprtodo; /* >= 0: the expression to do in InParallel, -1: otherwise */
181  int log; /* flag for logging mode */
182  WORD numsbufs; /* number of cyclic send buffers (PF.sbuf->numbufs) */
183  WORD numrbufs; /* number of cyclic receive buffers (PF.rbufs[i]->numbufs, i=1,...numtasks-1) */
184  PADPOSITION(2,0,8,2,0);
185 } PARALLELVARS;
186 
187 extern PARALLELVARS PF;
188 /*[04oct2005 mt]:*/
189 /*for broadcasting dollarvars, see parallel.c:PF_BroadcastPreDollar():*/
190 extern LONG PF_maxDollarChunkSize;
191 /*:[04oct2005 mt]*/
192 
193 /*
194  #] global variables used by the PF_functions :
195  #[ Function prototypes :
196 */
197 
198 /* mpi.c */
199 extern int PF_ISendSbuf(int,int);
200 extern int PF_Bcast(void *buffer, int count);
201 extern int PF_RawSend(int,void *,LONG,int);
202 extern LONG PF_RawRecv(int *,void *,LONG,int *);
203 
204 extern int PF_PreparePack(void);
205 extern int PF_Pack(const void *buffer, size_t count, MPI_Datatype type);
206 extern int PF_Unpack(void *buffer, size_t count, MPI_Datatype type);
207 extern int PF_PackString(const UBYTE *str);
208 extern int PF_UnpackString(UBYTE *str);
209 extern int PF_Send(int to, int tag);
210 extern int PF_Receive(int src, int tag, int *psrc, int *ptag);
211 extern int PF_Broadcast(void);
212 
213 extern int PF_PrepareLongSinglePack(void);
214 extern int PF_LongSinglePack(const void *buffer, size_t count, MPI_Datatype type);
215 extern int PF_LongSingleUnpack(void *buffer, size_t count, MPI_Datatype type);
216 extern int PF_LongSingleSend(int to, int tag);
217 extern int PF_LongSingleReceive(int src, int tag, int *psrc, int *ptag);
218 
219 extern int PF_PrepareLongMultiPack(void);
220 extern int PF_LongMultiPackImpl(const void *buffer, size_t count, size_t eSize, MPI_Datatype type);
221 extern int PF_LongMultiUnpackImpl(void *buffer, size_t count, size_t eSize, MPI_Datatype type);
222 extern int PF_LongMultiBroadcast(void);
223 
224 static inline size_t sizeof_datatype(MPI_Datatype type)
225 {
226  if ( type == PF_BYTE ) return sizeof(char);
227  if ( type == PF_INT ) return sizeof(int);
228  if ( type == PF_WORD ) return sizeof(WORD);
229  if ( type == PF_LONG ) return sizeof(LONG);
230  return(0);
231 }
232 
233 #define PF_LongMultiPack(buffer, count, type) PF_LongMultiPackImpl(buffer, count, sizeof_datatype(type), type)
234 #define PF_LongMultiUnpack(buffer, count, type) PF_LongMultiUnpackImpl(buffer, count, sizeof_datatype(type), type)
235 
236 /* parallel.c */
237 extern int PF_EndSort(void);
238 extern WORD PF_Deferred(WORD *,WORD);
239 extern int PF_Processor(EXPRESSIONS,WORD,WORD);
240 extern int PF_Init(int*,char ***);
241 extern int PF_Terminate(int);
242 extern LONG PF_GetSlaveTimes(void);
243 extern LONG PF_BroadcastNumber(LONG);
244 extern void PF_BroadcastBuffer(WORD **buffer, LONG *length);
245 extern int PF_BroadcastString(UBYTE *);
246 extern int PF_BroadcastPreDollar(WORD **, LONG *,int *);
247 extern int PF_CollectModifiedDollars(void);
248 extern int PF_BroadcastModifiedDollars(void);
249 extern int PF_BroadcastRedefinedPreVars(void);
250 extern int PF_BroadcastCBuf(int bufnum);
251 extern int PF_BroadcastExpFlags(void);
252 extern int PF_StoreInsideInfo(void);
253 extern int PF_RestoreInsideInfo(void);
254 extern int PF_BroadcastExpr(EXPRESSIONS e, FILEHANDLE *file);
255 extern int PF_BroadcastRHS(void);
256 extern int PF_InParallelProcessor(void);
257 extern int PF_SendFile(int to, FILE *fd);
258 extern int PF_RecvFile(int from, FILE *fd);
259 extern void PF_MLock(void);
260 extern void PF_MUnlock(void);
261 extern LONG PF_WriteFileToFile(int,UBYTE *,LONG);
262 extern void PF_FlushStdOutBuffer(void);
263 
264 /*
265  #] Function prototypes :
266 */
267 
268 #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:3244
LONG PF_BroadcastNumber(LONG)
Definition: parallel.c:2083
LONG PF_GetSlaveTimes(void)
Definition: parallel.c:2063
int PF_BroadcastExpr(EXPRESSIONS e, FILEHANDLE *file)
Definition: parallel.c:3536
int PF_CollectModifiedDollars(void)
Definition: parallel.c:2495
int PF_PreparePack(void)
Definition: mpi.c:624
int PF_PrepareLongSinglePack(void)
Definition: mpi.c:1451
int PF_Init(int *, char ***)
Definition: parallel.c:1953
Definition: structs.h:633
void PF_MUnlock(void)
Definition: parallel.c:4342
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:3564
int PF_SendFile(int to, FILE *fd)
Definition: parallel.c:4207
int PF_BroadcastPreDollar(WORD **, LONG *, int *)
Definition: parallel.c:2207
int PF_LongSingleReceive(int src, int tag, int *psrc, int *ptag)
Definition: mpi.c:1583
int PF_Processor(EXPRESSIONS, WORD, WORD)
Definition: parallel.c:1540
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:4326
void PF_FlushStdOutBuffer(void)
Definition: parallel.c:4465
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:4245
int PF_InParallelProcessor(void)
Definition: parallel.c:3611
WORD PF_Deferred(WORD *, WORD)
Definition: parallel.c:1208
void PF_BroadcastBuffer(WORD **buffer, LONG *length)
Definition: parallel.c:2110
LONG PF_WriteFileToFile(int, UBYTE *, LONG)
Definition: parallel.c:4371
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:3133
int PF_EndSort(void)
Definition: parallel.c:864
int PF_BroadcastModifiedDollars(void)
Definition: parallel.c:2774
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:2991
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:2047
int PF_BroadcastString(UBYTE *)
Definition: parallel.c:2152