/* * Sets up the mpi enviromment. This function should be called before any other MPI * function. */ static YAP_Bool mpi_init(void){ int thread_level; char ** my_argv; int my_argc = YAP_Argv(&my_argv); // MPI_Init(&GLOBAL_argc, &GLOBAL_argv); MPI_Init_thread(&my_argc, &my_argv, MPI_THREAD_MULTIPLE, &thread_level); #ifdef DEBUG write_msg(__FUNCTION__,__FILE__,__LINE__,"Thread level: %d\n",thread_level); #endif #ifdef MPISTATS RESET_STATS(); #endif return true; }
static YAP_Bool mpi_reset_stats(void) {RESET_STATS(); return true;}
/******************************************************************** * Init *******************************************************************/ void init_mpi(void) { requests=new_hashtable(HASHSIZE); broadcasts=new_hashtable(HASHSIZE); DEL_BUFFER(); YAP_UserCPredicate( "mpi_init", mpi_init,0); // mpi_init/0 #ifdef USE_THREADS YAP_UserCPredicate( "mpi_init_rcv_thread", mpi_init_rcv_thread,1); // mpi_init_rcv_thread(+HandleMsgGoal/1) #endif YAP_UserCPredicate( "mpi_finalize", mpi_finalize,0); // mpi_finalize turn YAP_UserCPredicate( "mpi_comm_size", mpi_comm_size,1); // mpi_comm_size(-Size) YAP_UserCPredicate( "mpi_comm_rank", mpi_comm_rank,1); // mpi_comm_rank(-Rank) YAP_UserCPredicate( "mpi_version", mpi_version,2); // mpi_version(-Major,-Minor) YAP_UserCPredicate( "mpi_get_processor_name", mpi_get_processor_name,1); // mpi_get_processor_name(-Name) YAP_UserCPredicate( "mpi_send", mpi_send,3); // mpi_send(+Data, +Destination, +Tag). YAP_UserCPredicate( "mpi_isend",mpi_isend,4); YAP_UserCPredicate( "mpi_recv", mpi_recv,3); // mpi_recv(?Source,?Tag,-Data). YAP_UserCPredicate( "mpi_irecv", mpi_irecv,3); // mpi_irecv(?Source,?Tag,-Handle). YAP_UserCPredicate( "mpi_wait", mpi_wait,2); // mpi_wait(+Handle,-Status). YAP_UserCPredicate( "mpi_wait_recv", mpi_wait_recv,3); // mpi_wait_recv(+Handle,-Status,-Data). YAP_UserCPredicate( "mpi_test", mpi_test,2); // mpi_test(+Handle,-Status). YAP_UserCPredicate( "mpi_test_recv", mpi_test_recv,3); // mpi_test(+Handle,-Status,-Data). YAP_UserCPredicate( "mpi_bcast", mpi_bcast,2); // mpi_bcast(Root,Term) YAP_UserCPredicate( "mpi_bcast2", mpi_bcast2,2); // mpi_bcast2(Root,Term) YAP_UserCPredicate( "mpi_bcast3", mpi_bcast3,3); // mpi_bcast3(Root,Term,Tag) /** @pred mpi_bcast3(+ _Root_, + _Data_, + _Tag_) Broadcasts the message _Data_ with tag _Tag_ from the process with rank _Root_ to all other processes. */ YAP_UserCPredicate( "mpi_ibcast2", mpi_ibcast2,2); // mpi_ibcast(Root,Term) YAP_UserCPredicate( "mpi_ibcast3", mpi_ibcast3,3); // mpi_ibcast(Root,Term,Tag) /** @pred mpi_ibcast(+ _Root_, + _Data_, + _Tag_) Non-blocking operation. Broadcasts the message _Data_ with tag _Tag_ from the process with rank _Root_ to all other processes. */ YAP_UserCPredicate( "mpi_barrier", mpi_barrier,0); // mpi_barrier/0 YAP_UserCPredicate( "mpi_gc", mpi_gc,0); // mpi_gc/0 YAP_UserCPredicate( "mpi_default_buffer_size", mpi_default_buffer_size,2); // buffer size /** @pred mpi_default_buffer_size(- _OldBufferSize_, ? _NewBufferSize_) The _OldBufferSize_ argument unifies with the current size of the MPI communication buffer size and sets the communication buffer size _NewBufferSize_. The buffer is used for assynchronous waiting and for broadcast receivers. Notice that buffer is local at each MPI process. */ #ifdef MPISTATS YAP_UserCPredicate( "mpi_stats", mpi_stats,7); // mpi_stats(-Time,#MsgsRecv,BytesRecv,MaxRecev,#MsgSent,BytesSent,MaxSent) YAP_UserCPredicate( "mpi_reset_stats", mpi_reset_stats,0); // cleans the timers RESET_STATS(); #endif // YAP_UserCPredicate( "mpi_gather", mpi_gather,0); //mpi_gather(+RootRank,?SendData,?RecvData) // Each process (root process included) sends the contents of its send buffer to the root process. The root process receives the messages and stores them in rank order. The outcome is as if each of the n processes in the group (including the root process) had executed a call to MPI_Send and the root had executed n calls to MPI_Recv. The receive buffer is ignored for all non-root processes. // MPI_Scatter #ifdef DEBUG fprintf(stderr,"MPI module succesfully loaded."); fflush(stderr); #endif }