[93b8cf4] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
[b5f1e850] | 7 | // order.cfa -- validates barrier return value from barrier block |
---|
[93b8cf4] | 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Fri Apr 01 11:39:09 2022 |
---|
[b5f1e850] | 11 | // Last Modified By : Peter A. Buhr |
---|
| 12 | // Last Modified On : Sun Nov 10 11:22:56 2024 |
---|
| 13 | // Update Count : 20 |
---|
[93b8cf4] | 14 | // |
---|
| 15 | |
---|
| 16 | #include <concurrency/barrier.hfa> |
---|
| 17 | #include <fstream.hfa> |
---|
| 18 | #include <mutex_stmt.hfa> |
---|
| 19 | #include <thread.hfa> |
---|
| 20 | |
---|
[b5f1e850] | 21 | enum { NUM_LAPS = 173, NUM_THREADS = 11 }; |
---|
[93b8cf4] | 22 | |
---|
| 23 | barrier bar = { NUM_THREADS }; |
---|
[31ef267] | 24 | |
---|
[b5f1e850] | 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 |
---|
[93b8cf4] | 30 | |
---|
| 31 | thread Tester {}; |
---|
[5b7fea7] | 32 | void main( Tester & this ) { |
---|
[b5f1e850] | 33 | for ( l; NUM_LAPS ) { |
---|
| 34 | yield( prng( this, 10 ) ); // yield for chaos |
---|
| 35 | unsigned int order = block( bar, last ); // block at barrier |
---|
| 36 | |
---|
| 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 |
---|
[93b8cf4] | 43 | } |
---|
| 44 | |
---|
| 45 | int main() { |
---|
[31ef267] | 46 | volatile unsigned gen_data[NUM_THREADS]; |
---|
[b5f1e850] | 47 | for( t; NUM_THREADS ) gen_data[t] = 0; |
---|
| 48 | generations = gen_data; // global points at local |
---|
[93b8cf4] | 49 | |
---|
[b5f1e850] | 50 | processor p[4]; // parallelism |
---|
| 51 | { // run experiment |
---|
[93b8cf4] | 52 | Tester testers[NUM_THREADS]; |
---|
| 53 | } |
---|
| 54 | sout | "done"; |
---|
[d2ad151] | 55 | } |
---|