/// strided insertion into nxn array (insert going down columns first into row //major array void stridedInsert() { MDArray *array; Btree::MSplitter<Datum_t> leafSp; Btree::MSplitter<PID_t> intSp; if (type == DMA) array = new MDArray(dim, type, row, fileName); else if (type == BTREE) array = new MDArray(dim, row, &leafSp, &intSp, fileName); PagedStorageContainer::resetPerfCounts(); gettimeofday(&tim, NULL); t1 = tim.tv_sec + tim.tv_usec/1000000.0; for (i64 j = 0; j < n; j++) { for (i64 i = 0; i < n; i++) { coord = MDCoord(2, i, j); array->put(coord, 12345); } } delete array; gettimeofday(&tim, NULL); t2 = tim.tv_sec + tim.tv_usec/1000000.0; readCount += PagedStorageContainer::readCount; writeCount += PagedStorageContainer::writeCount; accessTime += PagedStorageContainer::accessTime; execTime += (t2 - t1); fprintf(pFile, "%-14s %8i %8i %11.3f %11.3f\n", "stride insert", PagedStorageContainer::readCount, PagedStorageContainer::writeCount, PagedStorageContainer::accessTime, t2-t1); }
int main(int argc, char **argv) { const int required = 2; char fileName[100] = "/riot/mb"; unsigned int tm; if (argc >= required+1) tm = atoi(argv[required]); else tm = time(NULL); srand(tm); cerr<<"seed = "<<tm<<endl; if (argc < required) { cerr<<"Usage: "<<argv[0]<<"<splitter type>"<<endl <<"splitter type: M,A,D"<<endl; return 0; } char splitterType = argv[1][0]; i64 arraydims[] = {20000,20000}; i64 blockdims[] = {31,31}; u8 orders[] = {0, 1}; Linearization<2> *lin = new BlockBased<2>(arraydims, blockdims, orders, orders); MDArray<2> *array; StorageParam sp; sp.fileName = fileName; sp.intSp = 'M'; sp.leafSp = splitterType; if (splitterType == 'D') { // dma sp.type = DMA; } else if (splitterType == 'M') { sp.type = BTREE; sp.useDenseLeaf = false; } else if (splitterType == 'A') { sp.type = BTREE; sp.useDenseLeaf = true; } else { cerr<<"wrong splitter type"<<endl; exit(1); } array = new MDArray<2>(&sp, MDCoord<2>(arraydims), lin); for (i64 i=0; i<20000; ++i) { for (i64 j=0; j<20000; ++j) { MDCoord<2> c(i,j); array->put(c, 1.0); } } delete lin; delete array; }
/// random insertion into nxn array, all indices are written to once void randomInsert() { i64 k[n*n]; int stride = 5; int num = n*n/stride; for (int i = 0; i < num; i++) { k[i] = i*stride; } MDArray *array; Btree::MSplitter<Datum_t> leafSp; Btree::MSplitter<PID_t> intSp; if (type == DMA) array = new MDArray(dim, type, row, fileName); else if (type == BTREE) array = new MDArray(dim, row, &leafSp, &intSp, fileName); PagedStorageContainer::resetPerfCounts(); permute(k, num); i64 *i = k; gettimeofday(&tim, NULL); t1 = tim.tv_sec + tim.tv_usec/1000000.0; while (i < k + num) { coord = MDCoord(2, *i/n, *i%n); array->put(coord, 12345); i++; } delete array; gettimeofday(&tim, NULL); t2 = tim.tv_sec + tim.tv_usec/1000000.0; readCount += PagedStorageContainer::readCount; writeCount += PagedStorageContainer::writeCount; accessTime += PagedStorageContainer::accessTime; execTime += (t2 - t1); fprintf(pFile, "sparsity %4.3f\n", 1.0/stride); fprintf(pFile, "%-14s %8i %8i %11.3f %11.3f\n", "rand insert", PagedStorageContainer::readCount, PagedStorageContainer::writeCount, PagedStorageContainer::accessTime, t2-t1); }
TEST(DISABLED_MDArray, Create) { i64 rows = 500L; i64 cols = 500L; MDCoord dim(2, rows, cols); StorageType type = DMA; Linearization *row = new RowMajor(dim); Linearization *col = new ColMajor(dim); i64 blockDims[] = {100L, 100L}; u8 blockOrders[] = {0, 1}; u8 microOrders[] = {0, 1}; permute(blockOrders, dim.nDim); permute(microOrders, dim.nDim); Linearization *block = new BlockBased(dim.nDim, dim.coords, blockDims, blockOrders, microOrders); const char *fileName = "test.bin"; MDArray *array = new MDArray(dim, type, row, fileName); MDCoord coord1 = MDCoord(2, 120, 19); ASSERT_TRUE(AC_OK == array->put(coord1, 12345)); Datum_t datum; ASSERT_TRUE(AC_OK == array->get(coord1, datum)); ASSERT_DOUBLE_EQ(12345, datum); MDCoord coord2 = MDCoord(2, 400, 133); ASSERT_TRUE(AC_OK == array->put(coord2, 12.345)); MDCoord coord3 = MDCoord(2, 256, 19); ASSERT_TRUE(AC_OK == array->put(coord3, 1000)); ASSERT_TRUE(AC_OK == array->get(coord2, datum)); ASSERT_DOUBLE_EQ(12.345, datum); ASSERT_TRUE(AC_OK == array->get(coord3, datum)); ASSERT_DOUBLE_EQ(1000, datum); // dense itor, write MDIterator *it = array->createIterator(Dense, row); MDCoord coord; int i = 0; while (it->moveNext()) { it->put(i); i++; } ASSERT_EQ(rows*cols, i); delete it; // block itor, read it = array->createIterator(Dense, block); i = 0; while(it->moveNext()) { it->get(coord, datum); ASSERT_DOUBLE_EQ(row->linearize(coord), datum); i++; } ASSERT_EQ(rows*cols, i); delete it; /* // natural itor, read it = array->createNaturalIterator(Dense); i = 1; while(it->moveNext()) { it->get(coord, datum); ASSERT_EQ(i, row->linearize(coord)); ASSERT_EQ(i, datum); i++; } ASSERT_EQ(rows*cols, i); delete it; */ delete row; delete col; delete block; delete array; }