TEST_F(DataFieldOpenMPStorageUnittest, ExternalStorage) { // setup external memory IJKSize paddedSize = storage3D_.paddedSize(); int size = paddedSize.iSize() * paddedSize.jSize() * paddedSize.kSize(); std::vector<DataType3D> memory1, memory2; memory1.resize(size, 11.0); memory2.resize(size, 22.0); // define external storage ExternalStorage<DataType3D> externalStorage1, externalStorage2; externalStorage1.Init(&memory1[0], storage3D_.paddedSize()); externalStorage2.Init(&memory2[0], storage3D_.paddedSize()); // storage with external storage DataFieldOpenMPStorage<DataType3D, IJKStorageFormat> storage; storage.Init(externalStorage1, calculationDomain_, kBoundary_); // check the memory is ok ASSERT_EQ(&memory1[0], storage.pStorageBase()); ASSERT_EQ(11.0, *storage.pStorageBase()); // set the second external storage storage.SetExternalStorage(externalStorage2); // check the memory is ok ASSERT_EQ(&memory2[0], storage.pStorageBase()); ASSERT_EQ(22.0, *storage.pStorageBase()); }
void randomStorageInit(TStorage& storage) { IJKSize allocSize = storage.allocatedSize(); typename TStorage::StorageIteratorType iter = storage.originIterator(); iter.Advance( -storage.originOffset().iIndex(), -storage.originOffset().jIndex(), -storage.originOffset().kIndex() ); for(int i = 0; i < allocSize.iSize(); ++i) { for(int j = 0; j < allocSize.jSize(); ++j) { for(int k = 0; k < allocSize.kSize(); ++k) { iter.At(i,j,k) = static_cast<typename TStorage::ValueType>(rand()); } } } }