void DirectedGraph::createGraph(Graph::edgeType &edgeSet) { Graph::const_edgeItr minItr; DirectedEdge *e; //g.printGraph(); dirEdgeList.clear(); STXXL_MSG("Check"); for(minItr = edgeSet.begin(); minItr != edgeSet.end(); minItr++) { e = new DirectedEdge(minItr->getSrc(),minItr->getDst(),minItr->getOrigSrc(),minItr->getOrigDst(),minItr->getEdgeWt()); dirEdgeList.push_back(*e); delete e; } noEdges=dirEdgeList.size(); edgeSet.flush(); edgeSet.clear(); stxxl::sort(dirEdgeList.begin(),dirEdgeList.end(),dirCmpSrc(),INTERNAL_MEMORY_FOR_SORTING); STXXL_MSG("Directed graph created"); //printGraph(); }
int main() { // template parameter <data_type, externality, behaviour, blocks_per_page, block_size, internal_stack_type, migrating_critical_size, allocation_strategy, size_type> typedef stxxl::STACK_GENERATOR<int, stxxl::external, stxxl::grow_shrink, 4, 2*1024*1024>::result simple_stack; // create stack instance simple_stack a_stack; stxxl::random_number<> random; stxxl::uint64 number_of_elements = 16 * 1024 * 1024; // routine: 1) push random values on stack and 2) pop all except the lowest value and start again for (int k = 0; k < 5; k++) { STXXL_MSG("push..."); for (stxxl::uint64 i = 0; i < number_of_elements; i++) { a_stack.push(random(123456789)); } STXXL_MSG("pop..."); for (stxxl::uint64 j = 0; j < number_of_elements - 1; j++) { a_stack.pop(); } } return 0; }
void long_test() { typedef stxxl::vector<int> ext_vec_type; ext_vec_type STXXLVector(1024 * 1024 * 256 / sizeof(int)); STXXL_MSG("Filling vector with increasing values..."); stxxl::generate(STXXLVector.begin(), STXXLVector.end(), counter<int>(), 4); stxxl::uint64 i; STXXL_MSG("Begin: "); for (i = 0; i < 10; i++) STXXL_MSG(STXXLVector[i]); STXXL_MSG("End: "); for (i = STXXLVector.size() - 10; i < STXXLVector.size(); i++) STXXL_MSG(STXXLVector[i]); STXXL_MSG("Permute randomly..."); stxxl::random_shuffle(STXXLVector.begin(), STXXLVector.end(), 1024 * 1024 * 128); STXXL_MSG("Begin: "); for (i = 0; i < 10; i++) STXXL_MSG(STXXLVector[i]); STXXL_MSG("End: "); for (i = STXXLVector.size() - 10; i < STXXLVector.size(); i++) STXXL_MSG(STXXLVector[i]); }
block_manager::block_manager() { config* config = config::get_instance(); // initialize config (may read config files now) config->check_initialized(); // allocate disk_allocators ndisks = config->disks_number(); disk_allocators = new disk_allocator*[ndisks]; disk_files = new file*[ndisks]; uint64 total_size = 0; for (unsigned i = 0; i < ndisks; ++i) { disk_config& cfg = config->disk(i); // assign queues in order of disks. if (cfg.queue == file::DEFAULT_QUEUE) cfg.queue = i; try { disk_files[i] = create_file(cfg, file::CREAT | file::RDWR, i); STXXL_MSG("Disk '" << cfg.path << "' is allocated, space: " << (cfg.size) / (1024 * 1024) << " MiB, I/O implementation: " << cfg.fileio_string()); } catch (io_error&) { STXXL_MSG("Error allocating disk '" << cfg.path << "', space: " << (cfg.size) / (1024 * 1024) << " MiB, I/O implementation: " << cfg.fileio_string()); throw; } total_size += cfg.size; disk_allocators[i] = new disk_allocator(disk_files[i], cfg); } if (ndisks > 1) { STXXL_MSG("In total " << ndisks << " disks are allocated, space: " << (total_size / (1024 * 1024)) << " MiB"); } #if STXXL_MNG_COUNT_ALLOCATION m_current_allocation = 0; m_total_allocation = 0; m_maximum_allocation = 0; #endif // STXXL_MNG_COUNT_ALLOCATION }
/** Prints the edges of the graph **/ void Graph::printGraph() { edgeItr itr; STXXL_MSG("**Graph - Edge Listing **"<<std::endl); STXXL_MSG("Vertices: " << noVertices); STXXL_MSG("Edges: " << noEdges); for(itr=edgeList.begin();itr!=edgeList.end();itr++) { STXXL_MSG(" (" <<(itr->getSrc())<<", " <<(itr->getDst())<<", "<<(itr->getEdgeWt())<<") "); } }
int main() { testIO(); testIO2(); testPrefetchPool(); testWritePool(); testStreams(); #if STXXL_MNG_COUNT_ALLOCATION stxxl::block_manager* bm = stxxl::block_manager::get_instance(); STXXL_MSG("block_manager total allocation: " << bm->get_total_allocation()); STXXL_MSG("block_manager current allocation: " << bm->get_current_allocation()); STXXL_MSG("block_manager maximum allocation: " << bm->get_maximum_allocation()); #endif // STXXL_MNG_COUNT_ALLOCATION }
int main(int argc, char * argv[]) { if (argc < 5) { STXXL_ERRMSG("Usage: " << argv[0] << " D L m seed"); return -1; } int i; const stxxl::int_type D = atoi(argv[1]); const stxxl::int_type L = atoi(argv[2]); const stxxl::int_type m = atoi(argv[3]); stxxl::ran32State = atoi(argv[4]); stxxl::int_type * disks = new stxxl::int_type[L]; stxxl::int_type * prefetch_order = new stxxl::int_type[L]; int * count = new int[D]; for (i = 0; i < D; i++) count[i] = 0; stxxl::random_number<> rnd; for (i = 0; i < L; i++) { disks[i] = rnd(D); count[disks[i]]++; } for (i = 0; i < D; i++) std::cout << "Disk " << i << " has " << count[i] << " blocks" << std::endl; stxxl::compute_prefetch_schedule(disks, disks + L, prefetch_order, m, D); STXXL_MSG("Prefetch order:"); for (i = 0; i < L; ++i) { STXXL_MSG("request " << prefetch_order[i] << " on disk " << disks[prefetch_order[i]]); } STXXL_MSG("Request order:"); for (i = 0; i < L; ++i) { int j; for (j = 0; prefetch_order[j] != i; ++j) ; STXXL_MSG("request " << i << " on disk " << disks[i] << " scheduled as " << j); } delete[] count; delete[] disks; delete[] prefetch_order; }
STXXL_BEGIN_NAMESPACE linuxaio_queue::linuxaio_queue(int desired_queue_length) : num_waiting_requests(0), num_free_events(0), num_posted_requests(0), post_thread_state(NOT_RUNNING), wait_thread_state(NOT_RUNNING) { if (desired_queue_length == 0) { // default value, 64 entries per queue (i.e. usually per disk) should // be enough max_events = 64; } else max_events = desired_queue_length; // negotiate maximum number of simultaneous events with the OS context = 0; long result; while ((result = syscall(SYS_io_setup, max_events, &context)) == -1 && errno == EAGAIN && max_events > 1) { max_events <<= 1; // try with half as many events } if (result != 0) { STXXL_THROW_ERRNO(io_error, "linuxaio_queue::linuxaio_queue" " io_setup() nr_events=" << max_events); } for (int e = 0; e < max_events; ++e) num_free_events++; // cannot set semaphore to value directly STXXL_MSG("Set up an linuxaio queue with " << max_events << " entries."); start_thread(post_async, static_cast<void*>(this), post_thread, post_thread_state); start_thread(wait_async, static_cast<void*>(this), wait_thread, wait_thread_state); }
int main() { stxxl::config* config = stxxl::config::get_instance(); stxxl::disk_config disk1("/tmp/stxxl-###.tmp", 16 * 1024 * 1024, "syscall autogrow=no"); disk1.unlink_on_open = true; disk1.direct = stxxl::disk_config::DIRECT_OFF; config->add_disk(disk1); vector_type* vector = new vector_type(); try { while (true) vector->push_back(0); } catch (std::exception& e) { STXXL_ERRMSG("Caught exception: " << e.what()); delete vector; // here it will crash in block_manager::delete_block(bid) } STXXL_MSG("Delete done, all is well."); return 0; }
void DirectedGraph::addEdgesMST(StarGraph &star,MST &mst,Graph &inputGraph) { StarGraph::const_starItr starItr; const_dirEdgeItr eItr; starItr = star.begin(); Edge *e; Graph::const_vertexItr vItr = inputGraph.getFirstVertex(); if(roots.size()!=0) { for(eItr=dirEdgeList.begin();eItr!=dirEdgeList.end();eItr++) { while(starItr!=star.end() && starItr->starEdge.getSrc() < eItr->getSrc()) starItr++; while(!(inputGraph.checkVertexListEnd(vItr)) && vItr->first.getVertexId() < eItr->getSrc()) vItr++; if(starItr->starEdge.getSrc() == eItr->getSrc() && vItr->first.getVertexId() == eItr->getSrc()) { e = new Edge(eItr->getOrigDst(), eItr->getOrigSrc(), eItr->getEdgeWt()); mst.addEdge(*e); delete e; } } } clear(); STXXL_MSG("MST size: "<<mst.getMSTSize()); }
int main_usage(const char* arg0) { STXXL_MSG(stxxl::get_version_string_long()); std::cout << "Usage: " << arg0 << " <subtool> ..." << std::endl << "Available subtools: " << std::endl; size_t shortlen = 0; for (unsigned int i = 0; subtools[i].name; ++i) { if (!subtools[i].shortline) continue; shortlen = std::max(shortlen, strlen(subtools[i].name)); } for (unsigned int i = 0; subtools[i].name; ++i) { if (subtools[i].shortline) continue; std::cout << " " << subtools[i].name << std::endl; stxxl::cmdline_parser::output_wrap(std::cout, subtools[i].description, 80, 6, 6); std::cout << std::endl; } for (unsigned int i = 0; subtools[i].name; ++i) { if (!subtools[i].shortline) continue; std::cout << " " << std::left << std::setw(shortlen + 2) << subtools[i].name << subtools[i].description << std::endl; } std::cout << std::endl; return 0; }
int main() { #if STXXL_PARALLEL_MULTIWAY_MERGE STXXL_MSG("STXXL_PARALLEL_MULTIWAY_MERGE"); #endif // special parameter type typedef stxxl::stream::use_push<value_type> InputType; typedef stxxl::stream::runs_creator<InputType, Cmp, 4096, stxxl::RC> CreateRunsAlg; typedef CreateRunsAlg::sorted_runs_type SortedRunsType; unsigned input_size = (50 * megabyte / sizeof(value_type)); Cmp c; CreateRunsAlg SortedRuns(c, 1 * megabyte / 64); value_type checksum_before(0); stxxl::random_number32 rnd; for (unsigned cnt = input_size; cnt > 0; --cnt) { const value_type element = rnd(); checksum_before += element; SortedRuns.push(element); // push into the sorter } SortedRunsType& Runs = SortedRuns.result(); // get sorted_runs data structure assert(stxxl::stream::check_sorted_runs(Runs, Cmp())); // merge the runs stxxl::stream::runs_merger<SortedRunsType, Cmp> merger(Runs, Cmp(), 1 * megabyte); stxxl::vector<value_type, 4, stxxl::lru_pager<8>, block_size, STXXL_DEFAULT_ALLOC_STRATEGY> array; STXXL_MSG(input_size << " " << Runs->elements); STXXL_MSG("checksum before: " << checksum_before); value_type checksum_after(0); for (unsigned i = 0; i < input_size; ++i) { checksum_after += *merger; array.push_back(*merger); ++merger; } STXXL_MSG("checksum after: " << checksum_after); assert(stxxl::is_sorted(array.begin(), array.end(), Cmp())); assert(checksum_before == checksum_after); assert(merger.empty()); return 0; }
int main() { STXXL_MSG(sizeof(MyType) << " " << (BLOCK_SIZE % sizeof(MyType))); STXXL_MSG(sizeof(block_type) << " " << BLOCK_SIZE); const unsigned nblocks = 2; stxxl::BIDArray<BLOCK_SIZE> bids(nblocks); std::vector<int> disks(nblocks, 2); stxxl::request_ptr* reqs = new stxxl::request_ptr[nblocks]; stxxl::block_manager* bm = stxxl::block_manager::get_instance(); bm->new_blocks(stxxl::striping(), bids.begin(), bids.end()); block_type* block = new block_type[2]; STXXL_MSG(std::hex); STXXL_MSG("Allocated block address : " << (stxxl::unsigned_type)(block)); STXXL_MSG("Allocated block address + 1: " << (stxxl::unsigned_type)(block + 1)); STXXL_MSG(std::dec); unsigned i = 0; for (i = 0; i < block_type::size; ++i) { block->elem[i].integer = i; //memcpy (block->elem[i].chars, "STXXL", 4); } for (i = 0; i < nblocks; ++i) reqs[i] = block->write(bids[i], my_handler()); std::cout << "Waiting " << std::endl; stxxl::wait_all(reqs, nblocks); for (i = 0; i < nblocks; ++i) { reqs[i] = block->read(bids[i], my_handler()); reqs[i]->wait(); for (int j = 0; j < block_type::size; ++j) { STXXL_CHECK2(j == block->elem[j].integer, "Error in block " << std::hex << i << " pos: " << j << " value read: " << block->elem[j].integer); } } bm->delete_blocks(bids.begin(), bids.end()); delete[] reqs; delete[] block; #if 0 // variable-size blocks, not supported currently BIDArray<0> vbids(nblocks); for (i = 0; i < nblocks; i++) vbids[i].size = 1024 + i; bm->new_blocks(striping(), vbids.begin(), vbids.end()); for (i = 0; i < nblocks; i++) STXXL_MSG("Allocated block: offset=" << vbids[i].offset << ", size=" << vbids[i].size); bm->delete_blocks(vbids.begin(), vbids.end()); #endif }
void DirectedGraph::printGraph() { dirEdgeItr itr; STXXL_MSG("**Directed Graph - Edge Listing **"<<std::endl); STXXL_MSG("Number of edges: "<<noEdges<<std::endl); for(itr=dirEdgeList.begin();itr!=dirEdgeList.end();itr++) { STXXL_MSG(" (" <<(itr->getSrc())<<", " <<(itr->getDst())<<", "<<(itr->getEdgeWt())<<") "); } STXXL_MSG("\n**Directed Graph Components - Roots Listing **"); for(itr=roots.begin();itr!=roots.end();itr++) { STXXL_MSG(" (" <<(itr->getSrc())<<", " <<(itr->getDst())<<", "<<(itr->getEdgeWt())<<") "); } }
/** Generates the specified no of edges Selects a source and destination node randomly using rand function **/ void Graph::generateEdges() { unsigned int i; edgeItr eItr,NewEnd; edgeList.clear(); Edge *e; //Generate one edge for each vertex in the graph for(i=0;i<noVertices;i++) { e = new Edge(i+1,randomNodeID(),randomEdgeWeight()); //Re-generate until source and destination nodes are different while(e->getDst() == e->getSrc()) e->setDst(randomNodeID()); edgeList.push_back(*e); edgeList.push_back(*e); edgeList.back().swap(); delete e; } //Generate the remaining no. of edges for(i=0;i<(noEdges-noVertices);i++) { Edge tempEdge(randomNodeID(),randomNodeID(),randomEdgeWeight()); while(tempEdge.getDst() == tempEdge.getSrc()) tempEdge.setDst(randomNodeID()); edgeList.push_back(tempEdge); edgeList.push_back(tempEdge); edgeList.back().swap(); } stxxl::sort(edgeList.begin(),edgeList.end(),myCmpSrc(),INTERNAL_MEMORY_FOR_SORTING); //Remove duplicate edges NewEnd = edgeList.begin() ; for(eItr=edgeList.begin()+1; eItr!= edgeList.end(); eItr++) { if(!(*NewEnd == *eItr)) { NewEnd++; *NewEnd = *eItr; } } NewEnd++; edgeList.resize(NewEnd - edgeList.begin()); //Store edges sorted the key <Source vertex, Edge weight> stxxl::sort(edgeList.begin(),edgeList.end(),myCmpEdgeWt(),INTERNAL_MEMORY_FOR_SORTING); noEdges = edgeList.size()/2; STXXL_MSG("Edge vector created of size: "<<edgeList.size()); }
int main(int argc, char* argv[]) { if (argc < 2) { STXXL_MSG("Usage: " << argv[0] << " #log_ins"); return -1; } const int log_nins = atoi(argv[1]); if (log_nins > 31) { STXXL_ERRMSG("This test can't do more than 2^31 operations, you requested 2^" << log_nins); return -1; } btree_type BTree(1024 * 128, 1024 * 128); const stxxl::uint64 nins = 1ULL << log_nins; stxxl::ran32State = (unsigned int)time(NULL); stxxl::vector<int> Values(nins); STXXL_MSG("Generating " << nins << " random values"); stxxl::generate(Values.begin(), Values.end(), rnd_gen(), 4); stxxl::vector<int>::const_iterator it = Values.begin(); STXXL_MSG("Inserting " << nins << " random values into btree"); for ( ; it != Values.end(); ++it) BTree.insert(std::pair<int, double>(*it, double(*it) + 1.0)); STXXL_MSG("Number of elements in btree: " << BTree.size()); STXXL_MSG("Searching " << nins << " existing elements"); stxxl::vector<int>::const_iterator vIt = Values.begin(); for ( ; vIt != Values.end(); ++vIt) { btree_type::iterator bIt = BTree.find(*vIt); STXXL_CHECK(bIt != BTree.end()); STXXL_CHECK(bIt->first == *vIt); } STXXL_MSG("Searching " << nins << " non-existing elements"); stxxl::vector<int>::const_iterator vIt1 = Values.begin(); for ( ; vIt1 != Values.end(); ++vIt1) { btree_type::iterator bIt = BTree.find((*vIt1) + 1); STXXL_CHECK(bIt == BTree.end()); } STXXL_MSG("Test passed."); return 0; }
void testIO() { const unsigned nblocks = 2; stxxl::BIDArray<BLOCK_SIZE> bids(nblocks); std::vector<int> disks(nblocks, 2); stxxl::request_ptr* reqs = new stxxl::request_ptr[nblocks]; stxxl::block_manager* bm = stxxl::block_manager::get_instance(); bm->new_blocks(stxxl::striping(), bids.begin(), bids.end()); block_type* block = new block_type; STXXL_MSG(std::hex); STXXL_MSG("Allocated block address : " << (stxxl::unsigned_type)(block)); STXXL_MSG("Allocated block address + 1: " << (stxxl::unsigned_type)(block + 1)); STXXL_MSG(std::dec); unsigned i = 0; for (i = 0; i < block_type::size; ++i) { block->elem[i].integer = i; //memcpy (block->elem[i].chars, "STXXL", 4); } for (i = 0; i < nblocks; ++i) reqs[i] = block->write(bids[i], my_handler()); std::cout << "Waiting " << std::endl; stxxl::wait_all(reqs, nblocks); for (i = 0; i < nblocks; ++i) { reqs[i] = block->read(bids[i], my_handler()); reqs[i]->wait(); for (int j = 0; j < block_type::size; ++j) { STXXL_CHECK(j == block->elem[j].integer); } } bm->delete_blocks(bids.begin(), bids.end()); delete[] reqs; delete block; }
int main(int argc, char ** argv) { if (argc < 3) { std::cout << "Usage: " << argv[0] << " infile outfile" << std::endl; return -1; } const unsigned memory_to_use = 512 * 1024 * 1024; const unsigned int block_size = sizeof(my_type) * 4096; typedef stxxl::vector<my_type, 1, stxxl::lru_pager<2>, block_size> vector_type; stxxl::syscall_file in_file(argv[1], stxxl::file::DIRECT | stxxl::file::RDONLY); stxxl::syscall_file out_file(argv[2], stxxl::file::DIRECT | stxxl::file::RDWR | stxxl::file::CREAT); vector_type input(&in_file); vector_type output(&out_file); output.resize(input.size()); #ifdef BOOST_MSVC typedef stxxl::stream::streamify_traits<vector_type::iterator>::stream_type input_stream_type; #else typedef __typeof__(stxxl::stream::streamify(input.begin(), input.end())) input_stream_type; #endif input_stream_type input_stream = stxxl::stream::streamify(input.begin(), input.end()); typedef Cmp comparator_type; typedef stxxl::stream::sort<input_stream_type, comparator_type, block_size> sort_stream_type; sort_stream_type sort_stream(input_stream, comparator_type(), memory_to_use); vector_type::iterator o = stxxl::stream::materialize(sort_stream, output.begin(), output.end()); assert(o == output.end()); if (1) { STXXL_MSG("Checking order..."); STXXL_MSG((stxxl::is_sorted(output.begin(), output.end(), comparator_type()) ? "OK" : "WRONG")); } return 0; }
int main() { typedef stxxl::STACK_GENERATOR<int, stxxl::migrating, stxxl::normal, 4, 4096, std::stack<int>, critical_size>::result migrating_stack_type; STXXL_MSG("Starting test."); migrating_stack_type my_stack; int test_size = 1 * 1024 * 1024 / sizeof(int), i; STXXL_MSG("Filling stack."); for (i = 0; i < test_size; i++) { my_stack.push(i); STXXL_CHECK(my_stack.top() == i); STXXL_CHECK(my_stack.size() == i + 1); STXXL_CHECK((my_stack.size() >= critical_size) == my_stack.external()); } STXXL_MSG("Testing swap."); // test swap migrating_stack_type my_stack2; std::swap(my_stack2, my_stack); std::swap(my_stack2, my_stack); STXXL_MSG("Removing elements from " << (my_stack.external() ? "external" : "internal") << " stack"); for (i = test_size - 1; i >= 0; i--) { STXXL_CHECK(my_stack.top() == i); STXXL_CHECK(my_stack.size() == i + 1); my_stack.pop(); STXXL_CHECK(my_stack.size() == i); STXXL_CHECK(my_stack.external() == (test_size >= int(critical_size))); } STXXL_MSG("Test passed."); return 0; }
void C(btree_type& BTree) { stxxl::uint64 sum = 0; stxxl::timer Timer1; Timer1.start(); btree_type::const_iterator it = BTree.begin(), end = BTree.end(); for ( ; it != end; ++it) sum += it->second.data; Timer1.stop(); STXXL_MSG("Scanning with const iterator: " << Timer1.mseconds() << " msec"); STXXL_CHECK(sum == checksum); }
int main() { typedef stxxl::stream::runs_creator<Input, Cmp, 4096 * MULT, stxxl::RC> CreateRunsAlg; typedef CreateRunsAlg::sorted_runs_type SortedRunsType; stxxl::stats * s = stxxl::stats::get_instance(); std::cout << *s; STXXL_MSG("Size of block type " << sizeof(CreateRunsAlg::block_type)); unsigned size = MULT * 1024 * 128 / (sizeof(Input::value_type) * 2); Input in(size + 1); CreateRunsAlg SortedRuns(in, Cmp(), 1024 * 128 * MULT); SortedRunsType& Runs = SortedRuns.result(); assert(stxxl::stream::check_sorted_runs(Runs, Cmp())); // merge the runs stxxl::stream::runs_merger<SortedRunsType, Cmp> merger(Runs, Cmp(), MULT * 1024 * 128); stxxl::vector<Input::value_type> array; STXXL_MSG(size << " " << Runs->elements); STXXL_MSG("CRC: " << in.crc); Input::value_type crc(0); for (unsigned i = 0; i < size; ++i) { //STXXL_MSG(*merger<< " must be "<< i+2 << ((*merger != i+2)?" WARNING":"")); //assert(*merger == i+2); crc += *merger; array.push_back(*merger); ++merger; } STXXL_MSG("CRC: " << crc); assert(stxxl::is_sorted(array.begin(), array.end(), Cmp())); assert(merger.empty()); std::cout << *s; return 0; }
int stxxl_info(int, char**) { stxxl::config::get_instance(); stxxl::block_manager::get_instance(); stxxl::stats::get_instance(); stxxl::disk_queues::get_instance(); #if STXXL_PARALLEL STXXL_MSG("STXXL_PARALLEL, max threads = " << omp_get_max_threads()); #endif STXXL_MSG("sizeof(unsigned int) = " << sizeof(unsigned int)); STXXL_MSG("sizeof(unsigned_type) = " << sizeof(stxxl::unsigned_type)); STXXL_MSG("sizeof(uint64) = " << sizeof(stxxl::uint64)); STXXL_MSG("sizeof(long) = " << sizeof(long)); STXXL_MSG("sizeof(size_t) = " << sizeof(size_t)); STXXL_MSG("sizeof(off_t) = " << sizeof(off_t)); STXXL_MSG("sizeof(void*) = " << sizeof(void*)); #if defined(STXXL_HAVE_AIO_FILE) STXXL_MSG("STXXL_HAVE_AIO_FILE = " << STXXL_HAVE_AIO_FILE); #endif return 0; }
/** Generates a complete graph **/ void Graph::generateCompleteGraph() { unsigned int weight; edgeItr eItr,NewEnd; noEdges = noVertices * (noVertices - 1) / 2; edgeList.clear(); //Generate noVertices * (noVertices - 1) / 2 number of edges with edge weights genrated randomly for (unsigned int i=0; i<noVertices; i++) { for (unsigned int j=0; j<i; j++) { weight = randomEdgeWeight(); Edge tempEdge(i+1,j+1,weight); edgeList.push_back(tempEdge); edgeList.push_back(tempEdge); edgeList.back().swap(); } } stxxl::sort(edgeList.begin(),edgeList.end(),myCmpSrc(),INTERNAL_MEMORY_FOR_SORTING); NewEnd = edgeList.begin() ; for(eItr=edgeList.begin()+1; eItr!= edgeList.end(); eItr++) { if(!(NewEnd == eItr)) { NewEnd++; *NewEnd = *eItr; } } NewEnd++; edgeList.resize(NewEnd - edgeList.begin()); stxxl::sort(edgeList.begin(),edgeList.end(),myCmpEdgeWt(),INTERNAL_MEMORY_FOR_SORTING); noEdges = edgeList.size()/2; STXXL_MSG("Edge vector created of size: "<<edgeList.size()); //Generate the vertex list generateVertexList(); }
void test(stxxl::uint64 data_mem, unsigned memory_to_use) { stxxl::uint64 records_to_sort = data_mem / sizeof(T); typedef stxxl::vector<T, 2, stxxl::lru_pager<8>, block_size, alloc_strategy_type> vector_type; memory_to_use = stxxl::div_ceil(memory_to_use, vector_type::block_type::raw_size) * vector_type::block_type::raw_size; vector_type v(records_to_sort); unsigned ndisks = stxxl::config::get_instance()->disks_number(); STXXL_MSG("Sorting " << records_to_sort << " records of size " << sizeof(T)); STXXL_MSG("Total volume " << (records_to_sort * sizeof(T)) / MB << " MiB"); STXXL_MSG("Using " << memory_to_use / MB << " MiB"); STXXL_MSG("Using " << ndisks << " disks"); STXXL_MSG("Using " << alloc_strategy_type::name() << " allocation strategy "); STXXL_MSG("Block size " << vector_type::block_type::raw_size / 1024 << " KiB"); STXXL_MSG("Filling vector..."); std::generate(v.begin(), v.end(), stxxl::random_number64() _STXXL_FORCE_SEQUENTIAL); //std::generate(v.begin(),v.end(),zero()); STXXL_MSG("Sorting vector..."); stxxl::stats_data before(*stxxl::stats::get_instance()); stxxl::stable_ksort(v.begin(), v.end(), memory_to_use); stxxl::stats_data after(*stxxl::stats::get_instance()); STXXL_MSG("Checking order..."); STXXL_MSG((stxxl::is_sorted(v.begin(), v.end()) ? "OK" : "WRONG")); STXXL_MSG("Sorting: " << (after - before)); STXXL_MSG("Total: " << *stxxl::stats::get_instance()); }
int main(int argc, char * argv[]) { if (argc < 6) { STXXL_ERRMSG("Usage: " << argv[0] << " <MiB to sort> <MiB to use> <alloc_strategy [0..3]> <blk_size [0..14]> <seed>"); return -1; } #if STXXL_PARALLEL_MULTIWAY_MERGE STXXL_MSG("STXXL_PARALLEL_MULTIWAY_MERGE"); #endif stxxl::uint64 data_mem = stxxl::atoint64(argv[1]) * MB; int sort_mem = atoi(argv[2]) * MB; int strategy = atoi(argv[3]); int block_size = atoi(argv[4]); stxxl::set_seed(strtoul(argv[5], NULL, 10)); STXXL_MSG("Seed " << stxxl::get_next_seed()); stxxl::srandom_number32(); typedef my_type<stxxl::uint64, RECORD_SIZE> my_default_type; switch (block_size) { case 0: test_all_strategies<my_default_type, 128 * 1024>(data_mem, sort_mem, strategy); break; case 1: test_all_strategies<my_default_type, 256 * 1024>(data_mem, sort_mem, strategy); break; case 2: test_all_strategies<my_default_type, 512 * 1024>(data_mem, sort_mem, strategy); break; case 3: test_all_strategies<my_default_type, 1024 * 1024>(data_mem, sort_mem, strategy); break; case 4: test_all_strategies<my_default_type, 2 * 1024 * 1024>(data_mem, sort_mem, strategy); break; case 5: test_all_strategies<my_default_type, 4 * 1024 * 1024>(data_mem, sort_mem, strategy); break; case 6: test_all_strategies<my_default_type, 8 * 1024 * 1024>(data_mem, sort_mem, strategy); break; case 7: test_all_strategies<my_default_type, 16 * 1024 * 1024>(data_mem, sort_mem, strategy); break; case 8: test_all_strategies<my_default_type, 640 * 1024>(data_mem, sort_mem, strategy); break; case 9: test_all_strategies<my_default_type, 768 * 1024>(data_mem, sort_mem, strategy); break; case 10: test_all_strategies<my_default_type, 896 * 1024>(data_mem, sort_mem, strategy); break; case 11: test_all_strategies<my_type<unsigned, 12>, 2 * MB>(data_mem, sort_mem, strategy); break; case 12: test_all_strategies<my_type<unsigned, 12>, 2 * MB + 4096>(data_mem, sort_mem, strategy); break; case 13: test_all_strategies<my_type<unsigned, 20>, 2 * MB + 4096>(data_mem, sort_mem, strategy); break; case 14: test_all_strategies<my_type<unsigned, 8>, 2 * MB>(data_mem, sort_mem, strategy); break; default: STXXL_ERRMSG("Unknown block size: " << block_size << ", aborting"); abort(); } return 0; }
int main(int argc, char** argv) { if (argc < 3) { std::cout << "Usage: " << argv[0] << " action file" << std::endl; std::cout << " where action is one of generate, sort, ksort, stable_sort, stable_ksort" << std::endl; return -1; } const unsigned int block_size = sizeof(my_type) * 4096; if (strcmp(argv[1], "generate") == 0) { const my_type::key_type num_elements = 1 * 1024 * 1024; const unsigned int records_in_block = block_size / sizeof(my_type); stxxl::syscall_file f(argv[2], stxxl::file::CREAT | stxxl::file::RDWR); my_type* array = (my_type*)stxxl::aligned_alloc<STXXL_BLOCK_ALIGN>(block_size); memset(array, 0, block_size); my_type::key_type cur_key = num_elements; for (unsigned i = 0; i < num_elements / records_in_block; i++) { for (unsigned j = 0; j < records_in_block; j++) array[j]._key = cur_key--; stxxl::request_ptr req = f.awrite((void*)array, stxxl::int64(i) * block_size, block_size, stxxl::default_completion_handler()); req->wait(); } stxxl::aligned_dealloc<STXXL_BLOCK_ALIGN>(array); } else { #if STXXL_PARALLEL_MULTIWAY_MERGE STXXL_MSG("STXXL_PARALLEL_MULTIWAY_MERGE"); #endif stxxl::syscall_file f(argv[2], stxxl::file::DIRECT | stxxl::file::RDWR); unsigned memory_to_use = 50 * 1024 * 1024; typedef stxxl::vector<my_type, 1, stxxl::lru_pager<8>, block_size> vector_type; vector_type v(&f); /* STXXL_MSG("Printing..."); for(stxxl::int64 i=0; i < v.size(); i++) STXXL_MSG(v[i].key()); */ STXXL_MSG("Checking order..."); STXXL_MSG((stxxl::is_sorted(v.begin(), v.end()) ? "OK" : "WRONG")); STXXL_MSG("Sorting..."); if (strcmp(argv[1], "sort") == 0) { stxxl::sort(v.begin(), v.end(), Cmp(), memory_to_use); #if 0 // stable_sort is not yet implemented } else if (strcmp(argv[1], "stable_sort") == 0) { stxxl::stable_sort(v.begin(), v.end(), memory_to_use); #endif } else if (strcmp(argv[1], "ksort") == 0) { stxxl::ksort(v.begin(), v.end(), memory_to_use); } else if (strcmp(argv[1], "stable_ksort") == 0) { stxxl::stable_ksort(v.begin(), v.end(), memory_to_use); } else { STXXL_MSG("Not implemented: " << argv[1]); } STXXL_MSG("Checking order..."); STXXL_MSG((stxxl::is_sorted(v.begin(), v.end()) ? "OK" : "WRONG")); } return 0; }
/** The main program. */ int main(int argc, char *argv[]) { Parameters param(argc, argv); // parse the command-line arguments if(param.noOfNodes() == std::numeric_limits<unsigned int>::max() || param.noOfEdges() ==std::numeric_limits<unsigned int>::max()) { STXXL_MSG("Either number of vertices or edges is not speicifed. Exiting!!!"); return 0; } Graph inputGraph(param.noOfNodes(),param.noOfEdges()); if (param.randomGraph()) { STXXL_MSG("Generating random graph"); inputGraph.generateGraph(); inputGraph.printGraph(); } else if (param.importInputFilename() != "") { // import graph from file STXXL_MSG("Import graph" << std::endl ); if(param.otherGraph()) importFromFile(param.importInputFilename(),inputGraph ); else importEdgeVector( param.importInputFilename(),inputGraph ); } // export input graph if (param.outputFilename() != "") { STXXL_MSG("Export graph" << std::endl ); std::ofstream outFile(param.outputFilename().c_str()); exportEdgeVector(outFile, inputGraph); } stxxl::stats_data stats_begin(*stxxl::stats::get_instance()); stxxl::timer Timer; MST mst(inputGraph.getNoVertices()); mst.clearMST(); float B = (float) BLOCK_SIZE/(float)(sizeof(Edge)); float M = (10 * 1024 * 1024)/(float)(sizeof(Edge)); float N = param.noOfNodes()+2*param.noOfEdges(); STXXL_MSG("N: "<<N<<" M: "<<M<<" B: "<<B<<" Sizeof Edge: "<<sizeof(Edge)); if(N > M) { stxxl::stats_data stats_begin(*stxxl::stats::get_instance()); Timer.reset(); Timer.start(); stage(inputGraph,mst); STXXL_MSG("Part-1 build elapsed time: " << (Timer.mseconds() / 1000.) <<" seconds : " << (double(inputGraph.getNoEdges()) / (Timer.mseconds() / 1000.)) << " edges per sec"); std::cout << stats_total; } if(inputGraph.getNoEdges() != 0) { stats_begin = *stxxl::stats::get_instance(); Timer.reset(); Timer.start(); ExternalPrim prim; prim.buildMST(inputGraph,mst); STXXL_MSG("MST build elapsed time: " << (Timer.mseconds() / 1000.) <<" seconds : " << (double(inputGraph.getNoEdges()) / (Timer.mseconds() / 1000.)) << " edges per sec"); std::cout << stxxl::stats_data(*stxxl::stats::get_instance()) - stats_begin; } mst.printMST(); return 0; }
int main(int argc, char* argv[]) { if (argc < 3) { std::cout << "Usage: " << argv[0] << " [n in MiB]" #if defined(STXXL_PARALLEL) << " [p threads]" #endif << std::endl; return -1; } STXXL_MSG("----------------------------------------"); stxxl::config::get_instance(); std::string Flags = std::string("") #if STXXL_CHECK_ORDER_IN_SORTS + " STXXL_CHECK_ORDER_IN_SORTS" #endif #ifdef NDEBUG + " NDEBUG" #endif #if TINY_PQ + " TINY_PQ" #endif #if MANUAL_PQ + " MANUAL_PQ" #endif #if SIDE_PQ + " SIDE_PQ" #endif #if STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL + " STXXL_PARALLEL_PQ_MULTIWAY_MERGE_INTERNAL" #endif #if STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL + " STXXL_PARALLEL_PQ_MULTIWAY_MERGE_EXTERNAL" #endif #if STXXL_PARALLEL_PQ_MULTIWAY_MERGE_DELETE_BUFFER + " STXXL_PARALLEL_PQ_MULTIWAY_MERGE_DELETE_BUFFER" #endif ; STXXL_MSG("Flags:" << Flags); unsigned long megabytes = atoi(argv[1]); #if defined(STXXL_PARALLEL_MODE) int num_threads = atoi(argv[2]); STXXL_MSG("Threads: " << num_threads); omp_set_num_threads(num_threads); __gnu_parallel::_Settings parallel_settings(__gnu_parallel::_Settings::get()); parallel_settings.sort_algorithm = __gnu_parallel::QS_BALANCED; parallel_settings.sort_splitting = __gnu_parallel::SAMPLING; parallel_settings.sort_minimal_n = 1000; parallel_settings.sort_mwms_oversampling = 10; parallel_settings.merge_splitting = __gnu_parallel::SAMPLING; parallel_settings.merge_minimal_n = 1000; parallel_settings.merge_oversampling = 10; parallel_settings.multiway_merge_algorithm = __gnu_parallel::LOSER_TREE; parallel_settings.multiway_merge_splitting = __gnu_parallel::EXACT; parallel_settings.multiway_merge_oversampling = 10; parallel_settings.multiway_merge_minimal_n = 1000; parallel_settings.multiway_merge_minimal_k = 2; __gnu_parallel::_Settings::set(parallel_settings); #endif const stxxl::unsigned_type mem_for_queue = 512 * mega; const stxxl::unsigned_type mem_for_pools = 512 * mega; #if TINY_PQ stxxl::STXXL_UNUSED(mem_for_queue); const unsigned BufferSize1 = 32; // equalize procedure call overheads etc. const unsigned N = (1 << 9) / sizeof(my_type); // minimal sequence length const unsigned IntKMAX = 8; // maximal arity for internal mergersq const unsigned IntLevels = 2; // number of internal levels const unsigned BlockSize = (4 * mega); const unsigned ExtKMAX = 8; // maximal arity for external mergers const unsigned ExtLevels = 2; // number of external levels typedef stxxl::priority_queue< stxxl::priority_queue_config< my_type, my_cmp, BufferSize1, N, IntKMAX, IntLevels, BlockSize, ExtKMAX, ExtLevels > > pq_type; #elif MANUAL_PQ stxxl::STXXL_UNUSED(mem_for_queue); const unsigned BufferSize1 = 32; // equalize procedure call overheads etc. const unsigned N = (1 << 20) / sizeof(my_type); // minimal sequence length const unsigned IntKMAX = 16; // maximal arity for internal mergersq const unsigned IntLevels = 2; // number of internal levels const unsigned BlockSize = (4 * mega); const unsigned ExtKMAX = 32; // maximal arity for external mergers const unsigned ExtLevels = 2; // number of external levels typedef stxxl::priority_queue< stxxl::priority_queue_config< my_type, my_cmp, BufferSize1, N, IntKMAX, IntLevels, BlockSize, ExtKMAX, ExtLevels > > pq_type; #else const stxxl::uint64 volume = stxxl::uint64(200000) * mega; // in bytes typedef stxxl::PRIORITY_QUEUE_GENERATOR<my_type, my_cmp, mem_for_queue, volume / sizeof(my_type) / 1024 + 1> gen; typedef gen::result pq_type; // BufferSize1 = Config::BufferSize1, // N = Config::N, // IntKMAX = Config::IntKMAX, // IntLevels = Config::IntLevels, // ExtLevels = Config::ExtLevels, // Levels = Config::IntLevels + Config::ExtLevels, // BlockSize = Config::BlockSize, // ExtKMAX = Config::ExtKMAX /* STXXL_MSG ( "Blocks fitting into internal memory m: "<<gen::m ); STXXL_MSG ( "X : "<<gen::X ); //maximum number of internal elements //X = B * (settings::k - m) / settings::E, STXXL_MSG ( "Expected internal memory consumption: "<< (gen::EConsumption / 1048576) << " MiB");*/ #endif STXXL_MSG("Internal arity: " << pq_type::IntKMAX); STXXL_MSG("N : " << pq_type::N); //X / (AI * AI) STXXL_MSG("External arity: " << pq_type::ExtKMAX); STXXL_MSG("Block size B: " << pq_type::BlockSize); //EConsumption = X * settings::E + settings::B * AE + ((MaxS_ / X) / AE) * settings::B * 1024 STXXL_MSG("Data type size: " << sizeof(my_type)); STXXL_MSG(""); stxxl::stats_data sd_start(*stxxl::stats::get_instance()); stxxl::timer Timer; Timer.start(); pq_type p(mem_for_pools / 2, mem_for_pools / 2); stxxl::int64 nelements = stxxl::int64(megabytes * mega / sizeof(my_type)), i; STXXL_MSG("Internal memory consumption of the priority queue: " << p.mem_cons() << " B"); STXXL_MSG("Peak number of elements (n): " << nelements); STXXL_MSG("Max number of elements to contain: " << (stxxl::uint64(pq_type::N) * pq_type::IntKMAX * pq_type::IntKMAX * pq_type::ExtKMAX * pq_type::ExtKMAX)); srand(5); my_cmp cmp; my_key_type r, sum_input = 0, sum_output = 0; my_type least(0), last_least(0); const my_key_type modulo = 0x10000000; #if SIDE_PQ std::priority_queue<my_type, std::vector<my_type>, my_cmp> side_pq; #endif my_type side_pq_least; STXXL_MSG("op-sequence(monotonic pq): ( push, pop, push ) * n"); for (i = 0; i < nelements; ++i) { if ((i % mega) == 0) STXXL_MSG( std::fixed << std::setprecision(2) << std::setw(5) << (100.0 * (double)i / (double)nelements) << "% " << "Inserting element " << i << " top() == " << least.key << " @ " << std::setprecision(3) << Timer.seconds() << " s" << std::setprecision(6) << std::resetiosflags(std::ios_base::floatfield)); //monotone priority queue r = least.key + rand() % modulo; sum_input += r; p.push(my_type(r)); #if SIDE_PQ side_pq.push(my_type(r)); #endif least = p.top(); sum_output += least.key; p.pop(); #if SIDE_PQ side_pq_least = side_pq.top(); side_pq.pop(); if (!(side_pq_least == least)) STXXL_MSG("Wrong result at " << i << " " << side_pq_least.key << " != " << least.key); #endif if (cmp(last_least, least)) { STXXL_MSG("Wrong order at " << i << " " << last_least.key << " > " << least.key); } else last_least = least; r = least.key + rand() % modulo; sum_input += r; p.push(my_type(r)); #if SIDE_PQ side_pq.push(my_type(r)); #endif } Timer.stop(); STXXL_MSG("Time spent for filling: " << Timer.seconds() << " s"); STXXL_MSG("Internal memory consumption of the priority queue: " << p.mem_cons() << " B"); stxxl::stats_data sd_middle(*stxxl::stats::get_instance()); std::cout << sd_middle - sd_start; Timer.reset(); Timer.start(); STXXL_MSG("op-sequence(monotonic pq): ( pop, push, pop ) * n"); for (i = 0; i < (nelements); ++i) { assert(!p.empty()); least = p.top(); sum_output += least.key; p.pop(); #if SIDE_PQ side_pq_least = side_pq.top(); side_pq.pop(); if (!(side_pq_least == least)) { STXXL_VERBOSE1("" << side_pq_least << " != " << least); } #endif if (cmp(last_least, least)) { STXXL_MSG("Wrong result at " << i << " " << last_least.key << " > " << least.key); } else last_least = least; r = least.key + rand() % modulo; sum_input += r; p.push(my_type(r)); #if SIDE_PQ side_pq.push(my_type(r)); #endif least = p.top(); sum_output += least.key; p.pop(); #if SIDE_PQ side_pq_least = side_pq.top(); side_pq.pop(); if (!(side_pq_least == least)) { STXXL_VERBOSE1("" << side_pq_least << " != " << least); } #endif if (cmp(last_least, least)) { STXXL_MSG("Wrong result at " << i << " " << last_least.key << " > " << least.key); } else last_least = least; if ((i % mega) == 0) STXXL_MSG( std::fixed << std::setprecision(2) << std::setw(5) << (100.0 * (double)i / (double)nelements) << "% " << "Popped element " << i << " == " << least.key << " @ " << std::setprecision(3) << Timer.seconds() << " s" << std::setprecision(6) << std::resetiosflags(std::ios_base::floatfield)); } STXXL_MSG("Last element " << i << " popped"); Timer.stop(); if (sum_input != sum_output) STXXL_MSG("WRONG sum! " << sum_input << " - " << sum_output << " = " << (sum_output - sum_input) << " / " << (sum_input - sum_output)); STXXL_MSG("Time spent for removing elements: " << Timer.seconds() << " s"); STXXL_MSG("Internal memory consumption of the priority queue: " << p.mem_cons() << " B"); std::cout << stxxl::stats_data(*stxxl::stats::get_instance()) - sd_middle; std::cout << *stxxl::stats::get_instance(); assert(sum_input == sum_output); }
int main(int argc, char* argv[]) { typedef std::vector<std::pair<key_type, data_type> > vector_type; STXXL_MSG("Node block size: " << NODE_BLOCK_SIZE << " bytes"); STXXL_MSG("Leaf block size: " << LEAF_BLOCK_SIZE << " bytes"); STXXL_MSG("Node max elements: " << NODE_MELEMENTS); STXXL_MSG("Leaf max elements: " << LEAF_MELEMENTS); stxxl::random_number32 rnd; //stxxl::ran32State = 1141225706; STXXL_MSG("Init random seed: " << stxxl::ran32State); int a = (PERCENT_CLEAR + PERCENT_SIZING + PERCENT_ERASE_BULK + PERCENT_ERASE_KEY + PERCENT_ERASE_ITERATOR + PERCENT_INSERT_PAIR + PERCENT_INSERT_BULK + PERCENT_LOWER + PERCENT_UPPER + PERCENT_FIND + PERCENT_ITERATOR); STXXL_CHECK(a == 1000); if (argc < 2) { STXXL_MSG("Usage: " << argv[0] << " STEP "); STXXL_MSG("Note, that STEP must be > 1000"); return -1; } stxxl::uint64 MAX_STEP = atoi(argv[1]); STXXL_CHECK(MAX_STEP > 1000); std_map_type stdmap; xxl_map_type xxlmap(NODE_BLOCK_SIZE * 4, LEAF_BLOCK_SIZE * 3); for (stxxl::uint64 i = 0; i < MAX_STEP; i++) { // *************************************************** // A random number is created to determine which kind // of operation we will be called. // *************************************************** long step = rnd() % 1000; int percent = 0; if (i % (MAX_STEP / 100) == 0) { STXXL_MSG("Step=" << i << " (" << (unsigned)stdmap.size() << ")"); } // ********************************************************* // The clear function will be called // ********************************************************* if (step < (percent += PERCENT_CLEAR)) { if ((unsigned)rand() % 1000 < stdmap.size()) { stdmap.clear(); xxlmap.clear(); STXXL_CHECK(stdmap.empty()); STXXL_CHECK(xxlmap.empty()); } } // ********************************************************* // The size function will be called // ********************************************************* else if (step < (percent += PERCENT_SIZING)) { std_map_type::size_type size1 = stdmap.size(); xxl_map_type::size_type size2 = xxlmap.size(); STXXL_CHECK(size1 == size2); } // ********************************************************* // The erase range function will be called // ********************************************************* else if (step < (percent += PERCENT_ERASE_BULK)) { key_type key1 = rand() % MAX_KEY; key_type key2 = rand() % MAX_KEY; if (key1 > key2) { std::swap(key1, key2); } stdmap.erase(stdmap.lower_bound(key1), stdmap.upper_bound(key2)); xxlmap.erase(xxlmap.lower_bound(key1), xxlmap.upper_bound(key2)); STXXL_CHECK(stdmap.size() == xxlmap.size()); STXXL_CHECK(stdmap.lower_bound(key1) == stdmap.end() || stdmap.lower_bound(key1) == stdmap.upper_bound(key2)); STXXL_CHECK(xxlmap.lower_bound(key1) == xxlmap.end() || xxlmap.lower_bound(key1) == xxlmap.upper_bound(key2)); } // ********************************************************* // The erase a key function will be called // ********************************************************* else if (step < (percent += PERCENT_ERASE_KEY)) { key_type key = rnd() % MAX_KEY; stdmap.erase(key); xxlmap.erase(key); STXXL_CHECK(stxxl::not_there(stdmap, key)); STXXL_CHECK(stxxl::not_there(xxlmap, key)); } // ********************************************************* // The erase function will be called // ********************************************************* else if (step < (percent += PERCENT_ERASE_ITERATOR)) { key_type key = rnd() % MAX_KEY; std_map_type::iterator stditer = stdmap.find(key); xxl_map_type::iterator xxliter = xxlmap.find(key); STXXL_CHECK(stxxl::is_end(stdmap, stditer) == is_end(xxlmap, xxliter)); if (stditer != stdmap.end()) stdmap.erase(stditer); if (xxliter != xxlmap.end()) xxlmap.erase(xxliter); STXXL_CHECK(stxxl::not_there(stdmap, key)); STXXL_CHECK(stxxl::not_there(xxlmap, key)); } // ********************************************************* // The insert function will be called // ********************************************************* else if (step < (percent += PERCENT_INSERT_PAIR)) { key_type key = rnd() % MAX_KEY; stdmap.insert(std::pair<key_type, data_type>(key, 2 * key)); xxlmap.insert(std::pair<key_type, data_type>(key, 2 * key)); STXXL_CHECK(stxxl::there(stdmap, key, 2 * key)); STXXL_CHECK(stxxl::there(xxlmap, key, 2 * key)); } // ********************************************************* // The bulk insert function will be called // ********************************************************* else if (step < (percent += PERCENT_INSERT_BULK)) { unsigned lower = rnd() % MAX_KEY; unsigned upper = rnd() % MAX_KEY; if (lower > upper) std::swap(lower, upper); vector_type v2(upper - lower); for (unsigned j = 0; j < (unsigned)(upper - lower); j++) { v2[j].first = lower + j; v2[j].second = 2 * v2[j].first; } stdmap.insert(v2.begin(), v2.end()); xxlmap.insert(v2.begin(), v2.end()); for (unsigned i = lower; i < upper; i++) STXXL_CHECK(stxxl::there(stdmap, i, 2 * i)); for (unsigned i = lower; i < upper; i++) STXXL_CHECK(stxxl::there(xxlmap, i, 2 * i)); } // ********************************************************* // The lower_bound function will be called // ********************************************************* else if (step < (percent += PERCENT_LOWER)) { key_type key1 = rand() % MAX_KEY; key_type key2 = rand() % MAX_KEY; if (key1 > key2) { std::swap(key1, key2); } while (key1 < key2) { std_map_type::iterator stditer = stdmap.lower_bound(key1); xxl_map_type::iterator xxliter = xxlmap.lower_bound(key1); STXXL_CHECK(stxxl::is_end(stdmap, stditer) == is_end(xxlmap, xxliter)); if (!stxxl::is_end(stdmap, stditer)) { STXXL_CHECK(stxxl::is_same(*(stditer), *(xxliter))); } key1++; } } // ********************************************************* // The upper_bound function will be called // ********************************************************* else if (step < (percent += PERCENT_UPPER)) { key_type key1 = rand() % MAX_KEY; key_type key2 = rand() % MAX_KEY; if (key1 > key2) { std::swap(key1, key2); } while (key1 < key2) { std_map_type::iterator stditer = stdmap.upper_bound(key1); xxl_map_type::iterator xxliter = xxlmap.upper_bound(key1); STXXL_CHECK(stxxl::is_end(stdmap, stditer) == is_end(xxlmap, xxliter)); if (!stxxl::is_end(stdmap, stditer)) { STXXL_CHECK(stxxl::is_same(*(stditer), *(xxliter))); } key1++; } } // ********************************************************* // The find function will be called // ********************************************************* else if (step < (percent += PERCENT_FIND)) { key_type key1 = rand() % MAX_KEY; key_type key2 = rand() % MAX_KEY; if (key1 > key2) { std::swap(key1, key2); } while (key1 < key2) { std_map_type::iterator stditer = stdmap.find(key1); xxl_map_type::iterator xxliter = xxlmap.find(key1); STXXL_CHECK(stxxl::is_end(stdmap, stditer) == stxxl::is_end(xxlmap, xxliter)); if (!stxxl::is_end(stdmap, stditer)) { STXXL_CHECK(stxxl::is_same(*(stditer), *(xxliter))); } key1++; } } // ********************************************************* // The iterate functions will be called // ********************************************************* else if (step < (percent += PERCENT_ITERATOR)) { std_map_type::const_iterator siter1 = stdmap.begin(); xxl_map_type::const_iterator xiter1 = xxlmap.begin(); std_map_type::const_iterator siter2 = siter1; xxl_map_type::const_iterator xiter2 = xiter1; while (siter1 != stdmap.end()) { STXXL_CHECK(xiter1 != xxlmap.end()); STXXL_CHECK(stxxl::is_same(*(siter1++), *(xiter1++))); if (siter1 != stdmap.end()) { STXXL_CHECK(!stxxl::is_same(*siter1, *siter2)); } if (xiter1 != xxlmap.end()) { STXXL_CHECK(!stxxl::is_same(*xiter1, *xiter2)); } } STXXL_CHECK(xiter1 == xxlmap.end()); STXXL_CHECK(siter2 == stdmap.begin()); STXXL_CHECK(xiter2 == xxlmap.begin()); } } return 0; }
void operator () (stxxl::request* req) { STXXL_MSG(req << " done, type=" << req->io_type()); }