Stxxl  1.4.0
algo/test_asch.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *  algo/test_asch.cpp
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2002 Roman Dementiev <dementiev@mpi-sb.mpg.de>
00007  *  Copyright (C) 2009 Andreas Beckmann <beckmann@cs.uni-frankfurt.de>
00008  *
00009  *  Distributed under the Boost Software License, Version 1.0.
00010  *  (See accompanying file LICENSE_1_0.txt or copy at
00011  *  http://www.boost.org/LICENSE_1_0.txt)
00012  **************************************************************************/
00013 
00014 #include <cstdlib>
00015 #include <stxxl/bits/algo/async_schedule.h>
00016 #include <stxxl/bits/verbose.h>
00017 #include <stxxl/random>
00018 
00019 // Test async schedule algorithm
00020 
00021 
00022 int main(int argc, char * argv[])
00023 {
00024     if (argc < 5)
00025     {
00026         STXXL_ERRMSG("Usage: " << argv[0] << " D L m seed");
00027         return -1;
00028     }
00029     int i;
00030     const stxxl::int_type D = atoi(argv[1]);
00031     const stxxl::int_type L = atoi(argv[2]);
00032     const stxxl::int_type m = atoi(argv[3]);
00033     stxxl::ran32State = atoi(argv[4]);
00034     stxxl::int_type * disks = new stxxl::int_type[L];
00035     stxxl::int_type * prefetch_order = new stxxl::int_type[L];
00036     int * count = new int[D];
00037 
00038 
00039     for (i = 0; i < D; i++)
00040         count[i] = 0;
00041 
00042 
00043     stxxl::random_number<> rnd;
00044     for (i = 0; i < L; i++)
00045     {
00046         disks[i] = rnd(D);
00047         count[disks[i]]++;
00048     }
00049 
00050     for (i = 0; i < D; i++)
00051         std::cout << "Disk " << i << " has " << count[i] << " blocks" << std::endl;
00052 
00053     stxxl::compute_prefetch_schedule(disks, disks + L, prefetch_order, m, D);
00054 
00055     STXXL_MSG("Prefetch order:");
00056     for (i = 0; i < L; ++i) {
00057         STXXL_MSG("request " << prefetch_order[i] << "  on disk " << disks[prefetch_order[i]]);
00058     }
00059     STXXL_MSG("Request order:");
00060     for (i = 0; i < L; ++i) {
00061         int j;
00062         for (j = 0; prefetch_order[j] != i; ++j) ;
00063         STXXL_MSG("request " << i << "  on disk " << disks[i] << "  scheduled as " << j);
00064     }
00065 
00066     delete[] count;
00067     delete[] disks;
00068     delete[] prefetch_order;
00069 }
00070 
00071 // vim: et:ts=4:sw=4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines