A Bayanihan BSP program is started by giving the name of a subclass of BSPMainWork to the BSPProblem object. BSPMainWork is a subclass of BSPWork that provides extra methods for server-side control of a computation, as shown in Table 2. The BSPProblem object assigns the BSPMainWork the reserved ID of 0, and calls its bsp_main() method, which is then expected to spawn work objects of the desired class. As the program runs, the main work object runs together with the other processes, and can communicate with them using BSP methods. In addition to spawning new work, the main work object can be used for coordinating other work objects, for collecting and sending results to interested watcher clients , and for receiving and reacting to user requests.
This is similar to the common programming practice in SPMD/MPMD systems like PVM, MPI, and BSPLib of having a ``master'' or ``console'' process that handles data distribution and coordinates the operation of all the other processes.
|int bsp_spawn( String class,int n )||spawn n BSPWork's of class class|
|int bsp_spawn( BSPWork w,int n )||spawn n BSPWork's of same class as w|
|void bsp_postResult( Result res )||post result for watchers|
|Object bsp_getRequest()||get user input from watchers|
|boolean isMain()||am I the main work?|
To write an application, one can write separate BSPMainWork and BSPWork classes, or a single BSPMainWork class with separate bsp_main() and bsp_run() methods. The latter is useful when the main work object has the same fields as the other work objects, and has the added advantage of keeping all the code in one file. Since bsp_main() defaults to calling bsp_run(), one can also write a single BSPMainWork class with a single bsp_run() method containing code for both the main work and the other processes. This allows SPMD-style programming, and is useful in cases where the main work code is very similar to the worker code, or where it is useful to see the master and worker codes for each superstep in the same place. The isMain() function can be used within bsp_run() to let the main work process differentiate itself.