[project @ 1996-07-19 18:36:04 by partain]
[ghc-hetmet.git] / ghc / runtime / gum / LLComms.lc
index 8839bde..200ca34 100644 (file)
@@ -67,13 +67,13 @@ unsigned op;
        return ("Unknown PE Opcode");
 }
 
-void NullException(STG_NO_ARGS)
+void
+NullException(STG_NO_ARGS)
 {
   fprintf(stderr,"Null_Exception: called");
 }
-void (*ExceptionHandler)() = NullException;
-
 
+void (*ExceptionHandler)() = NullException;
 \end{code}
 
 @trace_SendOp@ handles the tracing of messages at the OS level.  If
@@ -87,10 +87,7 @@ last message sent was for a PE or an IMU.
 rtsBool PETrace = rtsFalse, IMUTrace = rtsFalse, SystemTrace = rtsFalse, ReplyTrace = rtsFalse;
 
 static void
-trace_SendOp(op, dest, data1, data2)
-OPCODE op;
-GLOBAL_TASK_ID dest;
-unsigned data1, data2;
+trace_SendOp(OPCODE op, GLOBAL_TASK_ID dest, unsigned int data1, unsigned int data2)
 {
     char *OpName;
 
@@ -164,28 +161,14 @@ For example,
 \end{verbatim}
 
 \begin{code}
-
-#ifdef __STDC__
 void
 SendOpV(OPCODE op, GLOBAL_TASK_ID task, int n, ...)
-#else
-void
-SendOpV(op, task, n, va_alist)
-OPCODE op;
-GLOBAL_TASK_ID task;
-int n;
-va_dcl
-#endif
 {
     va_list ap;
     int i;
     StgWord arg;
 
-#ifdef __STDC__
     va_start(ap, n);
-#else
-    va_start(ap);
-#endif
 
     trace_SendOp(op, task, 0, 0);
 
@@ -216,29 +199,14 @@ Important: The variable arguments must all be StgWords.
 
 \begin{code}
 
-#ifdef __STDC__
 void
 SendOpNV(OPCODE op, GLOBAL_TASK_ID task, int nelem, StgWord *datablock, int narg, ...)
-#else
-void
-SendOpNV(op, task, nelem, datablock, narg, va_alist)
-OPCODE op;
-GLOBAL_TASK_ID task;
-int nelem;
-StgWord *datablock;
-int narg;
-va_dcl
-#endif
 {
     va_list ap;
     int i;
     StgWord arg;
 
-#ifdef __STDC__
     va_start(ap, narg);
-#else
-    va_start(ap);
-#endif
 
     trace_SendOp(op, task, 0, 0);
 /*  fprintf(stderr,"SendOpNV: op = %x, task = %x, narg = %d, nelem = %d\n",op,task,narg,nelem); */
@@ -308,12 +276,16 @@ GLOBAL_TASK_ID who;
   rtsBool match;
 
   do {
-/*    fprintf(stderr,"WaitForPEOp: op = %x, who = %x\n",op,who); */
+#if 0
+    fprintf(stderr,"WaitForPEOp: op = %x, who = %x\n",op,who); 
+#endif
     while((p = pvm_recv(ANY_TASK,ANY_OPCODE)) < 0)
       pvm_perror("WaitForPEOp: Waiting for PEOp");
       
     pvm_bufinfo( p, &nbytes, &opcode, &sender_id );
-
+#if 0
+    fprintf(stderr,"WaitForPEOp: received: opcode = %x, sender_id = %x\n",opcode,sender_id); 
+#endif
     match = (op == ANY_OPCODE || op == opcode) && (who == ANY_TASK || who == sender_id);
 
     if(match)
@@ -364,50 +336,47 @@ GLOBAL_TASK_ID *psender_id;
 
 @PEStartUp@ does the low-level comms specific startup stuff for a
 PE. It initialises the comms system, joins the appropriate groups,
-synchronises with the other PEs. Finally it receives from Control the
-array of Global Task Ids.
+synchronises with the other PEs. Receives and records in a global
+variable the task-id of SysMan. If this is the main thread (discovered
+in main.lc), identifies itself to SysMan. Finally it receives
+from SysMan an array of the Global Task Ids of each PE, which is
+returned as the value of the function.
 
 \begin{code}
-
-static char *
-xmalloc(n)
-unsigned n;
-{
-    char *p = malloc(n);
-
-    if (p == NULL) {
-       fprintf(stderr, "Memory allocation of %u bytes failed\n", n);
-       EXIT(EXIT_FAILURE);
-    }
-    return p;
-}
-
 GLOBAL_TASK_ID *
 PEStartUp(nPEs)
 unsigned nPEs;
 {
     int i;
     PACKET addr;
-    long *buffer = (long *) xmalloc(sizeof(long) * nPEs);
-    GLOBAL_TASK_ID *PEs = (GLOBAL_TASK_ID *) xmalloc(sizeof(GLOBAL_TASK_ID) * nPEs);
+    long *buffer = (long *) stgMallocBytes(sizeof(long) * nPEs, "PEStartUp (buffer)");
+    GLOBAL_TASK_ID *PEs
+      = (GLOBAL_TASK_ID *) stgMallocBytes(sizeof(GLOBAL_TASK_ID) * nPEs, "PEStartUp (PEs)");
 
-    mytid = _my_gtid;          /* Initialise PVM and get task id into global
-                                * variable */
+    mytid = _my_gtid;          /* Initialise PVM and get task id into global var.*/
 
-/*    fprintf(stderr,"PEStartup, No. PEs = %d \n", nPEs); */
+/*    fprintf(stderr,"PEStartup, Task id = [%x], No. PEs = %d \n", mytid, nPEs); */
     checkComms(pvm_joingroup(PEGROUP), "PEStartup");
 /*    fprintf(stderr,"PEStartup, Joined PEGROUP\n"); */
     checkComms(pvm_joingroup(PECTLGROUP), "PEStartup");
 /*    fprintf(stderr,"PEStartup, Joined PECTLGROUP\n"); */
-    checkComms(pvm_barrier(PECTLGROUP, nPEs + 1), "PEStartup");
+    checkComms(pvm_barrier(PECTLGROUP, nPEs+1), "PEStartup");
 /*    fprintf(stderr,"PEStartup, Passed PECTLGROUP barrier\n"); */
 
+    addr = WaitForPEOp(PP_SYSMAN_TID, ANY_GLOBAL_TASK);
+    SysManTask = Sender_Task(addr);
+    if (IAmMainThread) {               /* Main Thread Identifies itself to SysMan */
+       pvm_initsend(PvmDataDefault);
+       pvm_send(SysManTask, PP_MAIN_TASK);
+    } 
     addr = WaitForPEOp(PP_PETIDS, ANY_GLOBAL_TASK);
     GetArgs(buffer, nPEs);
+#if 0
     for (i = 0; i < nPEs; ++i) {
        PEs[i] = (GLOBAL_TASK_ID) buffer[i];
-       /* fprintf(stderr,"PEs[%d] = %x \n", i, PEs[i]);  */
+       fprintf(stderr,"PEs[%d] = %x \n", i, PEs[i]); 
     }
+#endif
     free(buffer);
     return PEs;
 }