[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 | // |
---|
| 7 | // concurrent/barrier/order.cfa -- validates barriers the return value of |
---|
| 8 | // barrier block |
---|
| 9 | // |
---|
| 10 | // Author : Thierry Delisle |
---|
| 11 | // Created On : Fri Apr 01 11:39:09 2022 |
---|
| 12 | // Last Modified By : |
---|
| 13 | // Last Modified On : |
---|
| 14 | // Update Count : |
---|
| 15 | // |
---|
| 16 | |
---|
[31ef267] | 17 | // Test validates barrier and block return value by checking |
---|
| 18 | // that no more than one thread gets the same return value |
---|
| 19 | |
---|
[93b8cf4] | 20 | #include <concurrency/barrier.hfa> |
---|
| 21 | #include <fstream.hfa> |
---|
| 22 | #include <mutex_stmt.hfa> |
---|
| 23 | #include <thread.hfa> |
---|
| 24 | |
---|
[31ef267] | 25 | const unsigned NUM_LAPS = 173; |
---|
| 26 | const unsigned NUM_THREADS = 11; |
---|
[93b8cf4] | 27 | |
---|
[31ef267] | 28 | // The barrier we are testing |
---|
[93b8cf4] | 29 | barrier bar = { NUM_THREADS }; |
---|
[31ef267] | 30 | |
---|
| 31 | // The return values of the previous generation. |
---|
| 32 | volatile unsigned * generation; |
---|
[93b8cf4] | 33 | |
---|
| 34 | thread Tester {}; |
---|
[5b7fea7] | 35 | void main( Tester & this ) { |
---|
[31ef267] | 36 | // Repeat a few times |
---|
[93b8cf4] | 37 | for(l; NUM_LAPS) { |
---|
[5b7fea7] | 38 | // Yield for chaos |
---|
| 39 | yield(prng(this, 10)); |
---|
| 40 | |
---|
[31ef267] | 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? |
---|
[93b8cf4] | 48 | if(g != l) { |
---|
[31ef267] | 49 | // Complain that they are different |
---|
[93b8cf4] | 50 | sout | "Gen" | l | ": Expeced generation at" | ret | "to be" | l | "was" | g; |
---|
| 51 | } |
---|
[31ef267] | 52 | |
---|
| 53 | // Mark the expected next generation |
---|
| 54 | generation[ret] = l+1; |
---|
[93b8cf4] | 55 | } |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | int main() { |
---|
[31ef267] | 59 | // Create the data ans zero it. |
---|
| 60 | volatile unsigned gen_data[NUM_THREADS]; |
---|
[93b8cf4] | 61 | for(t; NUM_THREADS) |
---|
| 62 | gen_data[t] = 0; |
---|
| 63 | |
---|
| 64 | generation = gen_data; |
---|
| 65 | |
---|
[31ef267] | 66 | // Run the experiment |
---|
[93b8cf4] | 67 | processor p[4]; |
---|
| 68 | { |
---|
| 69 | Tester testers[NUM_THREADS]; |
---|
| 70 | } |
---|
| 71 | sout | "done"; |
---|
| 72 | } |
---|