[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / rts / gum / ParInit.c
1 /****************************************************************************
2
3 [ParInit.c] Initialising the parallel RTS
4
5      P. Trinder, January 17th 1995.
6      An extension based on Kevin Hammond's GRAPH for PVM version
7      P. Trinder, July 1997.
8      Adapted for the new RTS
9
10 ****************************************************************************/
11
12 #ifdef PAR /* whole file */
13
14 #define NON_POSIX_SOURCE /* so says Solaris */
15
16 #include "Rts.h"
17 #include <setjmp.h>
18 #include "LLC.h"
19 #include "HLC.h"
20
21 /* Global conditions defined here. */
22
23 rtsBool
24         IAmMainThread =         rtsFalse,       /* Set for the main thread      */
25         GlobalStopPending =     rtsFalse;       /* Terminating                  */
26
27 /* Task identifiers for various interesting global tasks. */
28
29 GLOBAL_TASK_ID IOTask = 0,              /* The IO Task Id               */
30                SysManTask = 0,          /* The System Manager Task Id   */
31                mytid = 0;               /* This PE's Task Id            */
32
33 REAL_TIME       main_start_time;        /* When the program started     */
34 REAL_TIME       main_stop_time;         /* When the program finished    */
35 jmp_buf         exit_parallel_system;   /* How to abort from the RTS    */
36
37
38 /* Flag handling. */
39
40 /*rtsBool TraceSparks =    rtsFalse;            /* Enable the spark trace mode          */
41 /*rtsBool SparkLocally =   rtsFalse;            /* Use local threads if possible        */
42 /*rtsBool DelaySparks =    rtsFalse;            /* Use delayed sparking                 */
43 /*rtsBool LocalSparkStrategy =   rtsFalse;      /* Either delayed threads or local threads*/
44 /*rtsBool GlobalSparkStrategy =   rtsFalse;     /* Export all threads                   */
45 /*
46 /*rtsBool DeferGlobalUpdates =   rtsFalse;      /* Defer updating of global nodes       */
47
48 rtsBool fishing = rtsFalse;                     /* We have no fish out in the stream    */
49
50 /* Initialisation Routines */
51
52 /*
53 par_exit defines how to terminate the program.  If the exit code is
54 non-zero (i.e. an error has occurred), the PE should not halt until
55 outstanding error messages have been processed.  Otherwise, messages
56 might be sent to non-existent Task Ids.  The infinite loop will actually
57 terminate, since STG_Exception will call myexit\tr{(0)} when
58 it received a PP_FINISH from the system manager task.
59 */
60
61 void
62 par_exit(I_ n)                  /* NB: "EXIT" is set to "myexit" for parallel world */
63 {
64     GlobalStopPending = rtsTrue;
65     SendOp(PP_FINISH, SysManTask);
66     if (n != 0) 
67       WaitForTermination();
68     else
69       WaitForPEOp(PP_FINISH, SysManTask);
70     PEShutDown();
71 /*    fprintf(stderr,"PE %lx shutting down, %ld Threads run, %ld Sparks Ignored\n", (W_) mytid, threadId, sparksIgnored); */
72    fprintf(stderr,"PE %lx shutting down, %ld Threads run\n", (W_) mytid, threadId); 
73
74     exit(n);
75 }
76
77 void srand48 (long);
78 time_t time (time_t *);
79
80 void
81 initParallelSystem(void)
82 {
83     /* Don't buffer standard channels... */
84     setbuf(stdout,NULL);
85     setbuf(stderr,NULL);
86
87     srand48(time(NULL) * getpid());     /*Initialise Random-number generator seed*/
88                                         /* Used to select target of FISH message*/
89     InitPackBuffer();
90     InitMoreBuffers();
91 }
92
93 /* 
94  *SynchroniseSystem synchronises the reduction task with the system
95  *manager, and initialises the Global address tables (LAGA & GALA)
96  */
97
98 GLOBAL_TASK_ID *PEs;
99
100 void
101 SynchroniseSystem(void)
102 {
103     int i;
104
105     PEs = PEStartUp(nPEs);
106
107     /* Initialize global address tables */
108     initGAtables();
109
110     /* Record the shortened the PE identifiers for LAGA etc. tables */
111     for (i = 0; i < nPEs; ++i)
112         registerTask(PEs[i]);
113
114 }
115
116 #endif /* PAR -- whole file */
117