FORM v5.0.0-35-g6318119
parallel.h
Go to the documentation of this file.
1#ifndef __PARALLEL__
2#define __PARALLEL__
3
9/* #[ License : */
10/*
11 * Copyright (C) 1984-2026 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
40/*
41 * Rank of the master process.
42 */
43#define MASTER 0
44
45/*
46 * Selector constants for PF_RealTime().
47 */
48#define PF_RESET 0 /* reset the timer */
49#define PF_TIME 1 /* get the elapsed time */
50
51/*
52 * Message tags for communication during parallel execution.
53 */
54#define PF_TERM_MSGTAG 10 /* master -> slave: sending terms */
55#define PF_ENDSORT_MSGTAG 11 /* master -> slave: no more terms to be distributed, slave -> master: after EndSort() */
56#define PF_DOLLAR_MSGTAG 12 /* slave -> master: sending $-variables */
57#define PF_BUFFER_MSGTAG 20 /* slave -> master: sending sorted terms, or in PF_SendFile()/PF_RecvFile() */
58#define PF_ENDBUFFER_MSGTAG 21 /* same as PF_BUFFER_MSGTAG, but indicates the end of operation */
59#define PF_READY_MSGTAG 30 /* slave -> master: slave is idle and can accept terms */
60#define PF_DATA_MSGTAG 50 /* InParallel, DoCheckpoint() */
61#define PF_EMPTY_MSGTAG 52 /* InParallel, DoCheckpoint(), PF_SendFile(), PF_RecvFile() */
62#define PF_STDOUT_MSGTAG 60 /* slave -> master: sending text to the stdout */
63#define PF_LOG_MSGTAG 61 /* slave -> master: sending text to the log file */
64#define PF_OPT_MCTS_MSGTAG 70 /* master <-> slave: optimization */
65#define PF_OPT_HORNER_MSGTAG 71 /* master <-> slave: optimization */
66#define PF_OPT_COLLECT_MSGTAG 72 /* slave -> master: optimization */
67#define PF_RUNTIME_ERROR_MSGTAG 80 /* slave <-> master: runtime error */
68#define PF_RUNTIME_SYNC_MSGTAG 81 /* master <-> slave: sync after EndSort() */
69#define PF_MISC_MSGTAG 100
70
71/*
72 * A macro for checking the version of gcc.
73 */
74#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
75# define GNUC_PREREQ(major, minor, patchlevel) \
76 ((__GNUC__ << 16) + (__GNUC_MINOR__ << 8) + __GNUC_PATCHLEVEL__ >= \
77 ((major) << 16) + ((minor) << 8) + (patchlevel))
78#else
79# define GNUC_PREREQ(major, minor, patchlevel) 0
80#endif
81
82/*
83 * The macro "indices" defined in variable.h collides with some function
84 * argument names in the MPI-3.0 standard.
85 */
86#undef indices
87
88/* Avoid messy padding warnings which may appear in mpi.h. */
89#if GNUC_PREREQ(4, 6, 0)
90# pragma GCC diagnostic push
91# pragma GCC diagnostic ignored "-Wpadded"
92# pragma GCC diagnostic ignored "-Wunused-parameter"
93#endif
94#if defined(__clang__) && defined(__has_warning)
95# pragma clang diagnostic push
96# if __has_warning("-Wpadded")
97# pragma clang diagnostic ignored "-Wpadded"
98# endif
99# if __has_warning("-Wunused-parameter")
100# pragma clang diagnostic ignored "-Wunused-parameter"
101# endif
102#endif
103
104# ifdef __cplusplus
105 /*
106 * form3.h (which includes parallel.h) is included from newpoly.h as
107 * extern "C" {
108 * #include "form3.h"
109 * }
110 * On the other hand, C++ interfaces to MPI are defined in mpi.h if it is
111 * included from C++ sources. We first leave from the C-linkage, include
112 * mpi.h, and then go back to the C-linkage.
113 * (TU 7 Jun 2011)
114 */
115}
116# define OMPI_SKIP_MPICXX 1
117# include <mpi.h>
118extern "C" {
119# else
120# define OMPI_SKIP_MPICXX 1
121# include <mpi.h>
122# endif
123
124/* Now redefine "indices" in the same way as in variable.h. */
125#define indices ((INDICES)(AC.IndexList.lijst))
126
127/* Restore the warning settings. */
128#if GNUC_PREREQ(4, 6, 0)
129# pragma GCC diagnostic pop
130#endif
131#if defined(__clang__) && defined(__has_warning)
132# pragma clang diagnostic pop
133#endif
134
135# define PF_ANY_SOURCE MPI_ANY_SOURCE
136# define PF_ANY_MSGTAG MPI_ANY_TAG
137# define PF_COMM MPI_COMM_WORLD
138# define PF_BYTE MPI_BYTE
139# define PF_INT MPI_INT
140#if BITSINWORD == 32
141# define PF_WORD MPI_INT32_T
142# define PF_LONG MPI_INT64_T
143#elif BITSINWORD == 16
144# define PF_WORD MPI_INT16_T
145# define PF_LONG MPI_INT32_T
146#else
147# error Can not detect if this is a 32-bit or 64-bit platform.
148#endif
149
150/*
151 #] macros & definitions :
152 #[ s/r-bufs :
153*/
154
159typedef struct {
160 WORD **buff;
161 WORD **fill;
162 WORD **full;
163 WORD **stop;
164 MPI_Status *status;
165 MPI_Status *retstat;
166 MPI_Request *request;
167 MPI_Datatype *type; /* this is needed in PF_Wait for Get_count */
168 int *index; /* dummies for returnvalues */
169 int *tag; /* for the version with blocking send/receives */
170 int *from;
171 int numbufs; /* number of cyclic buffers */
172 int active; /* flag telling which buffer is active */
173} PF_BUFFER;
174
175/*
176 #] s/r-bufs :
177 #[ global variables used by the PF_functions : need to be known everywhere
178*/
179
180typedef struct ParallelVars {
181 FILEHANDLE slavebuf; /* (slave) allocated if there are RHS expressions */
182 /* special buffers for nonblocking, unbuffered send/receives */
183 PF_BUFFER *sbuf; /* set of cyclic send buffers for master _and_ slave */
184 PF_BUFFER **rbufs; /* array of sets of cyclic receive buffers for master */
185 int me; /* Internal number of task: master is 0 */
186 int numtasks; /* total number of tasks */
187 int parallel; /* flags telling the master and slaves to do the sorting parallel */
188 /* [05nov2003 mt] This flag must be set to 0 in iniModule! */
189 int rhsInParallel; /* flag for parallel executing even if there are RHS expressions */
190 int mkSlaveInfile; /* flag tells that slavebuf is used on the slaves */
191 int exprbufsize; /* buffer size in WORDs to be used for transferring expressions */
192 int exprtodo; /* >= 0: the expression to do in InParallel, -1: otherwise */
193 int log; /* flag for logging mode */
194 int notMyFault; /* flag for termination due to another process's runtime error */
195 WORD numsbufs; /* number of cyclic send buffers (PF.sbuf->numbufs) */
196 WORD numrbufs; /* number of cyclic receive buffers (PF.rbufs[i]->numbufs, i=1,...numtasks-1) */
198
199extern PARALLELVARS PF;
200/*[04oct2005 mt]:*/
201/*for broadcasting dollarvars, see parallel.c:PF_BroadcastPreDollar():*/
202extern LONG PF_maxDollarChunkSize;
203/*:[04oct2005 mt]*/
204
205/*
206 #] global variables used by the PF_functions :
207 #[ Function prototypes :
208*/
209
210/* mpi.c */
211extern int PF_ISendSbuf(int,int);
212extern int PF_Bcast(void *buffer, int count);
213extern int PF_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype type, MPI_Op op, int root);
214extern int PF_RawSend(int,void *,LONG,int);
215extern LONG PF_RawRecv(int *,void *,LONG,int *);
216
217extern int PF_PreparePack(void);
218extern int PF_Pack(const void *buffer, size_t count, MPI_Datatype type);
219extern int PF_Unpack(void *buffer, size_t count, MPI_Datatype type);
220extern int PF_PackString(const UBYTE *str);
221extern int PF_UnpackString(UBYTE *str);
222extern int PF_Send(int to, int tag);
223extern int PF_Receive(int src, int tag, int *psrc, int *ptag);
224extern int PF_Broadcast(void);
225
226extern int PF_PrepareLongSinglePack(void);
227extern int PF_LongSinglePack(const void *buffer, size_t count, MPI_Datatype type);
228extern int PF_LongSingleUnpack(void *buffer, size_t count, MPI_Datatype type);
229extern int PF_LongSingleSend(int to, int tag);
230extern int PF_LongSingleReceive(int src, int tag, int *psrc, int *ptag);
231
232extern int PF_PrepareLongMultiPack(void);
233extern int PF_LongMultiPackImpl(const void *buffer, size_t count, size_t eSize, MPI_Datatype type);
234extern int PF_LongMultiUnpackImpl(void *buffer, size_t count, size_t eSize, MPI_Datatype type);
235extern int PF_LongMultiBroadcast(void);
236
237static inline size_t sizeof_datatype(MPI_Datatype type)
238{
239 if ( type == PF_BYTE ) return sizeof(char);
240 if ( type == PF_INT ) return sizeof(int);
241 if ( type == PF_WORD ) return sizeof(WORD);
242 if ( type == PF_LONG ) return sizeof(LONG);
243 return(0);
244}
245
246#define PF_LongMultiPack(buffer, count, type) PF_LongMultiPackImpl(buffer, count, sizeof_datatype(type), type)
247#define PF_LongMultiUnpack(buffer, count, type) PF_LongMultiUnpackImpl(buffer, count, sizeof_datatype(type), type)
248
249/* parallel.c */
250extern int PF_EndSort(void);
251extern WORD PF_Deferred(WORD *,WORD);
252extern int PF_Processor(EXPRESSIONS,WORD,WORD);
253extern int PF_Init(int*,char ***);
254extern void PF_PreTerminate(int errorcode);
255extern int PF_Terminate(int);
256extern LONG PF_GetSlaveTimes(void);
257extern LONG PF_BroadcastNumber(LONG);
258extern void PF_BroadcastBuffer(WORD **buffer, LONG *length);
259extern int PF_BroadcastString(UBYTE *);
260extern int PF_BroadcastPreDollar(WORD **, LONG *,int *);
261extern int PF_CollectModifiedDollars(void);
262extern int PF_BroadcastModifiedDollars(void);
263extern int PF_BroadcastRedefinedPreVars(void);
264extern int PF_BroadcastCBuf(int bufnum);
265extern int PF_BroadcastExpFlags(void);
266extern int PF_StoreInsideInfo(void);
267extern int PF_RestoreInsideInfo(void);
268extern int PF_BroadcastExpr(EXPRESSIONS e, FILEHANDLE *file);
269extern int PF_BroadcastRHS(void);
270extern int PF_InParallelProcessor(void);
271extern int PF_SendFile(int to, FILE *fd);
272extern int PF_RecvFile(int from, FILE *fd);
273extern void PF_MLock(void);
274extern void PF_MUnlock(void);
275extern LONG PF_WriteFileToFile(int,UBYTE *,LONG);
276extern void PF_FlushStdOutBuffer(void);
277extern void PF_ReceiveRuntimeError(void) NORETURN;
278
279/*
280 #] Function prototypes :
281*/
282
283#endif
int PF_LongSingleReceive(int src, int tag, int *psrc, int *ptag)
Definition mpi.c:1693
int PF_PackString(const UBYTE *str)
Definition mpi.c:818
int PF_BroadcastPreDollar(WORD **, LONG *, int *)
Definition parallel.c:2222
void PF_MUnlock(void)
Definition parallel.c:4369
int PF_RawSend(int, void *, LONG, int)
Definition mpi.c:497
int PF_LongSingleSend(int to, int tag)
Definition mpi.c:1650
WORD PF_Deferred(WORD *, WORD)
Definition parallel.c:1201
int PF_Processor(EXPRESSIONS, WORD, WORD)
Definition parallel.c:1533
int PF_BroadcastRedefinedPreVars(void)
Definition parallel.c:3005
int PF_PrepareLongSinglePack(void)
Definition mpi.c:1561
int PF_BroadcastRHS(void)
Definition parallel.c:3580
int PF_Unpack(void *buffer, size_t count, MPI_Datatype type)
Definition mpi.c:783
int PF_BroadcastString(UBYTE *)
Definition parallel.c:2167
int PF_Receive(int src, int tag, int *psrc, int *ptag)
Definition mpi.c:959
LONG PF_GetSlaveTimes(void)
Definition parallel.c:2077
int PF_BroadcastExpFlags(void)
Definition parallel.c:3258
int PF_Send(int to, int tag)
Definition mpi.c:933
int PF_BroadcastModifiedDollars(void)
Definition parallel.c:2788
int PF_Reduce(const void *sendbuf, void *recvbuf, int count, MPI_Datatype type, MPI_Op op, int root)
Definition mpi.c:475
int PF_Init(int *, char ***)
Definition parallel.c:1947
int PF_PreparePack(void)
Definition mpi.c:736
int PF_ISendSbuf(int, int)
Definition mpi.c:266
void PF_PreTerminate(int errorcode)
Definition parallel.c:2041
int PF_BroadcastCBuf(int bufnum)
Definition parallel.c:3147
void PF_BroadcastBuffer(WORD **buffer, LONG *length)
Definition parallel.c:2125
int PF_LongSingleUnpack(void *buffer, size_t count, MPI_Datatype type)
Definition mpi.c:1613
int PF_Pack(const void *buffer, size_t count, MPI_Datatype type)
Definition mpi.c:754
int PF_PrepareLongMultiPack(void)
Definition mpi.c:1752
int PF_CollectModifiedDollars(void)
Definition parallel.c:2509
int PF_LongMultiPackImpl(const void *buffer, size_t count, size_t eSize, MPI_Datatype type)
Definition mpi.c:1771
int PF_Broadcast(void)
Definition mpi.c:994
int PF_RecvFile(int from, FILE *fd)
Definition parallel.c:4272
int PF_LongMultiBroadcast(void)
Definition mpi.c:1916
int PF_UnpackString(UBYTE *str)
Definition mpi.c:886
void PF_FlushStdOutBuffer(void)
Definition parallel.c:4492
LONG PF_WriteFileToFile(int, UBYTE *, LONG)
Definition parallel.c:4398
LONG PF_BroadcastNumber(LONG)
Definition parallel.c:2098
LONG PF_RawRecv(int *, void *, LONG, int *)
Definition mpi.c:518
int PF_LongMultiUnpackImpl(void *buffer, size_t count, size_t eSize, MPI_Datatype type)
Definition mpi.c:1830
int PF_EndSort(void)
Definition parallel.c:874
int PF_LongSinglePack(const void *buffer, size_t count, MPI_Datatype type)
Definition mpi.c:1579
int PF_Bcast(void *buffer, int count)
Definition mpi.c:452
void PF_MLock(void)
Definition parallel.c:4353
int PF_SendFile(int to, FILE *fd)
Definition parallel.c:4234
int PF_Terminate(int)
Definition parallel.c:2061
int PF_BroadcastExpr(EXPRESSIONS e, FILEHANDLE *file)
Definition parallel.c:3552
void PF_ReceiveRuntimeError(void) NORETURN
Definition parallel.c:4820
int PF_InParallelProcessor(void)
Definition parallel.c:3627