[project @ 2000-01-13 14:33:57 by hwloidl]
[ghc-hetmet.git] / ghc / includes / Parallel.h
1 /*
2   Time-stamp: <Fri Dec 10 1999 17:15:01 Stardate: [-30]4028.38 software>
3  
4   Definitions for parallel machines.
5
6   This section contains definitions applicable only to programs compiled
7   to run on a parallel machine, i.e. on GUM. Some of these definitions
8   are also used when simulating parallel execution, i.e. on GranSim.
9 */
10
11 /*
12   ToDo: Check the PAR specfic part of this file 
13         Move stuff into Closures.h and ClosureMacros.h 
14         Clean-up GRAN specific code
15   -- HWL
16 */
17
18 #ifndef PARALLEL_H
19 #define PARALLEL_H
20
21 #if defined(PAR) || defined(GRAN)        /* whole file */
22
23 //@node Parallel definitions, End of File
24 //@section Parallel definitions
25
26 //@menu
27 //* Basic definitions::         
28 //* GUM::                       
29 //* GranSim::                   
30 //@end menu
31
32 //@node Basic definitions, GUM, Parallel definitions, Parallel definitions
33 //@subsection Basic definitions
34
35 /* SET_PAR_HDR and SET_STATIC_PAR_HDR now live in ClosureMacros.h */
36
37 /* Needed for dumping routines */
38 #if defined(PAR)
39 # define NODE_STR_LEN              20
40 # define TIME_STR_LEN              120
41 # define TIME                      rtsTime
42 # define CURRENT_TIME              msTime()
43 # define TIME_ON_PROC(p)           msTime()
44 # define CURRENT_PROC              thisPE
45 # define BINARY_STATS              RtsFlags.ParFlags.ParStats.Binary
46 #elif defined(GRAN)
47 # define NODE_STR_LEN              20
48 # define TIME_STR_LEN              120
49 # define TIME                      rtsTime
50 # define CURRENT_TIME              CurrentTime[CurrentProc]
51 # define TIME_ON_PROC(p)           CurrentTime[p]
52 # define CURRENT_PROC              CurrentProc
53 # define BINARY_STATS              RtsFlags.GranFlags.GranSimStats.Binary
54 #endif
55
56 #if defined(PAR)
57 #  define MAX_PES       256             /* Maximum number of processors */
58         /* MAX_PES is enforced by SysMan, which does not
59            allow more than this many "processors".
60            This is important because PackGA [GlobAddr.lc]
61            **assumes** that a PE# can fit in 8+ bits.
62         */
63
64 # define SPARK_POOLS    2   /* no. of spark pools */
65 # define REQUIRED_POOL  0   /* idx of pool of mandatory sparks (concurrency) */
66 # define ADVISORY_POOL  1   /* idx of pool of advisory sparks (parallelism) */
67 #endif
68
69 //@menu
70 //* GUM::                       
71 //* GranSim::                   
72 //@end menu
73 //*/
74
75 //@node GUM, GranSim, Basic definitions, Parallel definitions
76 //@subsection GUM
77
78 #if defined(PAR) 
79 /*
80 Symbolic constants for the packing code.
81
82 This constant defines how many words of data we can pack into a single
83 packet in the parallel (GUM) system.
84 */
85
86 //@menu
87 //* Types::                     
88 //* Externs::                   
89 //* Prototypes::                
90 //* Macros::                    
91 //@end menu
92 //*/
93
94 //@node Types, Externs, GUM, GUM
95 //@subsubsection Types
96
97 /* Sparks and spark queues */
98 typedef StgClosure  *rtsSpark;
99 typedef rtsSpark    *rtsSparkQ;
100
101 typedef struct rtsPackBuffer_ {
102   StgInt /* nat */           id; 
103   StgInt /* nat */           size;
104   StgInt /* nat */           unpacked_size;
105   StgTSO       *tso;
106   StgWord     *buffer[0];  
107 } rtsPackBuffer;
108
109 #define PACK_BUFFER_HDR_SIZE 4
110
111 //@node Externs, Prototypes, Types, GUM
112 //@subsubsection Externs
113
114 // extern rtsBool do_sp_profile;
115
116 extern globalAddr theGlobalFromGA, theGlobalToGA;
117 extern StgBlockedFetch *PendingFetches;
118 extern GlobalTaskId    *allPEs;
119
120 extern rtsBool      IAmMainThread, GlobalStopPending;
121 //extern rtsBool      fishing;
122 extern rtsTime      last_fish_arrived_at;
123 extern nat          outstandingFishes;
124 extern GlobalTaskId SysManTask;
125 extern int          seed;     /* pseudo-random-number generator seed: */
126                               /* Initialised in ParInit */
127 extern StgInt       threadId; /* Number of Threads that have existed on a PE */
128 extern GlobalTaskId mytid;
129
130 extern GlobalTaskId *allPEs;
131 extern nat nPEs;
132 extern nat sparksIgnored, sparksCreated, threadsIgnored, threadsCreated;
133 extern nat advisory_thread_count;
134
135 extern rtsBool InGlobalGC;  /* Are we in the midst of performing global GC */
136
137 static ullong startTime;    /* start of comp; in RtsStartup.c */
138
139 /* the spark pools proper */
140 extern rtsSpark *pending_sparks_hd[];  /* ptr to start of a spark pool */ 
141 extern rtsSpark *pending_sparks_tl[];  /* ptr to end of a spark pool */ 
142 extern rtsSpark *pending_sparks_lim[]; 
143 extern rtsSpark *pending_sparks_base[]; 
144 extern nat spark_limit[];
145
146 extern rtsPackBuffer *PackBuffer;      /* size: can be set via option */
147 extern rtsPackBuffer *buffer;             /* HWL_ */
148 extern rtsPackBuffer *freeBuffer;           /* HWL_ */
149 extern rtsPackBuffer *packBuffer;           /* HWL_ */
150 extern rtsPackBuffer *gumPackBuffer;
151
152 extern int thisPE;
153
154 /* From Global.c */
155 extern GALA *freeGALAList;
156 extern GALA *freeIndirections;
157 extern GALA *liveIndirections;
158 extern GALA *liveRemoteGAs;
159
160 /*
161 extern HashTable *taskIDtoPEtable;
162 extern HashTable *LAtoGALAtable;
163 extern HashTable *pGAtoGALAtable;
164 */
165
166 //@node Prototypes, Macros, Externs, GUM
167 //@subsubsection Prototypes
168
169 /* From ParInit.c */
170 void          initParallelSystem(void);
171 void          SynchroniseSystem(void);
172 void          par_exit(StgInt n);
173
174 PEs           taskIDtoPE (GlobalTaskId gtid);
175 void          registerTask (GlobalTaskId gtid);
176 globalAddr   *LAGAlookup (StgClosure *addr);
177 StgClosure   *GALAlookup (globalAddr *ga);
178 //static GALA  *allocIndirection (StgPtr addr);
179 globalAddr   *makeGlobal (StgClosure *addr, rtsBool preferred);
180 globalAddr   *setRemoteGA (StgClosure *addr, globalAddr *ga, rtsBool preferred);
181 void          splitWeight (globalAddr *to, globalAddr *from);
182 globalAddr   *addWeight (globalAddr *ga);
183 void          initGAtables (void);
184 void          RebuildLAGAtable (void);
185 StgWord       PackGA (StgWord pe, int slot);
186
187 //@node Macros,  , Prototypes, GUM
188 //@subsubsection Macros
189
190 /* delay (in us) between dying fish returning and sending out a new fish */
191 #define FISH_DELAY                   1000
192 /* max no. of outstanding spark steals */
193 #define MAX_FISHES                   1  
194
195 // ToDo: check which of these is actually needed!
196
197 #    define PACK_HEAP_REQUIRED  ((RtsFlags.ParFlags.packBufferSize - PACK_HDR_SIZE) / (PACK_GA_SIZE + _FHS) * (MIN_UPD_SIZE + 2))
198
199 #  define MAX_GAS       (RtsFlags.ParFlags.packBufferSize / PACK_GA_SIZE)
200
201
202 #  define PACK_GA_SIZE  3       /* Size of a packed GA in words */
203                                 /* Size of a packed fetch-me in words */
204 #  define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
205
206 #  define PACK_HDR_SIZE 1       /* Words of header in a packet */
207
208 #  define PACK_PLC_SIZE 2       /* Size of a packed PLC in words */
209
210 /*
211   Definitions relating to the entire parallel-only fixed-header field.
212
213   On GUM, the global addresses for each local closure are stored in a
214   separate hash table, rather then with the closure in the heap.  We call
215   @getGA@ to look up the global address associated with a local closure (0
216   is returned for local closures that have no global address), and @setGA@
217   to store a new global address for a local closure which did not
218   previously have one.  */
219
220 #  define GA_HDR_SIZE                   0
221   
222 #  define GA(closure)                   getGA(closure)
223   
224 #  define SET_GA(closure, ga)             setGA(closure,ga)
225 #  define SET_STATIC_GA(closure)
226 #  define SET_GRAN_HDR(closure,pe)
227 #  define SET_STATIC_PROCS(closure)
228   
229 #  define MAX_GA_WEIGHT                 0       /* Treat as 2^n */
230   
231 /* At the moment, there is no activity profiling for GUM.  This may change. */
232 #  define SET_TASK_ACTIVITY(act)        /* nothing */
233
234 #endif /* PAR */
235
236 //@node GranSim,  , GUM, Parallel definitions
237 //@subsection GranSim
238
239 #if defined(GRAN)
240 /* ToDo: Check which of the PAR routines are needed in GranSim -- HWL */
241
242 //@menu
243 //* Types::                     
244 //* Prototypes::                
245 //* Macros::                    
246 //@end menu
247 //*/
248
249 //@node Types, Prototypes, GranSim, GranSim
250 //@subsubsection Types
251
252 typedef struct rtsPackBuffer_ {
253   StgInt /* nat */           id;
254   StgInt /* nat */           size;
255   StgInt /* nat */           unpacked_size;
256   StgTSO       *tso;
257   StgClosure  **buffer;  
258 } rtsPackBuffer;
259
260 //@node Prototypes, Macros, Types, GranSim
261 //@subsubsection Prototypes
262
263
264 /* main packing functions */
265 /*
266 rtsPackBuffer *PackNearbyGraph(StgClosure* closure, StgTSO* tso, nat *packbuffersize);
267 rtsPackBuffer *PackOneNode(StgClosure* closure, StgTSO* tso, nat *packbuffersize);
268 void PrintPacket(rtsPackBuffer *buffer);
269 StgClosure *UnpackGraph(rtsPackBuffer* buffer);
270 */
271 /* important auxiliary functions */
272
273 /* 
274 OLD CODE -- HWL
275 void  InitPackBuffer(void);
276 P_    AllocateHeap (W_ size);
277 P_    PackNearbyGraph (P_ closure, P_ tso, W_ *packbuffersize);
278 P_    PackOneNode (P_ closure, P_ tso, W_ *packbuffersize);
279 P_    UnpackGraph (P_ buffer);
280
281 void    InitClosureQueue (void);
282 P_      DeQueueClosure(void);
283 void    QueueClosure (P_ closure);
284 // rtsBool QueueEmpty();
285 void    PrintPacket (P_ buffer);
286 */
287
288 // StgInfoTable *get_closure_info(StgClosure* node, unsigned int /* nat */ *size, unsigned int /* nat */ *ptrs, unsigned int /* nat */ *nonptrs, unsigned int /* nat */ *vhs, char *info_hdr_ty);
289 // int /* rtsBool */ IS_BLACK_HOLE(StgClosure* node)          ;
290
291 //@node Macros,  , Prototypes, GranSim
292 //@subsubsection Macros
293
294 /* max no. of outstanding spark steals */
295 #define MAX_FISHES                   1  
296
297 /* These are needed in the packing code to get the size of the packet
298    right. The closures itself are never built in GrAnSim. */
299 #  define FETCHME_VHS                           IND_VHS
300 #  define FETCHME_HS                            IND_HS
301   
302 #  define FETCHME_GA_LOCN                       FETCHME_HS
303   
304 #  define FETCHME_CLOSURE_SIZE(closure)         IND_CLOSURE_SIZE(closure)
305 #  define FETCHME_CLOSURE_NoPTRS(closure)               0L
306 #  define FETCHME_CLOSURE_NoNONPTRS(closure)    (IND_CLOSURE_SIZE(closure)-IND_VHS)
307   
308 #  define MAX_GAS       (RtsFlags.GranFlags.packBufferSize / PACK_GA_SIZE)
309 #  define PACK_GA_SIZE  3       /* Size of a packed GA in words */
310                                 /* Size of a packed fetch-me in words */
311 #  define PACK_FETCHME_SIZE (PACK_GA_SIZE + FIXED_HS)
312 #  define PACK_HDR_SIZE 4       /* Words of header in a packet */
313
314 #    define PACK_HEAP_REQUIRED  \
315       (RtsFlags.GranFlags.packBufferSize * sizeofW(StgClosure*) + \
316       2 * sizeofW(StgInt) + sizeofW(StgTSO*))
317
318 #    define PACK_FLAG_LOCN           0  
319 #    define PACK_TSO_LOCN            1
320 #    define PACK_UNPACKED_SIZE_LOCN  2
321 #    define PACK_SIZE_LOCN           3
322 #    define MAGIC_PACK_FLAG          0xfabc
323
324 #  define GA_HDR_SIZE                   1
325
326 #  define PROCS_HDR_POSN                PAR_HDR_POSN
327 #  define PROCS_HDR_SIZE                1
328
329 /* Accessing components of the field */
330 #  define PROCS(closure)                ((closure)->header.gran.procs)
331 /* SET_PROCS is now SET_GRAN_HEADER in ClosureMacros.h. */
332
333 #endif   /* GRAN */
334
335 //@node End of File,  , Parallel definitions
336 //@section End of File
337
338 #endif /* defined(PAR) || defined(GRAN)         whole file */
339
340 #endif /* Parallel_H */
341
342