本文整理汇总了C++中DataContainer::getElement方法的典型用法代码示例。如果您正苦于以下问题:C++ DataContainer::getElement方法的具体用法?C++ DataContainer::getElement怎么用?C++ DataContainer::getElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataContainer
的用法示例。
在下文中一共展示了DataContainer::getElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
dc.getMPISize(file_mpi_size);
std::cout << mpi_rank << ": total file MPI size = " <<
file_mpi_size.toString() << std::endl;
for (int i = 0; i < 3; ++i)
f_mpi_size[i] = file_mpi_size[i];
dc.close();
}
MPI_Bcast(f_mpi_size, 3, MPI_UNSIGNED_LONG_LONG, 0, MPI_COMM_WORLD);
file_mpi_size.set(f_mpi_size[0], f_mpi_size[1], f_mpi_size[2]);
// get number of files for this MPI process
filesToProcesses(mpi_size, mpi_rank, file_mpi_size.getScalarSize(),
files_start, files_end);
for (int f = files_start; f <= files_end; ++f)
{
// get file MPI pos for this file index
indexToPos(f, file_mpi_size, fAttr.mpiPosition);
std::cout << mpi_rank << ": opening position " <<
fAttr.mpiPosition.toString() << std::endl;
dc.open(filename.c_str(), fAttr);
// get number of entries
int32_t *ids = NULL;
size_t num_ids = 0;
dc.getEntryIDs(NULL, &num_ids);
if (num_ids == 0)
{
dc.close();
continue;
} else
{
ids = new int32_t[num_ids];
dc.getEntryIDs(ids, &num_ids);
}
// get entries for 1. id (iteration)
DataCollector::DCEntry *entries = NULL;
size_t num_entries = 0;
dc.getEntriesForID(ids[0], NULL, &num_entries);
if (num_entries == 0)
{
delete[] ids;
dc.close();
continue;
} else
{
entries = new DataCollector::DCEntry[num_entries];
dc.getEntriesForID(ids[0], entries, &num_entries);
}
// read 1. entry
DataCollector::DCEntry first_entry = entries[0];
std::cout << " " << mpi_rank << ": reading entry " << first_entry.name << std::endl;
// read complete domain
Domain domain = dc.getGlobalDomain(ids[0], first_entry.name.c_str());
DomainCollector::DomDataClass dataClass = DomainCollector::UndefinedType;
DataContainer* container = dc.readDomain(ids[0], first_entry.name.c_str(),
domain, &dataClass, false);
// access all elements, no matter how many subdomains
for (size_t i = 0; i < container->getNumElements(); ++i)
{
void *element = container->getElement(i);
// do anything with this element
// ...
}
// POLY data might be distributed over multiple subdomains
for (size_t d = 0; d < container->getNumSubdomains(); ++d)
{
DomainData* subdomain = container->getIndex(d);
Dimensions size = subdomain->getSize();
std::cout << " " << mpi_rank << ": subdomain " << d << " has size " <<
size.toString() << std::endl;
// access the underlying buffer of a subdomain
void *elements = subdomain->getData();
}
// don't forget to delete the container allocated by DomainCollector
delete container;
delete[] entries;
delete[] ids;
dc.close();
}
MPI_Finalize();
return 0;
}
示例2: subTestGridDomains
void DomainsTest::subTestGridDomains(const Dimensions mpiSize, const Dimensions gridSize,
uint32_t rank, uint32_t iteration)
{
int max_rank = 1;
for (int i = 0; i < rank; i++)
max_rank *= mpiSize[i];
int mpi_rank = totalMpiRank;
if (mpi_rank < max_rank)
{
// write data
int *data_write = new int[gridSize.getDimSize()];
// initialize data for writing with mpi index (mpi rank)
Dimensions mpi_position(mpi_rank % mpiSize[0],
(mpi_rank / mpiSize[0]) % mpiSize[1],
(mpi_rank / mpiSize[0]) / mpiSize[1]);
for (size_t i = 0; i < gridSize.getDimSize(); ++i)
data_write[i] = mpi_rank;
DataCollector::FileCreationAttr fattr;
fattr.fileAccType = DataCollector::FAT_CREATE;
fattr.mpiSize.set(mpiSize);
fattr.mpiPosition.set(mpi_position);
dataCollector->open(hdf5_file_grid, fattr);
Dimensions domain_offset = mpi_position * gridSize;
#if defined TESTS_DEBUG
std::cout << "writing..." << std::endl;
std::cout << "mpi_position = " << mpi_position.toString() << std::endl;
std::cout << "domain_offset = " << domain_offset.toString() << std::endl;
#endif
dataCollector->writeDomain(iteration, ctInt, rank, gridSize, "grid_data",
domain_offset, gridSize, DomainCollector::GridType, data_write);
dataCollector->close();
int *data_read = new int[gridSize.getDimSize()];
fattr.fileAccType = DataCollector::FAT_READ;
dataCollector->open(hdf5_file_grid, fattr);
DomainCollector::DomDataClass data_class = DomainCollector::UndefinedType;
DataContainer *container = dataCollector->readDomain(iteration, "grid_data",
domain_offset, gridSize, &data_class, false);
dataCollector->close();
CPPUNIT_ASSERT(container != NULL);
CPPUNIT_ASSERT(container->getNumSubdomains() == 1);
CPPUNIT_ASSERT(container->getNumElements() == gridSize.getDimSize());
for (size_t i = 0; i < gridSize.getDimSize(); ++i)
CPPUNIT_ASSERT(*((int*)(container->getElement(i))) == mpi_rank);
delete container;
delete[] data_read;
delete[] data_write;
data_write = NULL;
}
MPI_Barrier(MPI_COMM_WORLD);
if (mpi_rank == 0)
{
// now read and test domain subdomains
DataCollector::FileCreationAttr fattr;
fattr.fileAccType = DataCollector::FAT_READ_MERGED;
fattr.mpiSize = mpiSize;
dataCollector->open(hdf5_file_grid, fattr);
size_t global_domain_elements = dataCollector->getTotalElements(iteration, "grid_data");
Dimensions global_grid_size = mpiSize * gridSize;
#if defined TESTS_DEBUG
std::cout << "global_domain_elements = " << global_domain_elements << std::endl;
std::cout << "global_grid_size = " << global_grid_size.toString() << std::endl;
#endif
CPPUNIT_ASSERT(global_domain_elements == global_grid_size.getDimSize());
// test different domain offsets
for (uint32_t i = 0; i < 5; ++i)
{
Dimensions offset(rand() % global_grid_size[0],
rand() % global_grid_size[1],
rand() % global_grid_size[2]);
Dimensions partition_size = global_grid_size - offset;
#if defined TESTS_DEBUG
std::cout << "offset = " << offset.toString() << std::endl;
std::cout << "partition_size = " << partition_size.toString() << std::endl;
#endif
//.........这里部分代码省略.........
示例3: main
int main(int argc, char **argv)
{
if (argc < 2)
{
std::cout << "Usage: " << argv[0] << " <libsplash-file-base>" << std::endl;
return -1;
}
// libSplash filename
std::string filename;
filename.assign(argv[1]);
// create DomainCollector
DomainCollector dc(100);
DataCollector::FileCreationAttr fAttr;
DataCollector::initFileCreationAttr(fAttr);
fAttr.fileAccType = DataCollector::FAT_READ_MERGED;
dc.open(filename.c_str(), fAttr);
// get number of entries
int32_t *ids = NULL;
size_t num_ids = 0;
dc.getEntryIDs(NULL, &num_ids);
if (num_ids == 0)
{
dc.close();
return 1;
} else
{
ids = new int32_t[num_ids];
dc.getEntryIDs(ids, &num_ids);
}
// get entries for 1. id (iteration)
std::cout << "reading from iteration " << ids[0] << std::endl;
DataCollector::DCEntry *entries = NULL;
size_t num_entries = 0;
dc.getEntriesForID(ids[0], NULL, &num_entries);
if (num_entries == 0)
{
delete[] ids;
dc.close();
return 1;
} else
{
entries = new DataCollector::DCEntry[num_entries];
dc.getEntriesForID(ids[0], entries, &num_entries);
}
// read 1. entry from this iteration
DataCollector::DCEntry first_entry = entries[0];
std::cout << "reading entry " << first_entry.name << std::endl;
// read complete domain
Domain domain = dc.getGlobalDomain(ids[0], first_entry.name.c_str());
DomainCollector::DomDataClass dataClass = DomainCollector::UndefinedType;
DataContainer* container = dc.readDomain(ids[0], first_entry.name.c_str(),
domain, &dataClass, false);
// access all elements, no matter how many subdomains
for (size_t i = 0; i < container->getNumElements(); ++i)
{
void *element = container->getElement(i);
// do anything with this element
// ...
}
// POLY data might be distributed over multiple subdomains
for (size_t d = 0; d < container->getNumSubdomains(); ++d)
{
DomainData* subdomain = container->getIndex(d);
Dimensions size = subdomain->getSize();
std::cout << "subdomain " << d << " has size " << size.toString() << std::endl;
// access the underlying buffer of a subdomain
void *elements = subdomain->getData();
}
// don't forget to delete the container allocated by DomainCollector
delete container;
delete[] entries;
delete[] ids;
dc.close();
return 0;
}