Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * mng/test_pool_pair.cpp 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2009 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00007 * 00008 * Distributed under the Boost Software License, Version 1.0. 00009 * (See accompanying file LICENSE_1_0.txt or copy at 00010 * http://www.boost.org/LICENSE_1_0.txt) 00011 **************************************************************************/ 00012 00013 //! \example mng/test_pool_pair.cpp 00014 00015 #include <iostream> 00016 #include <stxxl/mng> 00017 #include <stxxl/bits/mng/prefetch_pool.h> 00018 #include <stxxl/bits/mng/write_pool.h> 00019 00020 #define BLOCK_SIZE (1024 * 512) 00021 00022 struct MyType 00023 { 00024 int integer; 00025 char chars[5]; 00026 }; 00027 00028 typedef stxxl::typed_block<BLOCK_SIZE, MyType> block_type; 00029 00030 int main() 00031 { 00032 stxxl::block_manager * bm = stxxl::block_manager::get_instance(); 00033 STXXL_DEFAULT_ALLOC_STRATEGY alloc; 00034 00035 { 00036 STXXL_MSG("Write-After-Write coherence test"); 00037 stxxl::prefetch_pool<block_type> p_pool(2); 00038 stxxl::write_pool<block_type> w_pool(10); 00039 block_type * blk; 00040 block_type::bid_type bid; 00041 00042 bm->new_block(alloc, bid); 00043 00044 // write the block for the first time 00045 blk = w_pool.steal(); 00046 (*blk)[0].integer = 42; 00047 w_pool.write(blk, bid); 00048 00049 // read the block 00050 blk = w_pool.steal(); 00051 p_pool.read(blk, bid)->wait(); 00052 delete blk; 00053 00054 // write the block for the second time 00055 blk = w_pool.steal(); 00056 (*blk)[0].integer = 23; 00057 w_pool.write(blk, bid); 00058 00059 // hint the block 00060 p_pool.hint(bid, w_pool); // flush w_pool 00061 00062 // get the hinted block 00063 blk = w_pool.steal(); 00064 p_pool.read(blk, bid)->wait(); 00065 00066 if ((*blk)[0].integer != 23) { 00067 STXXL_ERRMSG("WRITE-AFTER-WRITE COHERENCE FAILURE"); 00068 } 00069 00070 w_pool.add(blk); 00071 bm->delete_block(bid); 00072 } 00073 00074 { 00075 STXXL_MSG("Write-After-Hint coherence test #1"); 00076 stxxl::prefetch_pool<block_type> p_pool(1); 00077 stxxl::write_pool<block_type> w_pool(1); 00078 block_type * blk; 00079 block_type::bid_type bid; 00080 00081 bm->new_block(alloc, bid); 00082 blk = w_pool.steal(); 00083 (*blk)[0].integer = 42; 00084 w_pool.write(blk, bid); 00085 blk = w_pool.steal(); // flush w_pool 00086 00087 // hint the block 00088 p_pool.hint(bid); 00089 00090 // update the hinted block 00091 (*blk)[0].integer = 23; 00092 w_pool.write(blk, bid); 00093 p_pool.invalidate(bid); 00094 blk = w_pool.steal(); // flush w_pool 00095 00096 // get the hinted block 00097 p_pool.read(blk, bid)->wait(); 00098 00099 if ((*blk)[0].integer != 23) { 00100 STXXL_ERRMSG("WRITE-AFTER-HINT COHERENCE FAILURE"); 00101 } 00102 00103 w_pool.add(blk); 00104 bm->delete_block(bid); 00105 } 00106 00107 { 00108 STXXL_MSG("Write-After-Hint coherence test #2"); 00109 stxxl::prefetch_pool<block_type> p_pool(1); 00110 stxxl::write_pool<block_type> w_pool(1); 00111 block_type * blk; 00112 block_type::bid_type bid; 00113 00114 bm->new_block(alloc, bid); 00115 blk = w_pool.steal(); 00116 (*blk)[0].integer = 42; 00117 w_pool.write(blk, bid); 00118 00119 // hint the block 00120 p_pool.hint(bid, w_pool); // flush w_pool 00121 00122 // update the hinted block 00123 blk = w_pool.steal(); 00124 (*blk)[0].integer = 23; 00125 w_pool.write(blk, bid); 00126 p_pool.invalidate(bid); 00127 blk = w_pool.steal(); // flush w_pool 00128 00129 // get the hinted block 00130 p_pool.read(blk, bid)->wait(); 00131 00132 if ((*blk)[0].integer != 23) { 00133 STXXL_ERRMSG("WRITE-AFTER-HINT COHERENCE FAILURE"); 00134 } 00135 00136 w_pool.add(blk); 00137 bm->delete_block(bid); 00138 } 00139 } 00140 // vim: et:ts=4:sw=4