[project @ 1999-02-15 14:30:56 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 #if 0
41 rtsBool TraceSparks =    rtsFalse;              /* Enable the spark trace mode          */
42 rtsBool SparkLocally =   rtsFalse;              /* Use local threads if possible        */
43 rtsBool DelaySparks =    rtsFalse;              /* Use delayed sparking                 */
44 rtsBool LocalSparkStrategy =   rtsFalse;        /* Either delayed threads or local threads*/
45 rtsBool GlobalSparkStrategy =   rtsFalse;       /* Export all threads                   */
46
47 rtsBool DeferGlobalUpdates =     rtsFalse;      /* Defer updating of global nodes       */
48 #endif
49
50 rtsBool fishing = rtsFalse;                     /* We have no fish out in the stream    */
51
52 /* Initialisation Routines */
53
54 /*
55 par_exit defines how to terminate the program.  If the exit code is
56 non-zero (i.e. an error has occurred), the PE should not halt until
57 outstanding error messages have been processed.  Otherwise, messages
58 might be sent to non-existent Task Ids.  The infinite loop will actually
59 terminate, since STG_Exception will call myexit\tr{(0)} when
60 it received a PP_FINISH from the system manager task.
61 */
62
63 void
64 par_exit(I_ n)                  /* NB: "EXIT" is set to "myexit" for parallel world */
65 {
66     GlobalStopPending = rtsTrue;
67     SendOp(PP_FINISH, SysManTask);
68     if (n != 0) 
69       WaitForTermination();
70     else
71       WaitForPEOp(PP_FINISH, SysManTask);
72     PEShutDown();
73 /*    fprintf(stderr,"PE %lx shutting down, %ld Threads run, %ld Sparks Ignored\n", (W_) mytid, threadId, sparksIgnored); */
74    fprintf(stderr,"PE %lx shutting down, %ld Threads run\n", (W_) mytid, threadId); 
75
76     exit(n);
77 }
78
79 void srand48 (long);
80 time_t time (time_t *);
81
82 void
83 initParallelSystem(void)
84 {
85     /* Don't buffer standard channels... */
86     setbuf(stdout,NULL);
87     setbuf(stderr,NULL);
88
89     srand48(time(NULL) * getpid());     /*Initialise Random-number generator seed*/
90                                         /* Used to select target of FISH message*/
91     InitPackBuffer();
92     InitMoreBuffers();
93 }
94
95 /* 
96  *SynchroniseSystem synchronises the reduction task with the system
97  *manager, and initialises the Global address tables (LAGA & GALA)
98  */
99
100 GLOBAL_TASK_ID *PEs;
101
102 void
103 SynchroniseSystem(void)
104 {
105     int i;
106
107     PEs = PEStartUp(nPEs);
108
109     /* Initialize global address tables */
110     initGAtables();
111
112     /* Record the shortened the PE identifiers for LAGA etc. tables */
113     for (i = 0; i < nPEs; ++i)
114         registerTask(PEs[i]);
115
116 }
117
118 #endif /* PAR -- whole file */
119