void FORTRAN_API mpi_file_iwrite_(MPI_Fint *fh,void *buf,int *count, MPI_Datatype *datatype,MPI_Fint *request, int *ierr ) { MPI_File fh_c; MPIO_Request req_c; fh_c = MPI_File_f2c(*fh); *ierr = MPI_File_iwrite(fh_c,buf,*count,*datatype,&req_c); *request = MPIO_Request_c2f(req_c); }
JNIEXPORT jlong JNICALL Java_mpi_File_iWrite( 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((MPI_File)fh, ptr, count, (MPI_Datatype)type, &request); ompi_java_exceptionCheck(env, rc); return (jlong)request; }
void mpi_file_iwrite_(MPI_Fint *fh,void *buf,int *count, MPI_Fint *datatype,MPI_Fint *request, int *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(fh_c,buf,*count,datatype_c,&req_c); *request = MPIO_Request_c2f(req_c); }
void mpi_file_iwrite_f(MPI_Fint *fh, char *buf, MPI_Fint *count, MPI_Fint *datatype, MPI_Fint *request, MPI_Fint *ierr) { MPI_File c_fh = MPI_File_f2c(*fh); MPI_Datatype c_type = MPI_Type_f2c(*datatype); MPI_Request c_request; *ierr = OMPI_INT_2_FINT(MPI_File_iwrite(c_fh, OMPI_F2C_BOTTOM(buf), OMPI_FINT_2_INT(*count), c_type, &c_request)); if (MPI_SUCCESS == OMPI_FINT_2_INT(*ierr)) { *request = MPI_Request_c2f(c_request); } }
int main(int argc, char **argv) { int *buf, i, rank, nints, len; char *filename, *tmp; int errs=0; MPI_File fh; MPI_Status statuses[NUMOPS]; MPI_Request requests[NUMOPS]; MTest_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* process 0 takes the file name as a command-line argument and broadcasts it to other processes */ if (!rank) { i = 1; while ((i < argc) && strcmp("-fname", *argv)) { i++; argv++; } if (i >= argc) { /* Use a default filename of testfile */ len = 8; filename = (char *)malloc(len + 10); strcpy( filename, "testfile" ); /* fprintf(stderr, "\n*# Usage: async_any -fname filename\n\n"); MPI_Abort(MPI_COMM_WORLD, 1); */ } else { argv++; len = (int)strlen(*argv); filename = (char *) malloc(len+10); strcpy(filename, *argv); } MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD); } else { MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); filename = (char *) malloc(len+10); MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD); } buf = (int *) malloc(SIZE); nints = SIZE/sizeof(int); for (i=0; i<nints; i++) buf[i] = rank*100000 + i; /* each process opens a separate file called filename.'myrank' */ tmp = (char *) malloc(len+10); strcpy(tmp, filename); sprintf(filename, "%s.%d", tmp, rank); MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, (char*)"native", MPI_INFO_NULL); for (i=0; i < NUMOPS; i++) { MPI_File_iwrite(fh, buf, nints, MPI_INT, &(requests[i])); } MPI_Waitall(NUMOPS, requests, statuses); MPI_File_close(&fh); /* reopen the file and read the data back */ for (i=0; i<nints; i++) buf[i] = 0; MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, (char*)"native", MPI_INFO_NULL); for (i=0; i < NUMOPS; i++) { MPI_File_iread(fh, buf, nints, MPI_INT, &(requests[i])); } MPI_Waitall(NUMOPS, requests, statuses); MPI_File_close(&fh); /* check if the data read is correct */ for (i=0; i<nints; i++) { if (buf[i] != (rank*100000 + i)) { errs++; fprintf(stderr, "Process %d: error, read %d, should be %d\n", rank, buf[i], rank*100000+i); } } free(buf); free(filename); free(tmp); MTest_Finalize(errs); MPI_Finalize(); return 0; }
int main(int argc, char **argv) { int *buf, i, rank, nints, len; char *filename, *tmp; int errs=0, toterrs; MPI_File fh; MPI_Status status; MPIO_Request request; int errcode = 0; MPI_Init(&argc,&argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* process 0 takes the file name as a command-line argument and broadcasts it to other processes */ if (!rank) { i = 1; while ((i < argc) && strcmp("-fname", *argv)) { i++; argv++; } if (i >= argc) { fprintf(stderr, "\n*# Usage: async -fname filename\n\n"); MPI_Abort(MPI_COMM_WORLD, 1); } argv++; len = strlen(*argv); filename = (char *) malloc(len+10); strcpy(filename, *argv); MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD); } else { MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); filename = (char *) malloc(len+10); MPI_Bcast(filename, len+10, MPI_CHAR, 0, MPI_COMM_WORLD); } buf = (int *) malloc(SIZE); nints = SIZE/sizeof(int); for (i=0; i<nints; i++) buf[i] = rank*100000 + i; /* each process opens a separate file called filename.'myrank' */ tmp = (char *) malloc(len+10); strcpy(tmp, filename); sprintf(filename, "%s.%d", tmp, rank); errcode = MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); if (errcode != MPI_SUCCESS) { handle_error(errcode, "MPI_File_open"); } MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL); errcode = MPI_File_iwrite(fh, buf, nints, MPI_INT, &request); if (errcode != MPI_SUCCESS) { handle_error(errcode, "MPI_File_iwrite"); } #ifdef MPIO_USES_MPI_REQUEST MPI_Wait( &request, &status ); #else MPIO_Wait(&request, &status); #endif MPI_File_close(&fh); /* reopen the file and read the data back */ for (i=0; i<nints; i++) buf[i] = 0; errcode = MPI_File_open(MPI_COMM_SELF, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); if (errcode != MPI_SUCCESS) { handle_error(errcode, "MPI_File_open"); } MPI_File_set_view(fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL); errcode = MPI_File_iread(fh, buf, nints, MPI_INT, &request); if (errcode != MPI_SUCCESS) { handle_error(errcode, "MPI_File_open"); } #ifdef MPIO_USES_MPI_REQUEST MPI_Wait( &request, &status ); #else MPIO_Wait(&request, &status); #endif MPI_File_close(&fh); /* check if the data read is correct */ for (i=0; i<nints; i++) { if (buf[i] != (rank*100000 + i)) { errs++; fprintf(stderr, "Process %d: error, read %d, should be %d\n", rank, buf[i], rank*100000+i); } } MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); if (rank == 0) { if( toterrs > 0) { fprintf( stderr, "Found %d errors\n", toterrs ); } else { fprintf( stdout, " No Errors\n" ); } } free(buf); free(filename); free(tmp); MPI_Finalize(); return 0; }
int main(int argc, char **argv) { int *buf, i, mynod, nprocs, len, b[3]; int errs=0, toterrs; MPI_Aint d[3]; MPI_File fh; MPI_Status status; char *filename; MPI_Datatype typevec, newtype, t[3]; MPIO_Request req; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD, &nprocs); MPI_Comm_rank(MPI_COMM_WORLD, &mynod); if (nprocs != 2) { fprintf(stderr, "Run this program on two processes\n"); MPI_Abort(MPI_COMM_WORLD, 1); } /* process 0 takes the file name as a command-line argument and broadcasts it to other processes */ if (!mynod) { i = 1; while ((i < argc) && strcmp("-fname", *argv)) { i++; argv++; } if (i >= argc) { fprintf(stderr, "\n*# Usage: i_noncontig -fname filename\n\n"); MPI_Abort(MPI_COMM_WORLD, 1); } argv++; len = strlen(*argv); filename = (char *) malloc(len+1); strcpy(filename, *argv); MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD); } else { MPI_Bcast(&len, 1, MPI_INT, 0, MPI_COMM_WORLD); filename = (char *) malloc(len+1); MPI_Bcast(filename, len+1, MPI_CHAR, 0, MPI_COMM_WORLD); } buf = (int *) malloc(SIZE*sizeof(int)); MPI_Type_vector(SIZE/2, 1, 2, MPI_INT, &typevec); b[0] = b[1] = b[2] = 1; d[0] = 0; d[1] = mynod*sizeof(int); d[2] = SIZE*sizeof(int); t[0] = MPI_LB; t[1] = typevec; t[2] = MPI_UB; MPI_Type_struct(3, b, d, t, &newtype); MPI_Type_commit(&newtype); MPI_Type_free(&typevec); if (!mynod) { #if VERBOSE fprintf(stderr, "\ntesting noncontiguous in memory, noncontiguous in file using nonblocking I/O\n"); #endif MPI_File_delete(filename, MPI_INFO_NULL); } MPI_Barrier(MPI_COMM_WORLD); MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL); for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE; MPI_File_iwrite(fh, buf, 1, newtype, &req); #ifdef MPIO_USES_MPI_REQUEST MPI_Wait(&req, &status); #else MPIO_Wait(&req, &status); #endif MPI_Barrier(MPI_COMM_WORLD); for (i=0; i<SIZE; i++) buf[i] = -1; MPI_File_iread_at(fh, 0, buf, 1, newtype, &req); #ifdef MPIO_USES_MPI_REQUEST MPI_Wait(&req, &status); #else MPIO_Wait(&req, &status); #endif for (i=0; i<SIZE; i++) { if (!mynod) { if ((i%2) && (buf[i] != -1)) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]); } if (!(i%2) && (buf[i] != i)) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i); } } else { if ((i%2) && (buf[i] != i + mynod*SIZE)) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i + mynod*SIZE); } if (!(i%2) && (buf[i] != -1)) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]); } } } MPI_File_close(&fh); MPI_Barrier(MPI_COMM_WORLD); if (!mynod) { #if VERBOSE fprintf(stderr, "\ntesting noncontiguous in memory, contiguous in file using nonblocking I/O\n"); #endif MPI_File_delete(filename, MPI_INFO_NULL); } MPI_Barrier(MPI_COMM_WORLD); MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE; MPI_File_iwrite_at(fh, mynod*(SIZE/2)*sizeof(int), buf, 1, newtype, &req); #ifdef MPIO_USES_MPI_REQUEST MPI_Wait(&req, &status); #else MPIO_Wait(&req, &status); #endif MPI_Barrier(MPI_COMM_WORLD); for (i=0; i<SIZE; i++) buf[i] = -1; MPI_File_iread_at(fh, mynod*(SIZE/2)*sizeof(int), buf, 1, newtype, &req); #ifdef MPIO_USES_MPI_REQUEST MPI_Wait(&req, &status); #else MPIO_Wait(&req, &status); #endif for (i=0; i<SIZE; i++) { if (!mynod) { if ((i%2) && (buf[i] != -1)) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]); } if (!(i%2) && (buf[i] != i)) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i); } } else { if ((i%2) && (buf[i] != i + mynod*SIZE)) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i + mynod*SIZE); } if (!(i%2) && (buf[i] != -1)) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be -1\n", mynod, i, buf[i]); } } } MPI_File_close(&fh); MPI_Barrier(MPI_COMM_WORLD); if (!mynod) { #if VERBOSE fprintf(stderr, "\ntesting contiguous in memory, noncontiguous in file using nonblocking I/O\n"); #endif MPI_File_delete(filename, MPI_INFO_NULL); } MPI_Barrier(MPI_COMM_WORLD); MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_CREATE | MPI_MODE_RDWR, MPI_INFO_NULL, &fh); MPI_File_set_view(fh, 0, MPI_INT, newtype, "native", MPI_INFO_NULL); for (i=0; i<SIZE; i++) buf[i] = i + mynod*SIZE; MPI_File_iwrite(fh, buf, SIZE, MPI_INT, &req); #ifdef MPIO_USES_MPI_REQUEST MPI_Wait(&req, &status); #else MPIO_Wait(&req, &status); #endif MPI_Barrier(MPI_COMM_WORLD); for (i=0; i<SIZE; i++) buf[i] = -1; MPI_File_iread_at(fh, 0, buf, SIZE, MPI_INT, &req); #ifdef MPIO_USES_MPI_REQUEST MPI_Wait(&req, &status); #else MPIO_Wait(&req, &status); #endif for (i=0; i<SIZE; i++) { if (!mynod) { if (buf[i] != i) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i); } } else { if (buf[i] != i + mynod*SIZE) { errs++; fprintf(stderr, "Process %d: buf %d is %d, should be %d\n", mynod, i, buf[i], i + mynod*SIZE); } } } MPI_File_close(&fh); MPI_Allreduce( &errs, &toterrs, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD ); if (mynod == 0) { if( toterrs > 0) { fprintf( stderr, "Found %d errors\n", toterrs ); } else { fprintf( stdout, " No Errors\n" ); } } MPI_Type_free(&newtype); free(buf); free(filename); MPI_Finalize(); return 0; }