5.5.5. Library Example #1


Up: Motivating Examples Next: Library Example #2 Previous: Example #4

The main program:

main(int argc, char **argv) 
   { 
     int done = 0; 
     user_lib_t *libh_a, *libh_b; 
     void *dataset1, *dataset2; 
     ... 
     MPI_Init(&argc, &argv); 
     ... 
     init_user_lib(MPI_COMM_WORLD, &libh_a); 
     init_user_lib(MPI_COMM_WORLD, &libh_b); 
     ... 
     user_start_op(libh_a, dataset1); 
     user_start_op(libh_b, dataset2); 
     ... 
     while(!done) 
     { 
        /* work */ 
        ... 
        MPI_Reduce(..., MPI_COMM_WORLD); 
        ... 
        /* see if done */ 
        ... 
     } 
     user_end_op(libh_a); 
     user_end_op(libh_b); 

uninit_user_lib(libh_a); uninit_user_lib(libh_b); MPI_Finalize(); }

The user library initialization code:
void init_user_lib(MPI_Comm comm, user_lib_t **handle) 
   { 
     user_lib_t *save; 

user_lib_initsave(&save); /* local */ MPI_Comm_dup(comm, &(save -> comm));

/* other inits */ ...

*handle = save; }

User start-up code:
void user_start_op(user_lib_t *handle, void *data) 
   { 
     MPI_Irecv( ..., handle->comm, &(handle -> irecv_handle) ); 
     MPI_Isend( ..., handle->comm, &(handle -> isend_handle) ); 
   } 
User communication clean-up code:
void user_end_op(user_lib_t *handle) 
   { 
     MPI_Status *status; 
     MPI_Wait(handle -> isend_handle, status); 
     MPI_Wait(handle -> irecv_handle, status); 
   } 
User object clean-up code:
void uninit_user_lib(user_lib_t *handle) 
   { 
     MPI_Comm_free(&(handle -> comm)); 
     free(handle); 
   } 



Up: Motivating Examples Next: Library Example #2 Previous: Example #4


Return to MPI 1.1 Standard Index
Return to MPI-2 Standard Index
Return to MPI Forum Home Page

MPI-1.1 of June 12, 1995
HTML Generated on August 6, 1997