


bsp_init(3)             BSPlib FUNCTIONS              bsp_init(3)



NAME
     bsp_init - initialise the BSPlib system


C SYNOPSIS
     #include "bsp.h"

     void bsp_init(void (*_s_t_a_r_t_p_r_o_c)(void), int _a_r_g_c, char ** _a_r_g_v);

FORTRAN SYNOPSIS
     SUBROUTINE bspinit(_s_t_a_r_t_p_r_o_c)
     INTERFACE
        SUBROUTINE _s_t_a_r_t_p_r_o_c
     END INTERFACE


DESCRIPTION
     The purpose of bsp_init is to  support  a  mode  of  process
     intialisation  that  allows a single process to start execu-
     tion 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  pro-
     gram 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  _s_t_a_r_t_p_r_o_c.  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  _h_e_l_l_o  _w_o_r_l_d  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 %d0,
                     bsp_pid(),bsp_nprocs());
            bsp_end();



Oxford BSP Toolset  Last change: 1.4 25/9/98                    1






bsp_init(3)             BSPlib FUNCTIONS              bsp_init(3)



          }

          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 _s_p_m_d__p_a_r_t, 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  _h_e_l_l_o  _w_o_r_l_d
          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




Oxford BSP Toolset  Last change: 1.4 25/9/98                    2






bsp_init(3)             BSPlib FUNCTIONS              bsp_init(3)



                    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)

     ``_B_S_P_l_i_b: _T_h_e _B_S_P _P_r_o_g_r_a_m_m_i_n_g _L_i_b_r_a_r_y'' 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
     _h_t_t_p://_w_w_w._b_s_p-_w_o_r_l_d_w_i_d_e._o_r_g for more details.


BUGS
     Problems  and  bug  reports  should  be  mailed  to  _b_s_p_l_i_b-
     _b_u_g_s@_c_o_m_l_a_b._o_x._a_c._u_k


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




















Oxford BSP Toolset  Last change: 1.4 25/9/98                    3



