int
mca_sharedfp_lockedfile_get_position(mca_io_ompio_file_t *fh,
                                     OMPI_MPI_OFFSET_TYPE * offset)
{
    int ret = OMPI_SUCCESS;
    mca_sharedfp_base_module_t * shared_fp_base_module;
    struct mca_sharedfp_base_data_t *sh = NULL;

    if(fh->f_sharedfp_data==NULL){
	opal_output(ompi_sharedfp_base_framework.framework_output,
		    "sharedfp_lockedfile_get_position - opening the shared file pointer\n");
        shared_fp_base_module = fh->f_sharedfp;

        ret = shared_fp_base_module->sharedfp_file_open(fh->f_comm,
                                                        fh->f_filename,
                                                        fh->f_amode,
                                                        fh->f_info,
                                                        fh);
        if (ret != OMPI_SUCCESS) {
            opal_output(0,"sharedfp_lockedfile_write - error opening the shared file pointer\n");
            return ret;
        }
    }
    /*Retrieve the shared file data struct*/
    sh = fh->f_sharedfp_data;

    /*Requesting the offset to write 0 bytes,
     *returns the current offset w/o updating it
     */
    ret = mca_sharedfp_lockedfile_request_position(sh,0,offset);

    return ret;
}
Ejemplo n.º 2
0
int mca_sharedfp_lockedfile_iread(mca_io_ompio_file_t *fh,
                                  void *buf,
                                  int count,
                                  ompi_datatype_t *datatype,
                                  MPI_Request * request)
{
    int ret = OMPI_SUCCESS;
    mca_sharedfp_base_module_t * shared_fp_base_module;
    OMPI_MPI_OFFSET_TYPE offset = 0;
    long bytesRequested = 0;
    size_t numofBytes;
    struct mca_sharedfp_base_data_t *sh = NULL;

    if ( NULL == fh->f_sharedfp_data ) {
	if ( mca_sharedfp_lockedfile_verbose ) {
	    opal_output(ompi_sharedfp_base_framework.framework_output,
			"sharedfp_lockedfile_iread: opening the shared file pointer\n");
	}
        shared_fp_base_module = fh->f_sharedfp;

        ret = shared_fp_base_module->sharedfp_file_open(fh->f_comm,
                                                        fh->f_filename,
                                                        fh->f_amode,
                                                        fh->f_info,
                                                        fh);
        if ( OMPI_SUCCESS != ret ) {
            opal_output(0,"sharedfp_lockedfile_iread - error opening the shared file pointer\n");
            return ret;
        }
    }

    /* Calculate the number of bytes to read */
    opal_datatype_type_size ( &datatype->super, &numofBytes);
    bytesRequested = count * numofBytes;

    if ( mca_sharedfp_lockedfile_verbose ) {
	opal_output(ompi_sharedfp_base_framework.framework_output,
		    "sharedfp_lockedfile_iread - Bytes Requested is %ld\n",bytesRequested);
    }


    /*Retrieve the shared file data struct*/
    sh = fh->f_sharedfp_data;

    /*Request the offset to write bytesRequested bytes*/
    ret = mca_sharedfp_lockedfile_request_position(sh,bytesRequested,&offset);
    offset /= sh->sharedfh->f_etype_size;

    if ( -1 != ret )  {
	if ( mca_sharedfp_lockedfile_verbose ) {
	    opal_output(ompi_sharedfp_base_framework.framework_output,
			"sharedfp_lockedfile_iread - Offset received is %lld\n",offset);
	}

        /* Read the file */
        ret = ompio_io_ompio_file_iread_at(sh->sharedfh,offset,buf,count,datatype,request);
    }

    return ret;
}
Ejemplo n.º 3
0
int mca_sharedfp_lockedfile_write (mca_io_ompio_file_t *fh,
                                   void *buf,
                                   int count,
                                   struct ompi_datatype_t *datatype,
                                   ompi_status_public_t *status)
{
    mca_sharedfp_base_module_t * shared_fp_base_module;
    OMPI_MPI_OFFSET_TYPE offset = 0;
    long bytesRequested = 0;
    size_t numofBytes;
    struct mca_sharedfp_base_data_t *sh = NULL;
    int ret = OMPI_SUCCESS;

    if ( NULL == fh->f_sharedfp_data ){
	if ( mca_sharedfp_lockedfile_verbose ) {
	    printf("sharedfp_lockedfile_write - opening the shared file pointer\n");
	}
        shared_fp_base_module = fh->f_sharedfp;

        ret = shared_fp_base_module->sharedfp_file_open(fh->f_comm,
                                                        fh->f_filename,
                                                        fh->f_amode,
                                                        fh->f_info,
                                                        fh);
        if (ret != OMPI_SUCCESS) {
            opal_output(0,"sharedfp_lockedfile_write - error opening the shared file pointer\n");
            return ret;
        }
    }

    /*Calculate the number of bytes to write*/
    opal_datatype_type_size( &datatype->super, &numofBytes);
    bytesRequested = count * numofBytes;
    if ( mca_sharedfp_lockedfile_verbose ) {
	printf("sharedfp_lockedfile_write: Bytes Requested is %ld\n",bytesRequested);
    }

    /*Retrieve the shared file data struct*/
    sh = fh->f_sharedfp_data;

    /* Request the offset to write bytesRequested bytes */
    ret = mca_sharedfp_lockedfile_request_position ( sh, bytesRequested, &offset);
    if (-1 != ret )  {
	if ( mca_sharedfp_lockedfile_verbose ) {
	    printf("sharedfp_lockedfile_write: Offset received is %lld\n",offset);
	}
        /* Write to the file */
        ret = ompio_io_ompio_file_write_at ( sh->sharedfh, offset, buf, count, datatype, status);
    }

    return ret;
}
Ejemplo n.º 4
0
int mca_sharedfp_lockedfile_read ( ompio_file_t *fh,
                                   void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
{
    int ret = OMPI_SUCCESS;
    OMPI_MPI_OFFSET_TYPE offset = 0;
    long bytesRequested = 0;
    size_t numofBytes;
    struct mca_sharedfp_base_data_t *sh = NULL;

    if ( fh->f_sharedfp_data == NULL ) {
	if ( mca_sharedfp_lockedfile_verbose ) {
            opal_output(ompi_sharedfp_base_framework.framework_output,
                        "sharedfp_lockedfile_read: module not initialized\n");
	}
        return OMPI_ERROR;
    }

    /* Calculate the number of bytes to read */
    opal_datatype_type_size ( &datatype->super, &numofBytes);
    bytesRequested = count * numofBytes;

    if ( mca_sharedfp_lockedfile_verbose ) {
        opal_output(ompi_sharedfp_base_framework.framework_output,
                    "sharedfp_lockedfile_read: Bytes Requested is %ld\n",bytesRequested);
    }

    /*Retrieve the shared file data struct*/
    sh = fh->f_sharedfp_data;

    /*Request the offset to write bytesRequested bytes*/
    ret = mca_sharedfp_lockedfile_request_position(sh,bytesRequested,&offset);
    offset /= fh->f_etype_size;

    if (-1 != ret )  {
	if ( mca_sharedfp_lockedfile_verbose ) {
            opal_output(ompi_sharedfp_base_framework.framework_output,
                        "sharedfp_lockedfile_read: Offset received is %lld\n",offset);
	}

        /* Read the file */
        ret = mca_common_ompio_file_read_at(fh,offset,buf,count,datatype,status);
    }

    return ret;
}
Ejemplo n.º 5
0
int mca_sharedfp_lockedfile_write_ordered (mca_io_ompio_file_t *fh,
                                           void *buf,
                                           int count,
                                           struct ompi_datatype_t *datatype,
                                           ompi_status_public_t *status)
{
    int ret = OMPI_SUCCESS;
    mca_sharedfp_base_module_t * shared_fp_base_module=NULL;
    OMPI_MPI_OFFSET_TYPE offset = 0;
    long sendBuff = 0;
    long *buff=NULL;
    long offsetBuff;
    OMPI_MPI_OFFSET_TYPE offsetReceived = 0;
    long bytesRequested = 0;
    int recvcnt = 1, sendcnt = 1;
    size_t numofBytes;
    int rank, size, i;

    struct mca_sharedfp_base_data_t *sh = NULL;

    if( NULL == fh->f_sharedfp_data ) {
	if ( mca_sharedfp_lockedfile_verbose ) {
	    printf("sharedfp_lockedfile_write_ordered - opening the shared file pointer\n");
	}
        shared_fp_base_module = fh->f_sharedfp;

        ret = shared_fp_base_module->sharedfp_file_open(fh->f_comm,
                                                        fh->f_filename,
                                                        fh->f_amode,
                                                        fh->f_info,
                                                        fh);
        if ( OMPI_SUCCESS != ret ) {
            opal_output(0,"sharedfp_lockedfile_write_ordered - error opening the shared file pointer\n");
            return ret;
        }
    }

    /*Retrieve the new communicator*/
    sh = fh->f_sharedfp_data;

    /* Calculate the number of bytes to write*/
    opal_datatype_type_size ( &datatype->super, &numofBytes);
    sendBuff = count * numofBytes;

    /* Get the ranks in the communicator */
    rank = ompi_comm_rank ( sh->comm );
    size = ompi_comm_size ( sh->comm );

    if ( 0 == rank ) {
        buff = (long*) malloc (sizeof(long) * size);
        if ( NULL == buff ) {
            return OMPI_ERR_OUT_OF_RESOURCE;
	}
    }

    ret = sh->comm->c_coll.coll_gather ( &sendBuff, sendcnt, OMPI_OFFSET_DATATYPE, buff, recvcnt,
					 OMPI_OFFSET_DATATYPE, 0, sh->comm,
					 sh->comm->c_coll.coll_gather_module );
    if ( OMPI_SUCCESS != ret ) {
	goto exit;
    }

    /* All the counts are present now in the recvBuff.
       The size of recvBuff is sizeof_newComm
     */
    if (rank == 0) {
        for ( i = 0; i < size ; i ++)  {
            bytesRequested += buff[i];
	    if ( mca_sharedfp_lockedfile_verbose ) {
		printf("sharedfp_lockedfile_write_ordered: Bytes requested are %ld\n",bytesRequested);
	    }
        }

        /*Request the offset to write bytesRequested bytes
          only the root process needs to do the request,
          since the root process will then tell the other
          processes at what offset they should write their
          share of the data.
         */
        ret = mca_sharedfp_lockedfile_request_position(sh,bytesRequested,&offsetReceived);
        if ( OMPI_SUCCESS != ret ){
            goto exit;
        }
	if ( mca_sharedfp_lockedfile_verbose ) {
	    printf("sharedfp_lockedfile_write_ordered: Offset received is %lld\n",offsetReceived);
	}
        buff[0] += offsetReceived;
        for (i = 1 ; i < size; i++) {
            buff[i] += buff[i-1];
        }
    }

    /* Scatter the results to the other processes*/
    ret = sh->comm->c_coll.coll_scatter ( buff, sendcnt, OMPI_OFFSET_DATATYPE,
					 &offsetBuff, recvcnt, OMPI_OFFSET_DATATYPE, 0,
					 sh->comm, sh->comm->c_coll.coll_scatter_module );
    if ( OMPI_SUCCESS != ret ) {
	goto exit;
    }

    /*Each process now has its own individual offset*/
    offset = offsetBuff - sendBuff;

    if ( mca_sharedfp_lockedfile_verbose ) {
	printf("sharedfp_lockedfile_write_ordered: Offset returned is %lld\n",offset);
    }

    /* write to the file */
    ret = ompio_io_ompio_file_write_at_all(sh->sharedfh,offset,buf,count,datatype,status);

exit:
    if ( NULL != buff ) {
	free ( buff);
    }

    return ret;
}
Ejemplo n.º 6
0
int mca_sharedfp_lockedfile_read_ordered (ompio_file_t *fh,
                                           void *buf,
                                           int count,
                                           struct ompi_datatype_t *datatype,
                                           ompi_status_public_t *status)
{
    int ret = OMPI_SUCCESS;
    OMPI_MPI_OFFSET_TYPE offset = 0;
    long sendBuff = 0;
    long *buff=NULL;
    long offsetBuff;
    OMPI_MPI_OFFSET_TYPE offsetReceived = 0;
    long bytesRequested = 0;
    int recvcnt = 1, sendcnt = 1;
    size_t numofBytes;
    int rank, size, i;
    struct mca_sharedfp_base_data_t *sh = NULL;

    if ( fh->f_sharedfp_data == NULL){
        opal_output(ompi_sharedfp_base_framework.framework_output,
                    "sharedfp_lockedfile_read_ordered: module not initialized\n");
        return OMPI_ERROR;
    }

    /*Retrieve the new communicator*/
    sh = fh->f_sharedfp_data;

    /* Calculate the number of bytes to read*/
    opal_datatype_type_size ( &datatype->super, &numofBytes );
    sendBuff = count * numofBytes;

    /* Get the ranks in the communicator */
    rank = ompi_comm_rank ( fh->f_comm );
    size = ompi_comm_size ( fh->f_comm );

    if ( 0 == rank ) {
        buff = (long*)malloc(sizeof(long) * size);
        if ( NULL == buff )
            return OMPI_ERR_OUT_OF_RESOURCE;
    }

    ret = fh->f_comm->c_coll->coll_gather ( &sendBuff, sendcnt, OMPI_OFFSET_DATATYPE,
                                            buff, recvcnt, OMPI_OFFSET_DATATYPE, 0,
                                            fh->f_comm, fh->f_comm->c_coll->coll_gather_module );
    if ( OMPI_SUCCESS != ret ) {
	goto exit;
    }

    /* All the counts are present now in the recvBuff.
       The size of recvBuff is sizeof_newComm
     */
    if ( 0 == rank ) {
        for (i = 0; i < size ; i ++)  {
            bytesRequested += buff[i];
	    if ( mca_sharedfp_lockedfile_verbose ) {
                opal_output(ompi_sharedfp_base_framework.framework_output,
                            "sharedfp_lockedfile_read_ordered: Bytes requested are %ld\n",bytesRequested);
	    }
        }

        /*Request the offset to read bytesRequested bytes
          only the root process needs to do the request,
          since the root process will then tell the other
          processes at what offset they should read their
          share of the data.
         */
        ret = mca_sharedfp_lockedfile_request_position(sh,bytesRequested,&offsetReceived);
        if( OMPI_SUCCESS != ret ){
            goto exit;
        }
	if ( mca_sharedfp_lockedfile_verbose ) {
            opal_output(ompi_sharedfp_base_framework.framework_output,
                        "sharedfp_lockedfile_read_ordered: Offset received is %lld\n",offsetReceived);
	}
        buff[0] += offsetReceived;

        for (i = 1 ; i < size; i++) {
            buff[i] += buff[i-1];
        }
    }

    /* Scatter the results to the other processes*/
    ret = fh->f_comm->c_coll->coll_scatter ( buff, sendcnt, OMPI_OFFSET_DATATYPE,
                                             &offsetBuff, recvcnt, OMPI_OFFSET_DATATYPE, 0,
                                             fh->f_comm, fh->f_comm->c_coll->coll_scatter_module );

    /*Each process now has its own individual offset in recvBUFF*/
    offset = offsetBuff - sendBuff;
    offset /= fh->f_etype_size;

    if ( mca_sharedfp_lockedfile_verbose ) {
        opal_output(ompi_sharedfp_base_framework.framework_output,
                    "sharedfp_lockedfile_read_ordered: Offset returned is %lld\n",offset);
    }

    /* read to the file */
    ret = mca_common_ompio_file_read_at_all(fh,offset,buf,count,datatype,status);

exit:
    if ( NULL != buff ) {
	free ( buff );
    }

    return ret;
}