当前位置: 首页>>代码示例>>C++>>正文


C++ DataCollector::read方法代码示例

本文整理汇总了C++中DataCollector::read方法的典型用法代码示例。如果您正苦于以下问题:C++ DataCollector::read方法的具体用法?C++ DataCollector::read怎么用?C++ DataCollector::read使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataCollector的用法示例。


在下文中一共展示了DataCollector::read方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: subtestWriteRead

bool Parallel_SimpleDataTest::subtestWriteRead(int32_t iteration,
        int currentMpiRank,
        const Dimensions mpiSize, const Dimensions mpiPos,
        const Dimensions gridSize, uint32_t dimensions, MPI_Comm mpiComm)
{
    bool results_correct = true;
    DataCollector::FileCreationAttr fileCAttr;
    std::set<std::string> datasetNames;

#if defined TESTS_DEBUG
    if (currentMpiRank == 0)
        std::cout << "iteration: " << iteration << std::endl;
#endif

    size_t bufferSize = gridSize[0] * gridSize[1] * gridSize[2];

    // write data to file
    DataCollector::initFileCreationAttr(fileCAttr);
    fileCAttr.fileAccType = DataCollector::FAT_CREATE;
    fileCAttr.enableCompression = false;
    parallelDataCollector->open(HDF5_FILE, fileCAttr);

    int *dataWrite = new int[bufferSize];

    for (uint32_t i = 0; i < bufferSize; i++)
        dataWrite[i] = currentMpiRank + 1;

    parallelDataCollector->write(iteration, ctInt, dimensions, gridSize,
            "deep/folder/data", dataWrite);
    datasetNames.insert("deep/folder/data");
    parallelDataCollector->write(iteration, ctInt, dimensions, gridSize,
            "deep/folder/data2", dataWrite);
    datasetNames.insert("deep/folder/data2");
    parallelDataCollector->write(iteration, ctInt, dimensions, gridSize,
            "another_dataset", dataWrite);
    datasetNames.insert("another_dataset");
    parallelDataCollector->close();

    delete[] dataWrite;
    dataWrite = NULL;

    MPI_CHECK(MPI_Barrier(mpiComm));

    // test written data using various mechanisms
    fileCAttr.fileAccType = DataCollector::FAT_READ;
    // need a complete filename here
    std::stringstream filename_stream;
    filename_stream << HDF5_FILE << "_" << iteration << ".h5";

    Dimensions size_read;
    Dimensions full_grid_size = gridSize * mpiSize;
    int *data_read = new int[full_grid_size.getScalarSize()];
    memset(data_read, 0, sizeof (int) * full_grid_size.getScalarSize());

    // test using SerialDataCollector
    if (currentMpiRank == 0)
    {
        DataCollector *dataCollector = new SerialDataCollector(1);
        dataCollector->open(filename_stream.str().c_str(), fileCAttr);

        dataCollector->read(iteration, "deep/folder/data", size_read, data_read);
        dataCollector->close();
        delete dataCollector;

        CPPUNIT_ASSERT(size_read == full_grid_size);
        CPPUNIT_ASSERT(testData(mpiSize, gridSize, data_read));
    }

    MPI_CHECK(MPI_Barrier(mpiComm));

    // test using full read per process
    memset(data_read, 0, sizeof (int) * full_grid_size.getScalarSize());
    ParallelDataCollector *readCollector = new ParallelDataCollector(mpiComm,
            MPI_INFO_NULL, mpiSize, 1);

    readCollector->open(HDF5_FILE, fileCAttr);
    
    /* test entries listing */
    {
        DataCollector::DCEntry *entries = NULL;
        size_t numEntries = 0;

        int32_t *ids = NULL;
        size_t numIDs = 0;
        readCollector->getEntryIDs(NULL, &numIDs);
        /* there might be old files, but we are at least at the current iteration */
        CPPUNIT_ASSERT(numIDs >= iteration + 1);
        ids = new int32_t[numIDs];
        readCollector->getEntryIDs(ids, NULL);

        readCollector->getEntriesForID(iteration, NULL, &numEntries);
        CPPUNIT_ASSERT(numEntries == 3);
        entries = new DataCollector::DCEntry[numEntries];
        readCollector->getEntriesForID(iteration, entries, NULL);

        CPPUNIT_ASSERT(numEntries == datasetNames.size());
        for (uint32_t i = 0; i < numEntries; ++i)
        {
            /* test that listed datasets match expected dataset names*/
            CPPUNIT_ASSERT(datasetNames.find(entries[i].name) != datasetNames.end());
//.........这里部分代码省略.........
开发者ID:slizzered,项目名称:libSplash,代码行数:101,代码来源:Parallel_SimpleDataTest.cpp

示例2: subtestFill

bool Parallel_SimpleDataTest::subtestFill(int32_t iteration,
        int currentMpiRank,
        const Dimensions mpiSize, const Dimensions mpiPos,
        uint32_t elements, MPI_Comm mpiComm)
{
    bool results_correct = true;
    DataCollector::FileCreationAttr fileCAttr;

#if defined TESTS_DEBUG
    if (currentMpiRank == 0)
        std::cout << "iteration: " << iteration << std::endl;
#endif

    // write data to file
    DataCollector::initFileCreationAttr(fileCAttr);
    fileCAttr.fileAccType = DataCollector::FAT_CREATE;
    fileCAttr.enableCompression = false;
    parallelDataCollector->open(HDF5_FILE, fileCAttr);

    int dataWrite = currentMpiRank + 1;
    uint32_t num_elements = (currentMpiRank + 1) * elements;
    Dimensions grid_size(num_elements, 1, 1);

#if defined TESTS_DEBUG
    std::cout << "[" << currentMpiRank << "] " << num_elements << " elements" << std::endl;
#endif

    Dimensions globalOffset, globalSize;
    parallelDataCollector->reserve(iteration, grid_size,
            &globalSize, &globalOffset, 1, ctInt, "reserved/reserved_data");

    int attrVal = currentMpiRank;
    parallelDataCollector->writeAttribute(iteration, ctInt, "reserved/reserved_data",
            "reserved_attr", &attrVal);

    uint32_t elements_written = 0;
    uint32_t global_max_elements = mpiSize.getScalarSize() * elements;
    for (size_t i = 0; i < global_max_elements; ++i)
    {
        Dimensions write_size(1, 1, 1);
        if (i >= num_elements)
            write_size.set(0, 0, 0);

        Dimensions write_offset(globalOffset + Dimensions(elements_written, 0, 0));

        parallelDataCollector->append(iteration, write_size, 1,
                write_offset, "reserved/reserved_data", &dataWrite);

        if (i < num_elements)
            elements_written++;
    }

    MPI_CHECK(MPI_Barrier(mpiComm));

    attrVal = -1;
    parallelDataCollector->readAttribute(iteration, "reserved/reserved_data",
            "reserved_attr", &attrVal, NULL);

    CPPUNIT_ASSERT(attrVal == currentMpiRank);

    parallelDataCollector->close();

    MPI_CHECK(MPI_Barrier(mpiComm));

    // test written data using various mechanisms
    fileCAttr.fileAccType = DataCollector::FAT_READ;
    // need a complete filename here
    std::stringstream filename_stream;
    filename_stream << HDF5_FILE << "_" << iteration << ".h5";

    Dimensions size_read;
    Dimensions full_grid_size = globalSize;


    // test using SerialDataCollector
    if (currentMpiRank == 0)
    {
        int *data_read = new int[full_grid_size.getScalarSize()];
        memset(data_read, 0, sizeof (int) * full_grid_size.getScalarSize());

        DataCollector *dataCollector = new SerialDataCollector(1);
        dataCollector->open(filename_stream.str().c_str(), fileCAttr);

        dataCollector->read(iteration, "reserved/reserved_data",
                size_read, data_read);
        dataCollector->close();
        delete dataCollector;

        CPPUNIT_ASSERT(size_read == full_grid_size);
        CPPUNIT_ASSERT(size_read[1] == size_read[2] == 1);

        int this_rank = 0;
        uint32_t elements_this_rank = num_elements;
        for (uint32_t i = 0; i < size_read.getScalarSize(); ++i)
        {
            if (i == elements_this_rank)
            {
                this_rank++;
                elements_this_rank += num_elements * (this_rank + 1);
            }
//.........这里部分代码省略.........
开发者ID:slizzered,项目名称:libSplash,代码行数:101,代码来源:Parallel_SimpleDataTest.cpp

示例3: runTest

void FilenameTest::runTest(const char* filename, const char* fullFilename)
{
    CPPUNIT_ASSERT(!fileExists(fullFilename));

    DataCollector::FileCreationAttr attr;
    DataCollector::initFileCreationAttr(attr);
    attr.fileAccType = DataCollector::FAT_WRITE;

    // write first dataset to file (create file)
    dataCollector->open(filename, attr);
    int data1 = rand();

    dataCollector->write(1, ctInt, 1, Selection(Dimensions(1, 1, 1)), "data", &data1);
    dataCollector->close();
    // Now file must exist
    CPPUNIT_ASSERT(fileExists(fullFilename));

    // write second dataset to file (write to existing file of same name
    dataCollector->open(filename, attr);
    int data2 = rand();

    dataCollector->write(2, ctInt, 1, Selection(Dimensions(1, 1, 1)), "data", &data2);
    dataCollector->close();


    // read data from file
    attr.fileAccType = DataCollector::FAT_READ;
    Dimensions data_size;

    int data = -1;
    dataCollector->open(filename, attr);

    CPPUNIT_ASSERT(dataCollector->getMaxID() == 2);

    dataCollector->read(1, "data", data_size, &data);

    CPPUNIT_ASSERT(data_size.getScalarSize() == 1);
    CPPUNIT_ASSERT(data == data1);

    dataCollector->read(2, "data", data_size, &data);

    CPPUNIT_ASSERT(data_size.getScalarSize() == 1);
    CPPUNIT_ASSERT(data == data2);

    dataCollector->close();

    // erase file
    attr.fileAccType = DataCollector::FAT_CREATE;
    dataCollector->open(filename, attr);

    CPPUNIT_ASSERT_THROW(dataCollector->read(1, "data", data_size, &data), DCException);
    int data3 = rand();
    dataCollector->write(2, ctInt, 1, Selection(Dimensions(1, 1, 1)), "data", &data3);
    dataCollector->close();

    // Read from created file
    attr.fileAccType = DataCollector::FAT_READ;

    data = -1;
    dataCollector->open(filename, attr);

    CPPUNIT_ASSERT(dataCollector->getMaxID() == 2);

    dataCollector->read(2, "data", data_size, &data);

    CPPUNIT_ASSERT(data_size.getScalarSize() == 1);
    CPPUNIT_ASSERT(data == data3);
    dataCollector->close();
}
开发者ID:ComputationalRadiationPhysics,项目名称:libSplash,代码行数:69,代码来源:FilenameTest.cpp


注:本文中的DataCollector::read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。