- File:
-
- 1 edited
-
tests/concurrency/barrier/order.cfa (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/barrier/order.cfa
rb5f1e850 rb2fa3c2 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // order.cfa -- validates barrier return value from barrier block 7 // order.cfa -- validates barriers the return value of 8 // barrier block 8 9 // 9 10 // Author : Thierry Delisle 10 11 // Created On : Fri Apr 01 11:39:09 2022 11 // Last Modified By : Peter A. Buhr12 // Last Modified On : Sun Nov 10 11:22:56 202413 // Update Count : 2012 // Last Modified By : 13 // Last Modified On : 14 // Update Count : 14 15 // 16 17 // Test validates barrier and block return value by checking 18 // that no more than one thread gets the same return value 15 19 16 20 #include <concurrency/barrier.hfa> … … 19 23 #include <thread.hfa> 20 24 21 enum { NUM_LAPS = 173, NUM_THREADS = 11 }; 25 const unsigned NUM_LAPS = 173; 26 const unsigned NUM_THREADS = 11; 22 27 28 // The barrier we are testing 23 29 barrier bar = { NUM_THREADS }; 24 30 25 volatile unsigned generation = 0; // count laps 26 void last() { 27 generation += 1; // last thread at barrier advances 28 } 29 volatile unsigned * generations; // global array pointer 31 // The return values of the previous generation. 32 volatile unsigned * generation; 30 33 31 34 thread Tester {}; 32 35 void main( Tester & this ) { 33 for ( l; NUM_LAPS ) { 34 yield( prng( this, 10 ) ); // yield for chaos 35 unsigned int order = block( bar, last ); // block at barrier 36 // Repeat a few times 37 for(l; NUM_LAPS) { 38 // Yield for chaos 39 yield( prng(this, 10) ); 36 40 37 // For G == T, no thread should be able to advance generation until current generation finishes. 38 if ( generation - 1 != l || generations[order] != l ) { // generation advanced in block 39 mutex( sout ) sout | "mismatched generation, expected" | l | "got" | generation; 40 } // if 41 generations[order] = l + 1; // every thread advances their current order generation 42 } // for 41 // Block and what order we arrived 42 unsigned ret = block(bar); 43 44 // Check what was the last generation of that last thread in this position 45 unsigned g = generation[ret]; 46 47 // Is it what we expect? 48 if(g != l) { 49 // Complain that they are different 50 sout | "Gen" | l | ": Expeced generation at" | ret | "to be" | l | "was" | g; 51 } 52 53 // Mark the expected next generation 54 generation[ret] = l+1; 55 } 43 56 } 44 57 45 58 int main() { 59 // Create the data ans zero it. 46 60 volatile unsigned gen_data[NUM_THREADS]; 47 for( t; NUM_THREADS ) gen_data[t] = 0;48 generations = gen_data; // global points at local61 for(t; NUM_THREADS) 62 gen_data[t] = 0; 49 63 50 processor p[4]; // parallelism 51 { // run experiment 64 generation = gen_data; 65 66 // Run the experiment 67 processor p[4]; 68 { 52 69 Tester testers[NUM_THREADS]; 53 70 }
Note:
See TracChangeset
for help on using the changeset viewer.