// // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // order.cfa -- validates barrier return value from barrier block // // Author : Thierry Delisle // Created On : Fri Apr 01 11:39:09 2022 // Last Modified By : Peter A. Buhr // Last Modified On : Sun Nov 10 11:22:56 2024 // Update Count : 20 // #include #include #include #include enum { NUM_LAPS = 173, NUM_THREADS = 11 }; barrier bar = { NUM_THREADS }; volatile unsigned generation = 0; // count laps void last() { generation += 1; // last thread at barrier advances } volatile unsigned * generations; // global array pointer thread Tester {}; void main( Tester & this ) { for ( l; NUM_LAPS ) { yield( prng( this, 10 ) ); // yield for chaos unsigned int order = block( bar, last ); // block at barrier // For G == T, no thread should be able to advance generation until current generation finishes. if ( generation - 1 != l || generations[order] != l ) { // generation advanced in block mutex( sout ) sout | "mismatched generation, expected" | l | "got" | generation; } // if generations[order] = l + 1; // every thread advances their current order generation } // for } int main() { volatile unsigned gen_data[NUM_THREADS]; for( t; NUM_THREADS ) gen_data[t] = 0; generations = gen_data; // global points at local processor p[4]; // parallelism { // run experiment Tester testers[NUM_THREADS]; } sout | "done"; }