FORTRAN_API void FORT_CALL mpi_file_iwrite_shared_(MPI_Fint *fh,void *buf,MPI_Fint *count, MPI_Datatype *datatype,MPI_Fint *request, MPI_Fint *ierr ) { MPI_File fh_c; MPIO_Request req_c; fh_c = MPI_File_f2c(*fh); *ierr = MPI_File_iwrite_shared(fh_c,buf,*count,*datatype,&req_c); *request = MPIO_Request_c2f(req_c); }
JNIEXPORT jlong JNICALL Java_mpi_File_iWriteShared( JNIEnv *env, jobject jthis, jlong fh, jobject buf, jint count, jlong type) { void *ptr = (*env)->GetDirectBufferAddress(env, buf); MPI_Request request; int rc = MPI_File_iwrite_shared((MPI_File)fh, ptr, count, (MPI_Datatype)type, &request); ompi_java_exceptionCheck(env, rc); return (jlong)request; }
void mpi_file_iwrite_shared_(MPI_Fint * fh, void *buf, MPI_Fint * count, MPI_Fint * datatype, MPI_Fint * request, MPI_Fint * ierr) { MPI_File fh_c; MPIO_Request req_c; MPI_Datatype datatype_c; fh_c = MPI_File_f2c(*fh); datatype_c = MPI_Type_f2c(*datatype); *ierr = MPI_File_iwrite_shared(fh_c, buf, *count, datatype_c, &req_c); *request = MPIO_Request_c2f(req_c); }
/** * fh is shared by all processes. * In case of reading, after one process finishes, and the fh moves to the new position, * the another process use this fh to reading. * * int MPI_File_seek_shared(MPI_File fh, MPI_Offset offset, int whence); * int MPI_File_get_position_shared(MPI_File fh, MPI_Offset * offset); * * int MPI_File_write_shared(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Status * status); * int MPI_File_read_shared(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Status * status); * * non-blocking read/write, need MPI_Wait to wait for finishing * int MPI_File_iread_shared(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Request * request) * int MPI_File_iwrite_shared(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Request * request) * * read/write in oder of rankID * int MPI_File_read_ordered(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Status * status); * int MPI_File_write_ordered(MPI_File fh, void * buf, int count, MPI_Datatype datatype, MPI_Status * status); */ int main(int argc, char *argv[]) { int totalTaskNum, rankID; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rankID); MPI_Comm_size(MPI_COMM_WORLD, &totalTaskNum); char *filename = "file.txt"; MPI_File fh; MPI_Status status; MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); char write_buf[128]; sprintf(write_buf, "rankID = %d, totalTaskNum = %d\n", rankID, totalTaskNum); // MPI_File_write_shared(fh, write_buf, strlen(write_buf), MPI_CHAR, &status); // MPI_File_write_ordered(fh, write_buf, strlen(write_buf), MPI_CHAR, &status); MPI_Request request; MPI_File_iwrite_shared(fh, write_buf, strlen(write_buf), MPI_CHAR, &request); MPI_Wait(&request, &status); MPI_Offset offset; MPI_File_get_position_shared(fh, &offset); printf("1: rankID = %d, Now the position is offset = %lld\n", rankID, offset); sleep(3); MPI_Offset offset2 = 0; int whence = MPI_SEEK_SET; MPI_File_seek_shared(fh, offset2, whence); MPI_File_get_position_shared(fh, &offset); printf("2: rankID = %d, Now the position is offset = %lld\n", rankID, offset); sleep(3); char read_buf[30]; // MPI_File_read_ordered(fh, read_buf, sizeof(read_buf), MPI_CHAR, &status); // MPI_File_read_shared(fh, read_buf, sizeof(read_buf), MPI_CHAR, &status); MPI_File_iread_shared(fh, read_buf, sizeof(read_buf), MPI_CHAR, &request); MPI_Wait(&request, &status); printf("rankID = %d, content = '%s'\n", rankID, read_buf); MPI_File_close(&fh);//after open, fh has the communicator info MPI_Finalize(); return 0; }
static void writeMPINONB(aFiledataM *of) { int amount; MPI_Status status; int rankNode = commInqRankNode (); int fileID = of->fileID; /* write buffer */ amount = ( int ) dbuffer_data_size ( of->db ); if ( amount == 0 ) return; xdebug3 ( "IOPI%d: Write buffer, size %d bytes, in", rankNode, amount ); xmpi ( MPI_Wait ( & ( of->request ), &status )); xmpi(MPI_File_iwrite_shared(of->fh, of->db->buffer, amount, MPI_UNSIGNED_CHAR, &of->request)); xdebug("%d bytes written for fileID=%d", amount, fileID); /* change outputBuffer */ dbuffer_reset ( of->db ); if ( of->db == of->db1 ) { xdebug3 ( "IOPE%d: fileID=%d, change to buffer 2 ...", rankNode, fileID ); of->db = of->db2; } else { xdebug3 ( "IOPE%d: fileID=%d, change to buffer 1 ...", rankNode, fileID ); of->db = of->db1; } return; }