1 %****************************************************************************
3 \section[ParInit.lc]{Initialising the parallel RTS}
5 % (c) The Parade/AQUA Projects, Glasgow University, 1995.
6 % P. Trinder, January 17th 1995.
7 % An extension based on Kevin Hammond's GRAPH for PVM version
9 %****************************************************************************
12 #ifdef PAR /* whole file */
14 #define NON_POSIX_SOURCE /* so says Solaris */
22 Global conditions defined here.
26 OkToGC = rtsFalse, /* Set after initialisation */
27 IAmMainThread = rtsFalse, /* Set for the main thread */
28 GlobalStopPending = rtsFalse, /* Terminate */
29 GlobalGCPending = rtsFalse; /* Start Global GC */
32 Task identifiers for various interesting global tasks.
35 GLOBAL_TASK_ID IOTask = 0, /* The IO Task Id */
36 SysManTask = 0, /* The System Manager Task Id */
37 GCManTask = 0, /* The GC Manager Task Id */
38 StatsManTask = 0, /* The Statistics Manager Task Id*/
39 mytid = 0; /* This PE's Task Id */
43 REAL_TIME main_start_time; /* When the program started */
44 REAL_TIME main_stop_time; /* When the program finished */
45 jmp_buf exit_parallel_system; /* How to abort from the RTS */
51 rtsBool TraceSparks = rtsFalse; /* Enable the spark trace mode */
52 rtsBool SparkLocally = rtsFalse; /* Use local threads if possible */
53 rtsBool DelaySparks = rtsFalse; /* Use delayed sparking */
54 rtsBool LocalSparkStrategy = rtsFalse; /* Either delayed threads or local threads */
55 rtsBool GlobalSparkStrategy = rtsFalse; /* Export all threads */
57 rtsBool DeferGlobalUpdates = rtsFalse; /* Defer updating of global nodes */
58 rtsBool fishing = rtsFalse; /* We have no fish out in the stream */
63 RunParallelSystem(program_closure)
64 StgPtr program_closure;
67 /* Return here when exiting the program. */
68 if (setjmp(exit_parallel_system) != 0)
71 /* Show that we've started */
72 if (IAmMainThread && ! RTSflags.ParFlags.outputDisabled)
73 fprintf(stderr, "Starting main program...\n");
75 /* Record the start time for statistics purposes. */
76 main_start_time = usertime();
77 /* fprintf(stderr, "Start time is %u\n", main_start_time); */
80 * Start the main scheduler which will fish for threads on all but the PE with
84 ScheduleThreads(program_closure);
89 @myexit@ defines how to terminate the program. If the exit code is
90 non-zero (i.e. an error has occurred), the PE should not halt until
91 outstanding error messages have been processed. Otherwise, messages
92 might be sent to non-existent Task Ids. The infinite loop will actually
93 terminate, since @STG_Exception@ will call @myexit@\tr{(0)} when
94 it received a @PP_FINISH@ from the system manager task.
98 myexit(n) /* NB: "EXIT" is set to "myexit" for parallel world */
101 GlobalStopPending = rtsTrue;
102 SendOp(PP_FINISH, SysManTask);
104 WaitForTermination();
106 WaitForPEOp(PP_FINISH, SysManTask);
108 fprintf(stderr,"PE %lx shutting down, %ld Threads run, %ld Sparks Ignored\n", (W_) mytid, threadId, sparksIgnored);
110 /* And actually terminate -- always with code 0 */
111 longjmp(exit_parallel_system, 1);
116 void srand48 PROTO((long));
117 time_t time PROTO((time_t *));
120 initParallelSystem(STG_NO_ARGS)
122 /* Don't buffer standard channels... */
126 srand48(time(NULL) * getpid()); /*Initialise Random-number generator seed*/
128 OkToGC = rtsFalse; /* Must not GC till we have set up the environment */
129 /* because C is hanging onto heap pointers */
130 /* maybe bogus for the new RTS? -- KH */
131 /* And for the GUM system? PWT */
137 @SynchroniseSystem@ synchronises the reduction task with the system manager.
143 SynchroniseSystem(STG_NO_ARGS)
148 _SetMyExceptionHandler(STG_Exception);
150 PEs = PEStartUp(nPEs);
152 /* Initialize global address tables */
155 /* Record the shortened the PE identifiers for LAGA etc. tables */
156 for (i = 0; i < nPEs; ++i)
157 registerTask(PEs[i]);
159 /* pvm_notify( PvmTaskExit, PP_FAIL, 1, &SysManTask); /* Setup an error handler */
161 /* Initialise the PE task array? */
164 #endif /* PAR -- whole file */