move the scan block pointer into the gct structure
[ghc-hetmet.git] / rts / parallel / LLC.h
1 /* --------------------------------------------------------------------------
2    Time-stamp: <Sun Mar 18 2001 21:23:50 Stardate: [-30]6349.45 hwloidl>
3
4    Low Level Communications Header (LLC.h)
5
6    Contains the definitions used by the Low-level Communications
7    module of the GUM Haskell runtime environment.
8    Based on the Graph for PVM implementation.
9
10    Phil Trinder, Glasgow University, 13th Dec 1994
11    Adapted for the 4.xx RTS
12    H-W. Loidl, Heriot-Watt, November 1999
13    ----------------------------------------------------------------------- */
14
15 #ifndef __LLC_H
16 #define __LLC_H
17
18 #ifdef PAR
19
20 //@node Low Level Communications Header, , ,
21 //@section Low Level Communications Header
22
23 //@menu
24 //* Includes::                  
25 //* Macros and Constants::      
26 //* PVM macros::                
27 //* Externs::                   
28 //@end menu
29
30 //@node Includes, Macros and Constants, Low Level Communications Header, Low Level Communications Header
31 //@subsection Includes
32
33 #include "Rts.h"
34 #include "Parallel.h"
35
36 #include "PEOpCodes.h"
37 #include "pvm3.h"
38
39 //@node Macros and Constants, PVM macros, Includes, Low Level Communications Header
40 //@subsection Macros and Constants
41
42 #define ANY_TASK        (-1)    /* receive messages from any task */
43 #define ANY_GLOBAL_TASK ANY_TASK
44 #define ANY_OPCODE      (-1)    /* receive any opcode */
45 #define ALL_GROUP       (-1)    /* wait for barrier from every group member */
46
47 #define PEGROUP         "PE"
48
49 #define MGRGROUP        "MGR"
50 #define SYSGROUP        "SYS"
51
52
53 #define PETASK          "PE"
54
55 //@node PVM macros, Externs, Macros and Constants, Low Level Communications Header
56 //@subsection PVM macros
57
58 #define sync(gp,op)             do { \
59                                   broadcast(gp,op); \
60                                   pvm_barrier(gp,ALL_GROUP); \
61                                 } while(0)
62
63 #define broadcast(gp,op)        do { \
64                                   pvm_initsend(PvmDataDefault); \
65                                   pvm_bcast(gp,op); \
66                                 } while(0)
67
68 #define checkComms(c,s)         do { \
69                                   if ((c)<0) { \
70                                     pvm_perror(s); \
71                                     stg_exit(EXIT_FAILURE); \
72                                 }} while(0)
73
74 #define _my_gtid                pvm_mytid()
75 #define GetPacket()             pvm_recv(ANY_TASK,ANY_OPCODE)
76 #define PacketsWaiting()        (pvm_probe(ANY_TASK,ANY_OPCODE) != 0)
77
78 #define SPARK_THREAD_DESCRIPTOR         1
79 #define GLOBAL_THREAD_DESCRIPTOR        2
80
81 #define _extract_jump_field(v)  (v)
82
83 #define MAX_DATA_WORDS_IN_PACKET        1024
84
85 /* basic PVM packing */
86 #define PutArg1(a)              pvm_pklong((long *)&(a),1,1)
87 #define PutArg2(a)              pvm_pklong((long *)&(a),1,1)
88 #define PutArgN(n,a)            pvm_pklong((long *)&(a),1,1)
89 #define PutArgs(b,n)            pvm_pklong((long *)b,n,1)
90
91 #define PutLit(l)               { int a = l; PutArgN(?,a); }
92
93 /* basic PVM unpacking */
94 #define GetArg1(a)              pvm_upklong((long *)&(a),1,1)
95 #define GetArg2(a)              pvm_upklong((long *)&(a),1,1)
96 #define GetArgN(n,a)            pvm_upklong((long *)&(a),1,1)
97 #define GetArgs(b,n)            pvm_upklong((long *)b,n,1)
98
99 //@node Externs,  , PVM macros, Low Level Communications Header
100 //@subsection Externs
101
102 /* basic message passing routines */
103 extern void sendOp   (OpCode,GlobalTaskId),
104             sendOp1  (OpCode,GlobalTaskId,StgWord),
105             sendOp2  (OpCode,GlobalTaskId,StgWord,StgWord),
106             sendOpV  (OpCode,GlobalTaskId,int,...), 
107             sendOpN  (OpCode,GlobalTaskId,int,StgPtr),
108             sendOpNV (OpCode,GlobalTaskId,int,StgPtr,int,...);
109
110 extern void broadcastOpN(OpCode op, char *group, int n, StgPtr args);
111
112 /* extracting data out of a packet */
113 OpCode        getOpcode (rtsPacket p);
114 void          getOpcodeAndSender (rtsPacket p, OpCode *popcode, 
115                                   GlobalTaskId *psender_id);
116 GlobalTaskId  senderTask (rtsPacket p);
117 rtsPacket     waitForPEOp(OpCode op, GlobalTaskId who, void(*processUnexpected)(rtsPacket) );
118
119 /* Init and shutdown routines */
120 void          startUpPE (void);
121 void          shutDownPE(void);
122 int           getExitCode(int nbytes, GlobalTaskId *sender_idp);
123
124 /* aux functions */
125 char  *getOpName (unsigned op);  // returns string of opcode
126 void   processUnexpectedMessage (rtsPacket);
127 //void   NullException(void);
128
129 #endif /*PAR */
130 #endif /*defined __LLC_H */