bsp_init(3)

NAME
bsp_init - initialise the BSPlib system

C SYNOPSIS
#include "bsp.h"

void bsp_init(void (*startproc
)(void), int argc
, char ** argv);

FORTRAN SYNOPSIS
SUBROUTINE bspinit(startproc)
INTERFACE
END INTERFACE

DESCRIPTION
The purpose of bsp_init is to support a mode of process intialisation that allows a single process to start execution and determine the number of parallel processes required for a calculation. The desired number of processes are then spawned using bsp_begin(3) . Execution of the spawned processes continues in a SPMD manner until bsp_end(3) is encountered by all the processes. At that point, all processes except process zero are terminated, and process zero is left to continue execution of the rest of the program sequentially.

The procedure bsp_init enables the implementation of BSPlib to simulate this dynamic spawning mechanism by giving a hint to the BSPlib system that SPMD computation will commence inside the procedure startproc . The procedure named in bsp_init must contain bsp_begin(3) and bsp_end(3) as its first and last statements.

EXAMPLES

1   A C implementation of a simple hello world program, that spawns a number of processes determined by user-driven input.

    #include <stdio.h>
    #include "bsp.h"
    int n; /* global variable
    void spmd_part() {
      bsp_begin(n);
        printf("Hello BSP Worldwide from process %d of %d,
               bsp_pid(),bsp_nprocs());
      bsp_end();
    }
    void main(int argc, char **argv) {
      bsp_init(spmd_part,argc,argv);
      printf("How many processes? ");
      scanf("%d",&n);
      printf("Only one process should print this\n");
      spmd_start();
      printf("Just about to finish\n");
    }
When the above program is executed a single process will begin execution and read a number from standard input that specifies the number of parallel processes to be spawned. The desired number of processes will then be spawned within the procedure spmd_part , and each process will print the string ``Hello BSP Worldwide''. An example compilation and execution is shown below:
    pippin> bspcc test.c -o hello
    pippin> ./hello
    How many processes? 4
    Only one process should print this
    Hello BSP Worldwide from process  1 of 4
    Hello BSP Worldwide from process  2 of 4
    Hello BSP Worldwide from process  0 of 4
    Hello BSP Worldwide from process  3 of 4
    Just about to finish

2   A Fortran 77 implementation of a simple hello world program, that spawns a number of processes determined by user-driven input.
            SUBROUTINE spmdpart
              INCLUDE 'fbsp.h'
              INTEGER nprocs
              COMMON /global/ nprocs
              CALL bspbegin(nprocs)
                WRITE (*,*) 'Hello BSP Worldwide from process',
         +                  bsppid(), ' of ',bspnprocs()
              CALL bspend()
            END
            PROGRAM MAIN
              EXTERNAL spmdpart
              INTEGER nprocs
              COMMON /global/ nprocs
              CALL bspinit(spmdpart)
              READ *,nprocs
              CALL spmdpart
            END
An example compilation and execution is shown below:
    pippin> bspf77 test.f -o hello
    pippin> ./hello
    4
    Hello BSP Worldwide from process	0	of	4
    Hello BSP Worldwide from process	2	of	4
    Hello BSP Worldwide from process	3	of	4
    Hello BSP Worldwide from process	1	of	4

SEE ALSO
bsplib(3), bsp_begin(3), bsp_end(3) ``BSPlib: The BSP Programming Library'' Jonathan M. D. Hill, Bill McColl, Dan C. Stefanescu, Mark W. Goudreau, Kevin Lang, Satish B. Rao, , Torsten Suel, Thanasis Tsantilas, and Rob Bisseling. Parallel Computing, to appear 1998. See http://www.bsp-worldwide.org for more details.

BUGS
Problems and bug reports should be mailed to bsplib-bugs@comlab.ox.ac.uk

AUTHORS
The Oxford BSP Toolset implementation of BSPlib was written by Jonathan.Hill@comlab.ox.ac.uk
http://www.comlab.ox.ac.uk/oucl/people/jonathan.hill.html