Esempio n. 1
0
/**
 * 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;
}
Esempio n. 2
0
void FORTRAN_API mpi_file_get_position_shared_(MPI_Fint *fh, MPI_Offset *offset, int *ierr )
{
    MPI_File fh_c;
    
    fh_c = MPI_File_f2c(*fh);
    *ierr = MPI_File_get_position_shared(fh_c, offset);
}
Esempio n. 3
0
static int
destroyAFiledataMPINONB(void *v)
{
  int iret = 0;
  aFiledataM *of;
  MPI_Status status;
  int rankNode = commInqRankNode ();
  MPI_Offset endpos;

  of = (aFiledataM * ) v;

  xdebug ( "IOPE%d: close file %d, name=\"%s\"",
           rankNode, of->fileID, of->name );

  /* close file */
  xmpi(MPI_Wait(&of->request, &status));
  xmpi(MPI_Barrier(commInqCommNode()));
  xmpi(MPI_File_get_position_shared(of->fh, &endpos));
  xmpi(MPI_File_set_size(of->fh, endpos));
  iret = MPI_File_close ( & ( of->fh ));

  /* file closed, cleanup */

  dbuffer_cleanup ( & ( of->db1 ));
  dbuffer_cleanup ( & ( of->db2 ));

  free ( of );

  xdebug ( "IOPE%d: closed file, cleaned up, return",
           rankNode );

  return iret == MPI_SUCCESS ? 0 : -1;
}
Esempio n. 4
0
JNIEXPORT jlong JNICALL Java_mpi_File_getPositionShared(
        JNIEnv *env, jobject jthis, jlong fh)
{
    MPI_Offset offset;
    int rc = MPI_File_get_position_shared((MPI_File)fh, &offset);
    ompi_java_exceptionCheck(env, rc);
    return (jlong)offset;
}
void ompi_file_get_position_shared_f(MPI_Fint *fh, MPI_Offset *offset,
				    MPI_Fint *ierr)
{
    int c_ierr;
    MPI_File c_fh = MPI_File_f2c(*fh);
    MPI_Offset c_offset;

    c_ierr = MPI_File_get_position_shared(c_fh, &c_offset);
    if (NULL != ierr) *ierr = OMPI_INT_2_FINT(c_ierr);

    if (MPI_SUCCESS == c_ierr) {
        *offset = (MPI_Offset) c_offset;
    }
}