Changeset b5f1e850
- Timestamp:
- Nov 11, 2024, 10:33:51 PM (10 days ago)
- Branches:
- master
- Children:
- 0cb3479
- Parents:
- a3af522
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/concurrency/barrier/order.cfa
ra3af522 rb5f1e850 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // order.cfa -- validates barriers the return value of 8 // barrier block 7 // order.cfa -- validates barrier return value from barrier block 9 8 // 10 9 // Author : Thierry Delisle 11 10 // Created On : Fri Apr 01 11:39:09 2022 12 // Last Modified By : 13 // Last Modified On : 14 // Update Count : 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Sun Nov 10 11:22:56 2024 13 // Update Count : 20 15 14 // 16 17 // Test validates barrier and block return value by checking18 // that no more than one thread gets the same return value19 15 20 16 #include <concurrency/barrier.hfa> … … 23 19 #include <thread.hfa> 24 20 25 const unsigned NUM_LAPS = 173; 26 const unsigned NUM_THREADS = 11; 21 enum { NUM_LAPS = 173, NUM_THREADS = 11 }; 27 22 28 // The barrier we are testing29 23 barrier bar = { NUM_THREADS }; 30 24 31 // The return values of the previous generation. 32 volatile unsigned * generation; 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 33 30 34 31 thread Tester {}; 35 32 void main( Tester & this ) { 36 // Repeat a few times 37 for(l; NUM_LAPS) { 38 // Yield for chaos 39 yield( prng(this, 10) ); 33 for ( l; NUM_LAPS ) { 34 yield( prng( this, 10 ) ); // yield for chaos 35 unsigned int order = block( bar, last ); // block at barrier 40 36 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 } 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 56 43 } 57 44 58 45 int main() { 59 // Create the data ans zero it.60 46 volatile unsigned gen_data[NUM_THREADS]; 61 for( t; NUM_THREADS)62 gen_data[t] = 0;47 for( t; NUM_THREADS ) gen_data[t] = 0; 48 generations = gen_data; // global points at local 63 49 64 generation = gen_data; 65 66 // Run the experiment 67 processor p[4]; 68 { 50 processor p[4]; // parallelism 51 { // run experiment 69 52 Tester testers[NUM_THREADS]; 70 53 }
Note: See TracChangeset
for help on using the changeset viewer.