MPI_Comm mpi_comm_new(void) { MPI_Comm chandle; Comm *cptr; static int num=0; mpi_alloc_handle(&chandle,(void **) &cptr); cptr->sendlist=AP_list_new(); cptr->recvlist=AP_list_new(); cptr->num=num++; return(chandle); }
/* Public function, wrapper for Type_struct that translates handle to * pointer (see NOTES at top of file) */ int MPI_Type_struct(int count, int * blocklens, MPI_Aint * displacements, MPI_Datatype *oldtypes, MPI_Datatype *newtype) { int i; Datatype oldtypes_ptr[count]; Datatype * newtype_ptr; for (i = 0; i < count; i++) { oldtypes_ptr[i] = *(Datatype*) mpi_handle_to_datatype(oldtypes[i]); } mpi_alloc_handle(newtype, (void**) &newtype_ptr); return Type_struct(count, blocklens, displacements, oldtypes_ptr, newtype_ptr); }
int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request *request) { pListitem match; Comm *mycomm; Req *rreq, *sreq; mycomm=mpi_handle_to_ptr(comm); /* mycomm=(Comm *)comm; */ #ifdef INFO fflush(stdout); fprintf(stderr,"MPI_Irecv: Comm=%d tag=%d count=%d type=%d\n", mycomm->num,tag,count,datatype); #endif if (source!=0 && source!=MPI_ANY_SOURCE && source!=MPI_PROC_NULL) { fprintf(stderr,"MPI_Irecv: bad source %d\n",source); abort(); } mpi_alloc_handle(request,(void **)&rreq); if (source==MPI_PROC_NULL) { rreq->complete=1; rreq->source=MPI_PROC_NULL; rreq->tag=MPI_ANY_TAG; return(MPI_SUCCESS); } if ( match=AP_list_search_func(mycomm->sendlist,mpi_match_send,&tag) ) { sreq=(Req *)AP_listitem_data(match); AP_list_delete_item(mycomm->sendlist,match); memcpy(buf,sreq->buf,count * datatype); rreq->complete=1; rreq->source=0; rreq->tag=sreq->tag; /* in case tag was MPI_ANY_TAG */ sreq->complete=1; #ifdef DEBUG printf("Completion(recv) value=%d tag=%d\n", *((int *)buf),rreq->tag); #endif return(MPI_SUCCESS); } rreq->buf=buf; rreq->tag=tag; rreq->complete=0; rreq->listitem=AP_list_append(mycomm->recvlist,rreq); #ifdef INFO print_list(mycomm->recvlist,"recvlist for comm ",mycomm->num); #endif return(MPI_SUCCESS); }