1 /* --------------------------------------------------------------------------
2 Time-stamp: <Sat Dec 04 1999 18:26:22 Stardate: [-30]3998.84 hwloidl>
3 $Id: ParInit.c,v 1.2 2000/01/13 14:34:08 hwloidl Exp $
5 Initialising the parallel RTS
7 An extension based on Kevin Hammond's GRAPH for PVM version
8 P. Trinder, January 17th 1995.
9 Adapted for the new RTS
10 P. Trinder, July 1997.
11 H-W. Loidl, November 1999.
13 ------------------------------------------------------------------------ */
15 #ifdef PAR /* whole file */
17 #define NON_POSIX_SOURCE /* so says Solaris */
21 //* Global variables::
22 //* Initialisation Routines::
25 //@node Includes, Global variables
26 //@subsection Includes
31 #include "ParallelRts.h"
36 //@node Global variables, Initialisation Routines, Includes
37 //@subsection Global variables
39 /* Global conditions defined here. */
41 rtsBool IAmMainThread = rtsFalse, /* Set for the main thread */
42 GlobalStopPending = rtsFalse; /* Terminating */
44 /* Task identifiers for various interesting global tasks. */
46 GlobalTaskId IOTask = 0, /* The IO Task Id */
47 SysManTask = 0, /* The System Manager Task Id */
48 mytid = 0; /* This PE's Task Id */
50 rtsTime main_start_time; /* When the program started */
51 rtsTime main_stop_time; /* When the program finished */
52 jmp_buf exit_parallel_system; /* How to abort from the RTS */
55 //rtsBool fishing = rtsFalse; /* We have no fish out in the stream */
56 rtsTime last_fish_arrived_at = 0; /* Time of arrival of most recent fish*/
57 nat outstandingFishes = 0; /* Number of active fishes */
60 /* GranSim: a globally visible array of spark queues */
61 rtsSpark *pending_sparks_hd[SPARK_POOLS], /* ptr to start of a spark pool */
62 *pending_sparks_tl[SPARK_POOLS], /* ptr to end of a spark pool */
63 *pending_sparks_lim[SPARK_POOLS],
64 *pending_sparks_base[SPARK_POOLS];
67 /* max number of sparks permitted on the PE;
68 see RtsFlags.ParFlags.maxLocalSparks */
69 nat spark_limit[SPARK_POOLS];
71 globalAddr theGlobalFromGA, theGlobalToGA;
73 HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACK !! see FETCH_ME_entry
74 Only used within FETCH_ME_entry as local vars, but they shouldn't
75 be defined locally in there -- that would move %esp and you'll never
79 globalAddr *rga_GLOBAL;
80 globalAddr *lga_GLOBAL;
81 globalAddr fmbqga_GLOBAL;
84 //@cindex PendingFetches
85 /* A list of fetch reply messages not yet processed; this list is filled
86 by awaken_blocked_queue and processed by processFetches */
87 StgBlockedFetch *PendingFetches = END_BF_QUEUE;
95 //@cindex sparksIgnored
96 nat sparksIgnored = 0, sparksCreated = 0,
97 threadsIgnored = 0, threadsCreated = 0;
99 //@cindex advisory_thread_count
100 nat advisory_thread_count = 0;
102 /* Where to write the log file
103 This is now in Parallel.c
104 FILE *gr_file = NULL;
105 char gr_filename[STATS_FILENAME_MAXLEN];
111 /* that's now all done via RtsFlags.ParFlags... */
112 rtsBool TraceSparks = rtsFalse; /* Enable the spark trace mode */
113 rtsBool SparkLocally = rtsFalse; /* Use local threads if possible */
114 rtsBool DelaySparks = rtsFalse; /* Use delayed sparking */
115 rtsBool LocalSparkStrategy = rtsFalse; /* Either delayed threads or local threads*/
116 rtsBool GlobalSparkStrategy = rtsFalse; /* Export all threads */
118 rtsBool DeferGlobalUpdates = rtsFalse; /* Defer updating of global nodes */
121 //@node Initialisation Routines, , Global variables
122 //@subsection Initialisation Routines
125 par_exit defines how to terminate the program. If the exit code is
126 non-zero (i.e. an error has occurred), the PE should not halt until
127 outstanding error messages have been processed. Otherwise, messages
128 might be sent to non-existent Task Ids. The infinite loop will actually
129 terminate, since STG_Exception will call myexit\tr{(0)} when
130 it received a PP_FINISH from the system manager task.
134 shutdownParallelSystem(StgInt n)
136 belch(" entered shutdownParallelSystem ...");
137 ASSERT(GlobalStopPending = rtsTrue);
138 sendOp(PP_FINISH, SysManTask);
140 waitForTermination();
142 waitForPEOp(PP_FINISH, SysManTask);
144 IF_PAR_DEBUG(verbose,
145 belch("--++ shutting down PE %lx, %ld sparks created, %ld sparks Ignored, %ld threads created, %ld threads Ignored",
146 (W_) mytid, sparksCreated, sparksIgnored,
147 threadsCreated, threadsIgnored));
151 /* Some prototypes */
153 time_t time (time_t *);
155 //@cindex initParallelSystem
157 initParallelSystem(void)
159 belch("entered initParallelSystem ...");
161 /* Don't buffer standard channels... */
165 srand48(time(NULL) * getpid()); /*Initialise Random-number generator seed*/
166 /* Used to select target of FISH message*/
168 theGlobalFromGA.payload.gc.gtid = 0;
169 theGlobalToGA.payload.gc.gtid = 0;
171 //IF_PAR_DEBUG(verbose,
172 belch("initPackBuffer ...");
173 if (!initPackBuffer())
174 barf("initPackBuffer");
176 // IF_PAR_DEBUG(verbose,
177 belch("initMoreBuffers ...");
178 if (!initMoreBuffers())
179 barf("initMoreBuffers");
181 // IF_PAR_DEBUG(verbose,
182 belch("initSparkPools ...");
183 if (!initSparkPools())
184 barf("initSparkPools");
188 * SynchroniseSystem synchronises the reduction task with the system
189 * manager, and initialises the Global address tables (LAGA & GALA)
192 //@cindex SynchroniseSystem
194 SynchroniseSystem(void)
198 fprintf(stderr, "SynchroniseSystem: nPEs=%d\n", nPEs);
200 initEachPEHook(); /* HWL: hook to be execed on each PE */
202 fprintf(stderr, "SynchroniseSystem: initParallelSystem\n");
203 initParallelSystem();
204 allPEs = startUpPE(nPEs);
206 /* Initialize global address tables */
209 /* Record the shortened the PE identifiers for LAGA etc. tables */
210 for (i = 0; i < nPEs; ++i) {
211 fprintf(stderr, "[%x] registering %d-th PE as %x\n", mytid, i, allPEs[i]);
212 registerTask(allPEs[i]);
216 #endif /* PAR -- whole file */
219 //* PendingFetches:: @cindex\s-+PendingFetches
220 //* SynchroniseSystem:: @cindex\s-+SynchroniseSystem
221 //* allPEs:: @cindex\s-+allPEs
222 //* initParallelSystem:: @cindex\s-+initParallelSystem
223 //* nPEs:: @cindex\s-+nPEs
224 //* par_exit:: @cindex\s-+par_exit
225 //* spark queue:: @cindex\s-+spark queue
226 //* sparksIgnored:: @cindex\s-+sparksIgnored