[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / rts / gum / Parallel.h
1
2 /************************************************************************
3  *                                                                      *
4  * [Parallel.h]{Definitions for parallel machines}
5  *                                                                      *
6  ************************************************************************/
7
8 #ifndef Parallel_H
9 #define Parallel_H
10
11 /*
12  * This section contains definitions applicable only to programs compiled
13  * to run on a parallel machine.  
14  *
15  * These basic definitions need to be around, one way or the other:
16  */
17
18 #include "ParTypes.h"
19
20 # ifdef PAR
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.
26         */
27
28 extern I_ do_sp_profile;
29
30 extern P_ PendingFetches;
31 extern GLOBAL_TASK_ID *PEs;
32
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;
40
41 extern int  nPEs;
42
43 extern rtsBool InGlobalGC;      /* Are we in the midst of performing global GC */
44
45 extern HashTable *pGAtoGALAtable;
46 extern HashTable *LAtoGALAtable;
47 extern GALA *freeIndirections;
48 extern GALA *liveIndirections;
49 extern GALA *freeGALAList;
50 extern GALA *liveRemoteGAs;
51 extern int thisPE;
52
53 void RunParallelSystem (StgPtr program_closure);
54 void initParallelSystem(void);
55 void SynchroniseSystem(void);
56
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);
67
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);
73
74 extern void par_exit (I_);
75 #endif
76
77 /************************************************************************
78  *                                                                      *
79 [anti-parallel-SM]{But if we're {\em not} compiling for a parallel system...}
80  *                                                                      *
81  ************************************************************************
82  *
83  *Get this out of the way.  These are all null definitions.
84  */
85
86 #if defined(GRAN)
87
88 #  define GA_HDR_SIZE                   1
89
90 #  define PROCS_HDR_POSN                PAR_HDR_POSN
91 #  define PROCS_HDR_SIZE                1
92
93 /* Accessing components of the field */
94 #  define       PROCS(closure)          (*((P_)(closure)+PROCS_HDR_POSN))
95
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)
99
100 #   define SET_STATIC_PROCS(closure)    , (W_) (Everywhere)
101
102 #  define SET_TASK_ACTIVITY(act)        /* nothing */
103 #endif
104
105 /************************************************************************
106  *                                                                      *
107  *[parallel-GAs]{Parallel-only part of fixed headers (global addresses)}
108  *                                                                      *
109  ************************************************************************
110  *
111  *Definitions relating to the entire parallel-only fixed-header field.
112  *
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.
118  */
119
120 #if defined(PAR) 
121
122 #  define GA(closure)                   getGA(closure)
123 #  define SET_GA(closure, ga)             setGA(closure,ga)
124
125 #  define SET_STATIC_GA(closure)
126 #  define SET_STATIC_PROCS(closure)
127   
128 #  define MAX_GA_WEIGHT                 0       /* Treat as 2^n */
129   
130 W_ PackGA (W_, int);
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)
134  */
135
136 /** 
137  *At the moment, there is no activity profiling for GUM:
138  */
139
140 #  define SET_TASK_ACTIVITY(act)
141
142
143
144 /************************************************************************
145  *                                                                      *
146  *[parallel-heap-objs]{Special parallel-only heap objects (`closures')}
147  *                                                                      *
148  ************************************************************************
149  *
150  *  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
151  *  NB: The following definitons are BOTH for GUM and GrAnSim -- HWL
152  *  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153  *
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
159  *
160  ************************************************************************
161  *                                                                      *
162  * [FETCHME-closures]{@FETCHME@ heap objects (`closures')}
163  *                                                                      *
164  ************************************************************************
165
166  ... Zapped for now PWT ...
167 */
168
169
170 /************************************************************************
171  *                                                                      *
172  [parallel-pack-defs]{Parallel-only Packing definitions}
173  *                                                                      *
174  ************************************************************************
175  *
176  *
177  *Symbolic constants for the packing code.
178  *
179  *This constant defines how many words of data we can pack into a single
180  *packet in the parallel (GUM) system.
181  */
182
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 */
187
188 void    InitClosureQueue (void);
189 P_      DeQueueClosure(void);
190 void    QueueClosure (P_ closure);
191 rtsBool QueueEmpty(void);
192 void    PrintPacket (P_ buffer);
193
194 P_      get_closure_info (P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type);
195
196 rtsBool isOffset (globalAddr *ga),
197         isFixed (globalAddr *ga);
198
199 void    doGlobalGC(void);
200
201 P_      PackNearbyGraph (P_ closure,W_ *size);
202 P_      UnpackGraph (W_ *buffer, globalAddr **gamap, W_ *nGAs);
203
204 #    define PACK_HEAP_REQUIRED  \
205       ((RTSflags.ParFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _FHS) * (SPEC_HS + 2))
206
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_ */
211
212 extern void    InitPackBuffer(void);
213 extern void    InitMoreBuffers(void);
214 extern void    InitPendingGABuffer(W_ size); 
215 extern void    AllocClosureQueue(W_ size);
216
217 #  define MAX_GAS       (RTSflags.ParFlags.packBufferSize / PACK_GA_SIZE)
218
219
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)
223
224 #  define PACK_HDR_SIZE 1       /* Words of header in a packet */
225
226 #  define PACK_PLC_SIZE 2       /* Size of a packed PLC in words */
227
228 #if defined(GRAN)
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);
235
236 void    InitClosureQueue (void);
237 P_      DeQueueClosure(void);
238 void    QueueClosure (P_ closure);
239 rtsBool QueueEmpty(void);
240 void    PrintPacket (P_ buffer);
241
242 P_      get_closure_info (P_ closure, W_ *size, W_ *ptrs, W_ *nonptrs, W_ *vhs, char *type);
243
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
248   
249 #  define FETCHME_GA_LOCN                       FETCHME_HS
250   
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)
254   
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 */
260
261 #    define PACK_HEAP_REQUIRED  \
262       ((RTSflags.GranFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE \
263       + _FHS) * (SPEC_HS + 2)) 
264
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
270 #endif /* GRAN */
271
272 #endif /* PAR */
273 #endif /* Parallel_H */
274
275
276