2 /************************************************************************
4 * [Parallel.h]{Definitions for parallel machines}
6 ************************************************************************/
12 * This section contains definitions applicable only to programs compiled
13 * to run on a parallel machine.
15 * These basic definitions need to be around, one way or the other:
21 # define MAX_PES 256 /* Maximum number of processors */
22 /* MAX_PES is enforced by SysMan, which does not
23 allow more than this many "processors".
24 This is important because PackGA [GlobAddr.lc]
25 **assumes** that a PE# can fit in 8+ bits.
28 extern I_ do_sp_profile;
30 extern P_ PendingFetches;
31 extern GLOBAL_TASK_ID *PEs;
33 extern rtsBool IAmMainThread, GlobalStopPending;
34 extern rtsBool fishing;
35 extern GLOBAL_TASK_ID SysManTask;
36 extern int seed; /*pseudo-random-number generator seed:*/
37 /*Initialised in ParInit*/
38 extern I_ threadId; /*Number of Threads that have existed on a PE*/
39 extern GLOBAL_TASK_ID mytid;
43 extern rtsBool InGlobalGC; /* Are we in the midst of performing global GC */
45 extern HashTable *pGAtoGALAtable;
46 extern HashTable *LAtoGALAtable;
47 extern GALA *freeIndirections;
48 extern GALA *liveIndirections;
49 extern GALA *freeGALAList;
50 extern GALA *liveRemoteGAs;
53 void RunParallelSystem (StgPtr program_closure);
54 void initParallelSystem(void);
55 void SynchroniseSystem(void);
57 void registerTask (GLOBAL_TASK_ID gtid);
58 globalAddr *LAGAlookup (P_ addr);
59 P_ GALAlookup (globalAddr *ga);
60 globalAddr *MakeGlobal (P_ addr, rtsBool preferred);
61 globalAddr *setRemoteGA (P_ addr, globalAddr *ga, rtsBool preferred);
62 void splitWeight (globalAddr *to, globalAddr *from);
63 globalAddr *addWeight (globalAddr *ga);
64 void initGAtables(void);
65 W_ taskIDtoPE (GLOBAL_TASK_ID gtid);
66 void RebuildLAGAtable(void);
68 void *lookupHashTable (HashTable *table, StgWord key);
69 void insertHashTable (HashTable *table, StgWord key, void *data);
70 void freeHashTable (HashTable *table, void (*freeDataFun) (void *data));
71 HashTable *allocHashTable(void);
72 void *removeHashTable (HashTable *table, StgWord key, void *data);
74 extern void par_exit (I_);
77 /************************************************************************
79 [anti-parallel-SM]{But if we're {\em not} compiling for a parallel system...}
81 ************************************************************************
83 *Get this out of the way. These are all null definitions.
88 # define GA_HDR_SIZE 1
90 # define PROCS_HDR_POSN PAR_HDR_POSN
91 # define PROCS_HDR_SIZE 1
93 /* Accessing components of the field */
94 # define PROCS(closure) (*((P_)(closure)+PROCS_HDR_POSN))
96 # define SET_PROCS(closure, procs) \
97 PROCS(closure) = (W_)(procs) /* Set closure's location */
98 # define SET_GRAN_HDR(closure,pe) SET_PROCS(closure,pe)
100 # define SET_STATIC_PROCS(closure) , (W_) (Everywhere)
102 # define SET_TASK_ACTIVITY(act) /* nothing */
105 /************************************************************************
107 *[parallel-GAs]{Parallel-only part of fixed headers (global addresses)}
109 ************************************************************************
111 *Definitions relating to the entire parallel-only fixed-header field.
113 *On GUM, the global addresses for each local closure are stored in a separate
114 *hash table, rather then with the closure in the heap. We call @getGA@ to
115 *look up the global address associated with a local closure (0 is returned
116 *for local closures that have no global address), and @setGA@ to store a new
117 *global address for a local closure which did not previously have one.
122 # define GA(closure) getGA(closure)
123 # define SET_GA(closure, ga) setGA(closure,ga)
125 # define SET_STATIC_GA(closure)
126 # define SET_STATIC_PROCS(closure)
128 # define MAX_GA_WEIGHT 0 /* Treat as 2^n */
131 /* There was a PACK_GA macro here; but we turned it into the PackGA
132 * routine [GlobAddr.lc] (because it needs to do quite a bit of
133 * paranoia checking. Phil & Will (95/08)
137 *At the moment, there is no activity profiling for GUM:
140 # define SET_TASK_ACTIVITY(act)
144 /************************************************************************
146 *[parallel-heap-objs]{Special parallel-only heap objects (`closures')}
148 ************************************************************************
150 * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151 * NB: The following definitons are BOTH for GUM and GrAnSim -- HWL
152 * %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154 *The rest of this file contains definitions for {\it GUM and GrAnSim}.
155 *Although we don't create FetchMe nodes in GrAnSim (we simulate it by
156 *bitmask twiddling) we use FetchMe_info when converting nodes into RBHs
157 *(mainly to keep the code as close to GUM as possible). So, we define all
158 *the FetchMe related stuff in GrAnSim, too. % -- HWL
160 ************************************************************************
162 * [FETCHME-closures]{@FETCHME@ heap objects (`closures')}
164 ************************************************************************
166 ... Zapped for now PWT ...
170 /************************************************************************
172 [parallel-pack-defs]{Parallel-only Packing definitions}
174 ************************************************************************
177 *Symbolic constants for the packing code.
179 *This constant defines how many words of data we can pack into a single
180 *packet in the parallel (GUM) system.
183 void InitPackBuffer(void);
184 P_ PackTSO (P_ tso, W_ *size);
185 P_ PackStkO (P_ stko, W_ *size);
186 P_ AllocateHeap (W_ size); /* Doesn't belong */
188 void InitClosureQueue (void);
189 P_ DeQueueClosure(void);
190 void QueueClosure (P_ closure);
191 rtsBool QueueEmpty(void);
192 void PrintPacket (P_ buffer);
194 P_ get_closure_info (P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type);
196 rtsBool isOffset (globalAddr *ga),
197 isFixed (globalAddr *ga);
199 void doGlobalGC(void);
201 P_ PackNearbyGraph (P_ closure,W_ *size);
202 P_ UnpackGraph (W_ *buffer, globalAddr **gamap, W_ *nGAs);
204 # define PACK_HEAP_REQUIRED \
205 ((RTSflags.ParFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _FHS) * (SPEC_HS + 2))
207 extern W_ *PackBuffer; /* size: can be set via option */
208 extern long *buffer; /* HWL_ */
209 extern W_ *freeBuffer; /* HWL_ */
210 extern W_ *packBuffer; /* HWL_ */
212 extern void InitPackBuffer(void);
213 extern void InitMoreBuffers(void);
214 extern void InitPendingGABuffer(W_ size);
215 extern void AllocClosureQueue(W_ size);
217 # define MAX_GAS (RTSflags.ParFlags.packBufferSize / PACK_GA_SIZE)
220 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
221 /* Size of a packed fetch-me in words */
222 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
224 # define PACK_HDR_SIZE 1 /* Words of header in a packet */
226 # define PACK_PLC_SIZE 2 /* Size of a packed PLC in words */
229 /* ToDo: Check which of the PAR routines are needed in GranSim -- HWL */
230 void InitPackBuffer(void);
231 P_ AllocateHeap (W_ size); /* Doesn't belong */
232 P_ PackNearbyGraph (P_ closure, P_ tso, W_ *packbuffersize);
233 P_ PackOneNode (P_ closure, P_ tso, W_ *packbuffersize);
234 P_ UnpackGraph (P_ buffer);
236 void InitClosureQueue (void);
237 P_ DeQueueClosure(void);
238 void QueueClosure (P_ closure);
239 rtsBool QueueEmpty(void);
240 void PrintPacket (P_ buffer);
242 P_ get_closure_info (P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type);
244 /* These are needed in the packing code to get the size of the packet
245 right. The closures itself are never built in GrAnSim. */
246 # define FETCHME_VHS IND_VHS
247 # define FETCHME_HS IND_HS
249 # define FETCHME_GA_LOCN FETCHME_HS
251 # define FETCHME_CLOSURE_SIZE(closure) IND_CLOSURE_SIZE(closure)
252 # define FETCHME_CLOSURE_NoPTRS(closure) 0L
253 # define FETCHME_CLOSURE_NoNONPTRS(closure) (IND_CLOSURE_SIZE(closure)-IND_VHS)
255 # define MAX_GAS (RTSflags.GranFlags.packBufferSize / PACK_GA_SIZE)
256 # define PACK_GA_SIZE 3 /* Size of a packed GA in words */
257 /* Size of a packed fetch-me in words */
258 # define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
259 # define PACK_HDR_SIZE 4 /* Words of header in a packet */
261 # define PACK_HEAP_REQUIRED \
262 ((RTSflags.GranFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE \
263 + _FHS) * (SPEC_HS + 2))
265 # define PACK_FLAG_LOCN 0
266 # define PACK_TSO_LOCN 1
267 # define PACK_UNPACKED_SIZE_LOCN 2
268 # define PACK_SIZE_LOCN 3
269 # define MAGIC_PACK_FLAG 0xfabc
273 #endif /* Parallel_H */