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 OutputDisabled = rtsFalse; /* Disable output for performance purposes */
53 rtsBool SparkLocally = rtsFalse; /* Use local threads if possible */
54 rtsBool DelaySparks = rtsFalse; /* Use delayed sparking */
55 rtsBool LocalSparkStrategy = rtsFalse; /* Either delayed threads or local threads */
56 rtsBool GlobalSparkStrategy = rtsFalse; /* Export all threads */
58 rtsBool ParallelStats = rtsFalse; /* Gather parallel statistics */
59 rtsBool DeferGlobalUpdates = rtsFalse; /* Defer updating of global nodes */
60 rtsBool fishing = rtsFalse; /* We have no fish out in the stream */
65 RunParallelSystem(program_closure)
66 StgPtr program_closure;
69 /* Return here when exiting the program. */
70 if (setjmp(exit_parallel_system) != 0)
73 /* Show that we've started */
74 if (IAmMainThread && !OutputDisabled)
75 fprintf(stderr, "Starting main program...\n");
78 /* Record the start time for statistics purposes. */
79 main_start_time = usertime();
80 /* fprintf(stderr, "Start time is %u\n", main_start_time); */
83 * Start the main scheduler which will fish for threads on all but the PE with
87 ScheduleThreads(program_closure);
92 @myexit@ defines how to terminate the program. If the exit code is
93 non-zero (i.e. an error has occurred), the PE should not halt until
94 outstanding error messages have been processed. Otherwise, messages
95 might be sent to non-existent Task Ids. The infinite loop will actually
96 terminate, since @STG_Exception@ will call @myexit@\tr{(0)} when
97 it received a @PP_FINISH@ from the system manager task.
101 myexit(n) /* NB: "EXIT" is set to "myexit" for parallel world */
104 GlobalStopPending = rtsTrue;
105 SendOp(PP_FINISH, SysManTask);
107 WaitForTermination();
109 WaitForPEOp(PP_FINISH, SysManTask);
111 fprintf(stderr,"Processor %lx shutting down, %ld Threads run\n", mytid, threadId);
113 /* And actually terminate -- always with code 0 */
114 longjmp(exit_parallel_system, 1);
119 void srand48 PROTO((long));
120 time_t time PROTO((time_t *));
123 initParallelSystem(STG_NO_ARGS)
126 /* Don't buffer standard channels... */
130 srand48(time(NULL) * getpid()); /*Initialise Random-number generator seed*/
132 OkToGC = rtsFalse; /* Must not GC till we have set up the environment */
133 /* because C is hanging onto heap pointers */
134 /* maybe bogus for the new RTS? -- KH */
135 /* And for the GUM system? PWT */
139 @SynchroniseSystem@ synchronises the reduction task with the system manager,
140 and gathers information about which PEs are actually in use.
146 SynchroniseSystem(STG_NO_ARGS)
151 _SetMyExceptionHandler(STG_Exception);
153 PEs = PEStartUp(nPEs);
155 /* Initialize global address tables */
158 /* Record the shortened the PE identifiers for LAGA etc. tables */
159 for (i = 0; i < nPEs; ++i)
160 registerTask(PEs[i]);
162 addr = WaitForPEOp(PP_INIT, ANY_GLOBAL_TASK);
163 SysManTask = Sender_Task(addr);
165 /* pvm_notify( PvmTaskExit, PP_FAIL, 1, &SysManTask); /* Setup an error handler */
167 /* Initialise the PE task array? */
170 #endif /* PAR -- whole file */