/* Same behavior as PMPI_Irsend.c */ int PMPI_Issend (void* message, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request* request) { int size, retval, index; char* p; _MPI_COVERAGE(); _MPI_CHECK_STATUS(&comm); retval = _MPI_checkRequest(*request); if ( retval!=MPI_SUCCESS ) { _MPI_Set_Request(request, message, count, datatype, _MPI_TRUE, tag, comm); } retval = _MPI_checks(message, count, datatype, dest, tag, comm); if (retval == MPI_SUCCESS) { index = _MPI_Req_Find(tag, comm); if ( index >= 0 ) { size = _MPI_calculateSize(count, datatype); p = (char *)_MPI_safeMalloc(size, "Error with malloc for send buffer."); p = memcpy(p, message, size); retval =_MPI_Buff_Insert(p, count, datatype, tag, comm); return retval; } return MPI_ERR_PENDING; } else { _MPI_ERR_ROUTINE (retval, "MPI_ISSEND / MPI_IRSEND: argument error"); MPI_Abort (comm, retval); } _MPI_COVERAGE(); return retval; }
/*==========================================================================*/ int PMPI_Scatter (void *sendbuf, int sendcnt, MPI_Datatype sendtype, void *recvbuf, int recvcnt, MPI_Datatype recvtype, int root, MPI_Comm comm) { int sendsize, recvsize, retval; _MPI_COVERAGE(); _MPI_CHECK_STATUS(&comm); retval = _MPI_checks(sendbuf, sendcnt, sendtype, _MPI_RANK, MPI_ANY_TAG, comm); if (retval != MPI_SUCCESS) return retval; retval = _MPI_checks(recvbuf,recvcnt,recvtype, _MPI_RANK, MPI_ANY_TAG, comm); if (retval == MPI_SUCCESS) { recvsize = _MPI_calculateSize(recvcnt, recvtype); sendsize = _MPI_calculateSize(sendcnt, sendtype); if (recvsize < sendsize) /*MESSAGE IS TRUNCATED*/ { recvbuf = memcpy(recvbuf, sendbuf, recvsize); printf("MPI_RECV : Message truncated.\n"); MPI_Abort(comm, MPI_ERR_COUNT); return MPI_ERR_COUNT; } else { recvbuf = memcpy(recvbuf, sendbuf, sendsize); } } _MPI_COVERAGE(); return _MPI_NOT_OK; }
/*=============================================================================================*/ int PMPI_Msend (void* message, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { int size, retval; char* p; /* option 1: Assert( _MPI_IS_INITIALIZED() ); */ _MPI_COVERAGE(); _MPI_CHECK_STATUS(&comm); retval = _MPI_checks(message, count, datatype, dest, tag, comm); /* option 2: STANDARD_MPI_CHECK(comm); */ if (retval == MPI_SUCCESS) { size = _MPI_calculateSize(count, datatype); p = (char *)_MPI_safeMalloc(size, "Error with malloc for send buffer."); p = memcpy(p, message, size); retval =_MPI_Buff_Insert(p, count, datatype, tag, comm); return retval; } else { _MPI_ERR_ROUTINE (retval, "MPI_SEND / MPI_ISEND: argument error"); MPI_Abort (comm, retval); } _MPI_COVERAGE(); return _MPI_NOT_OK; }
int PMPI_Comm_compare ( MPI_Comm comm1, MPI_Comm comm2, int *result) { int index1, index2; /* treat an index as the MPI communicator "context" */ MPI_Group group1, group2; int gcmp; _MPI_COVERAGE(); *result = MPI_UNEQUAL; if (_MPI_CHECK_STATUS(&comm1) == _MPI_OK && _MPI_CHECK_STATUS(&comm2) == _MPI_OK) { _MPI_COVERAGE(); if (_MPI_Comm_check_legal(comm1, &index1)==MPI_SUCCESS && _MPI_Comm_check_legal(comm2, &index2)==MPI_SUCCESS) { _MPI_COVERAGE(); if (comm1 == MPI_COMM_NULL || comm2 == MPI_COMM_NULL) return MPI_ERR_COMM; if ( index1 == index2 ) { _MPI_COVERAGE(); *result = MPI_IDENT; } else { _MPI_COVERAGE(); group1 = _MPI_COMM_LIST[index1].group; group2 = _MPI_COMM_LIST[index2].group; if ( PMPI_Group_compare( group1, group2, &gcmp ) != MPI_SUCCESS ) return MPI_ERR_GROUP; if ( gcmp == MPI_IDENT ) *result = MPI_CONGRUENT; if ( gcmp == MPI_SIMILAR ) *result = MPI_SIMILAR; } return MPI_SUCCESS; } } return MPI_ERR_COMM; }
/* STUB */ int PMPI_Alltoall( void *sendbuf, int sendcount, MPI_Datatype sendtype, void *recvbuf, int recvcount, MPI_Datatype recvtype, MPI_Comm comm ) { int send_size; int recv_size; _MPI_COVERAGE(); if ( sendbuf == 0 ) return MPI_ERR_ARG; if ( sendcount <= 0 ) return MPI_ERR_ARG; if ( recvbuf == 0 ) return MPI_ERR_ARG; if ( recvcount <= 0 ) return MPI_ERR_ARG; _MPI_CHECK_STATUS(&comm); /* TODO: This is not really correct */ switch( _MPI_checkSendType(sendtype) ) { case _MPI_DEFAULT: _MPI_COVERAGE(); switch( _MPI_checkSendType(recvtype) ) { case _MPI_DEFAULT: _MPI_COVERAGE(); send_size = _MPI_calculateSize(sendcount, sendtype); recv_size = _MPI_calculateSize(recvcount, recvtype); if ( send_size < recv_size ) { _MPI_COVERAGE(); memcpy(recvbuf,sendbuf,send_size); } else { _MPI_COVERAGE(); memcpy(recvbuf,sendbuf,recv_size); } return MPI_SUCCESS; default: return MPI_Abort(comm, MPI_UNDEFINED); } default: return MPI_Abort(comm, MPI_UNDEFINED); } }
int PMPI_Comm_rank(MPI_Comm comm, int* rank) { int index; if (_MPI_CHECK_STATUS(&comm) == _MPI_OK) { if (_MPI_Comm_check_legal(comm, &index) == MPI_SUCCESS) { *rank = _MPI_RANK; return MPI_SUCCESS; } _MPI_ERR_ROUTINE(MPI_ERR_COMM, "MPI_COMM_RANK: Null communicator."); MPI_Abort (comm, MPI_ERR_COMM); return MPI_ERR_COMM; } else { _MPI_ERR_ROUTINE(MPI_ERR_IN_STATUS, "MPI_COMM_RANK: MPI initialization error."); MPI_Abort (comm, MPI_ERR_IN_STATUS); return MPI_ERR_ARG; } }
/*=============================================================================================*/ int PMPI_Send (void* message, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { int size, retval, sendType, index; MPI_Aint position, copiedPointer; _MPI_TYPE_INFO *info; char* p; _MPI_COVERAGE(); _MPI_CHECK_STATUS(&comm); retval = _MPI_checks(message, count, datatype, dest, tag, comm); if (retval == MPI_SUCCESS) { sendType = _MPI_checkSendType(datatype); switch (sendType) { case _MPI_DEFAULT: { size = _MPI_calculateSize(count, datatype); p = (char *)_MPI_safeMalloc(size, "Error with malloc for send buffer."); p = memcpy(p, message, size); retval =_MPI_Buff_Insert(p, count, datatype, tag, comm); return retval; } case _MPI_CONTIG: { sendType = _MPI_FindType(datatype); size = _MPI_TYPE_LIST[sendType].extent; p = (char *)_MPI_safeMalloc(size, "Error with malloc for send buffer."); p = memcpy(p, message, size); retval =_MPI_Buff_Insert(p, count, datatype, tag, comm); return retval; } case _MPI_INDEXED: { sendType = _MPI_FindType(datatype); size = _MPI_TYPE_LIST[sendType].extent; p = (char *)_MPI_safeMalloc(size, "Error with malloc for send buffer."); /* ================================================== */ /* Determine the correct parts to save to the buffers */ info = _MPI_TYPE_LIST[sendType].info; position = (MPI_Aint) 0; copiedPointer = (MPI_Aint) 0; for (index = 0; index < info->count; index++) { position = info->stride[index]*sizeof(info->types[0]); p = memcpy(p+copiedPointer, ((char*)message)+position, info->blocklen[index]*sizeof(info->types[0])); copiedPointer += info->blocklen[index]*sizeof(info->types[0]); } retval =_MPI_Buff_Insert(p, count, datatype, tag, comm); return retval; } case _MPI_VECTOR: { sendType = _MPI_FindType(datatype); size = _MPI_TYPE_LIST[sendType].extent; p = (char *)_MPI_safeMalloc(size, "Error with malloc for send buffer."); /* =================================== */ /* Figure out the correct ones to pass */ retval =_MPI_Buff_Insert(p, count, datatype, tag, comm); return retval; } case _MPI_STRUCT: { sendType = _MPI_FindType(datatype); size = _MPI_TYPE_LIST[sendType].extent; p = (char *)_MPI_safeMalloc(size, "Error with malloc for send buffer."); /* =================================== */ /* Figure out the correct ones to pass */ retval =_MPI_Buff_Insert(p, count, datatype, tag, comm); return retval; } default: { fprintf(stderr,"SEND: mpi_Hindexed or mpi_Hvector not implemented\n"); MPI_Abort (comm, _MPI_NOT_OK); } } } else { _MPI_ERR_ROUTINE (retval, "MPI_SEND / MPI_ISEND: argument error"); MPI_Abort (comm, retval); } _MPI_COVERAGE(); return _MPI_NOT_OK; }