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