void openH5File()
    {

        if (dataCollector == NULL)
        {
            DataSpace<simDim> mpi_pos;
            DataSpace<simDim> mpi_size;

            Dimensions splashMpiPos;
            Dimensions splashMpiSize;

            GridController<simDim> &gc = Environment<simDim>::get().GridController();

            mpi_pos = gc.getPosition();
            mpi_size = gc.getGpuNodes();

            splashMpiPos.set(0, 0, 0);
            splashMpiSize.set(1, 1, 1);

            for (uint32_t i = 0; i < simDim; ++i)
            {
                splashMpiPos[i] = mpi_pos[i];
                splashMpiSize[i] = mpi_size[i];
            }


            const uint32_t maxOpenFilesPerNode = 1;
            dataCollector = new ParallelDomainCollector(
                                                        gc.getCommunicator().getMPIComm(),
                                                        gc.getCommunicator().getMPIInfo(),
                                                        splashMpiSize,
                                                        maxOpenFilesPerNode);
            // set attributes for datacollector files
            DataCollector::FileCreationAttr h5_attr;
            h5_attr.enableCompression = false;
            h5_attr.fileAccType = DataCollector::FAT_CREATE;
            h5_attr.mpiPosition.set(splashMpiPos);
            h5_attr.mpiSize.set(splashMpiSize);
        }


        // open datacollector
        try
        {
            std::string filename = (foldername + std::string("/makroParticlePerSupercell"));
            log<picLog::INPUT_OUTPUT > ("HDF5 open DataCollector with file: %1%") %
                filename;
            dataCollector->open(filename.c_str(), h5_attr);
        }
        catch (DCException e)
        {
            std::cerr << e.what() << std::endl;
            throw std::runtime_error("Failed to open datacollector");
        }
    }
示例#2
0
int detectFileMPISize(Options& options, Dimensions &fileMPISizeDim)
{
    int result = RESULT_OK;

    DataCollector *dc = NULL;
#if (SPLASH_SUPPORTED_PARALLEL==1)
    if (options.parallelFile)
        dc = new ParallelDataCollector(MPI_COMM_WORLD, MPI_INFO_NULL,
            Dimensions(options.mpiSize, 1, 1), 1);
    else
#endif
        dc = new SerialDataCollector(1);

    DataCollector::FileCreationAttr fileCAttr;
    DataCollector::initFileCreationAttr(fileCAttr);
    fileCAttr.fileAccType = DataCollector::FAT_READ;

    try
    {
        dc->open(options.filename.c_str(), fileCAttr);
        dc->getMPISize(fileMPISizeDim);
        dc->close();
    } catch (DCException e)
    {
        std::cerr << "[0] Detecting file MPI size failed!" << std::endl <<
                e.what() << std::endl;
        fileMPISizeDim.set(0, 0, 0);
        result = RESULT_ERROR;
    }

    delete dc;
    dc = NULL;

    return result;
}
示例#3
0
    void DCDataSet::read(Dimensions dstBuffer,
            Dimensions dstOffset,
            Dimensions srcSize,
            Dimensions srcOffset,
            Dimensions& sizeRead,
            uint32_t& srcNDims,
            void* dst)
    throw (DCException)
    {
        log_msg(2, "DCDataSet::read (%s)", name.c_str());

        if (!opened)
            throw DCException(getExceptionString("read: Dataset has not been opened/created"));

        if (dstBuffer.getScalarSize() == 0)
            dstBuffer.set(srcSize);

        // dst buffer is allowed to be NULL
        // in this case, only the size of the dataset is returned
        // if the dataset is empty, return just its size as there is nothing to read
        if ((dst != NULL) && (getNDims() > 0))
        {
            log_msg(3,
                    " ndims = %llu\n"
                    " logical_size = %s\n"
                    " physical_size = %s\n"
                    " dstBuffer = %s\n"
                    " dstOffset = %s\n"
                    " srcSize = %s\n"
                    " srcOffset = %s\n",
                    (long long unsigned) ndims,
                    getLogicalSize().toString().c_str(),
                    getPhysicalSize().toString().c_str(),
                    dstBuffer.toString().c_str(),
                    dstOffset.toString().c_str(),
                    srcSize.toString().c_str(),
                    srcOffset.toString().c_str());

            dstBuffer.swapDims(ndims);
            dstOffset.swapDims(ndims);
            srcSize.swapDims(ndims);
            srcOffset.swapDims(ndims);

            hid_t dst_dataspace = H5Screate_simple(ndims, dstBuffer.getPointer(), NULL);
            if (dst_dataspace < 0)
                throw DCException(getExceptionString("read: Failed to create target dataspace"));

            if (H5Sselect_hyperslab(dst_dataspace, H5S_SELECT_SET, dstOffset.getPointer(), NULL,
                    srcSize.getPointer(), NULL) < 0 ||
                    H5Sselect_valid(dst_dataspace) <= 0)
                throw DCException(getExceptionString("read: Target dataspace hyperslab selection is not valid!"));

            if (H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, srcOffset.getPointer(), NULL,
                    srcSize.getPointer(), NULL) < 0 ||
                    H5Sselect_valid(dataspace) <= 0)
                throw DCException(getExceptionString("read: Source dataspace hyperslab selection is not valid!"));

            if (srcSize.getScalarSize() == 0)
                H5Sselect_none(dataspace);
            
            if (H5Dread(dataset, this->datatype, dst_dataspace, dataspace, dsetReadProperties, dst) < 0)
                throw DCException(getExceptionString("read: Failed to read dataset"));

            H5Sclose(dst_dataspace);

            srcSize.swapDims(ndims);
        }

        // swap dimensions if necessary
        sizeRead.set(srcSize);
        srcNDims = this->ndims;

        log_msg(3, " returns ndims = %llu", (long long unsigned) ndims);
        log_msg(3, " returns sizeRead = %s", sizeRead.toString().c_str());
    }