http://stxxl.sourceforge.net
<beckmann@cs.uni-frankfurt.de>
http://www.boost.org/LICENSE_1_0.txt
#include <iostream>
#include <stxxl/mng>
#include <stxxl/bits/mng/prefetch_pool.h>
#include <stxxl/bits/mng/write_pool.h>
#define BLOCK_SIZE (1024 * 512)
struct MyType
{
int integer;
char chars[5];
};
typedef stxxl::typed_block<BLOCK_SIZE, MyType> block_type;
template class stxxl::typed_block<BLOCK_SIZE, MyType>;
template class stxxl::prefetch_pool<block_type>;
template class stxxl::write_pool<block_type>;
int main()
{
stxxl::block_manager* bm = stxxl::block_manager::get_instance();
STXXL_DEFAULT_ALLOC_STRATEGY alloc;
{
STXXL_MSG("Write-After-Write coherence test");
stxxl::prefetch_pool<block_type> p_pool(2);
stxxl::write_pool<block_type> w_pool(10);
block_type* blk;
block_type::bid_type bid;
bm->new_block(alloc, bid);
blk = w_pool.steal();
(*blk)[0].integer = 42;
w_pool.write(blk, bid);
blk = w_pool.steal();
p_pool.read(blk, bid)->wait();
delete blk;
blk = w_pool.steal();
(*blk)[0].integer = 23;
w_pool.write(blk, bid);
p_pool.hint(bid, w_pool);
blk = w_pool.steal();
p_pool.read(blk, bid)->wait();
STXXL_CHECK2((*blk)[0].integer == 23,
"WRITE-AFTER-WRITE COHERENCE FAILURE");
w_pool.add(blk);
bm->delete_block(bid);
}
{
STXXL_MSG("Write-After-Hint coherence test #1");
stxxl::prefetch_pool<block_type> p_pool(1);
stxxl::write_pool<block_type> w_pool(1);
block_type* blk;
block_type::bid_type bid;
bm->new_block(alloc, bid);
blk = w_pool.steal();
(*blk)[0].integer = 42;
w_pool.write(blk, bid);
blk = w_pool.steal();
p_pool.hint(bid);
(*blk)[0].integer = 23;
w_pool.write(blk, bid);
p_pool.invalidate(bid);
blk = w_pool.steal();
p_pool.read(blk, bid)->wait();
STXXL_CHECK2((*blk)[0].integer == 23,
"WRITE-AFTER-HINT COHERENCE FAILURE");
w_pool.add(blk);
bm->delete_block(bid);
}
{
STXXL_MSG("Write-After-Hint coherence test #2");
stxxl::prefetch_pool<block_type> p_pool(1);
stxxl::write_pool<block_type> w_pool(1);
block_type* blk;
block_type::bid_type bid;
bm->new_block(alloc, bid);
blk = w_pool.steal();
(*blk)[0].integer = 42;
w_pool.write(blk, bid);
p_pool.hint(bid, w_pool);
blk = w_pool.steal();
(*blk)[0].integer = 23;
w_pool.write(blk, bid);
p_pool.invalidate(bid);
blk = w_pool.steal();
p_pool.read(blk, bid)->wait();
STXXL_CHECK2((*blk)[0].integer == 23,
"WRITE-AFTER-HINT COHERENCE FAILURE");
w_pool.add(blk);
bm->delete_block(bid);
}
return 0;
}