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 | // order.cfa -- validates barrier return value from barrier block
|
---|
8 | //
|
---|
9 | // Author : Thierry Delisle
|
---|
10 | // Created On : Fri Apr 01 11:39:09 2022
|
---|
11 | // Last Modified By : Peter A. Buhr
|
---|
12 | // Last Modified On : Sun Nov 10 11:22:56 2024
|
---|
13 | // Update Count : 20
|
---|
14 | //
|
---|
15 |
|
---|
16 | #include <concurrency/barrier.hfa>
|
---|
17 | #include <fstream.hfa>
|
---|
18 | #include <mutex_stmt.hfa>
|
---|
19 | #include <thread.hfa>
|
---|
20 |
|
---|
21 | enum { NUM_LAPS = 173, NUM_THREADS = 11 };
|
---|
22 |
|
---|
23 | barrier bar = { NUM_THREADS };
|
---|
24 |
|
---|
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
|
---|
30 |
|
---|
31 | thread Tester {};
|
---|
32 | 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 |
|
---|
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
|
---|
43 | }
|
---|
44 |
|
---|
45 | int main() {
|
---|
46 | volatile unsigned gen_data[NUM_THREADS];
|
---|
47 | for( t; NUM_THREADS ) gen_data[t] = 0;
|
---|
48 | generations = gen_data; // global points at local
|
---|
49 |
|
---|
50 | processor p[4]; // parallelism
|
---|
51 | { // run experiment
|
---|
52 | Tester testers[NUM_THREADS];
|
---|
53 | }
|
---|
54 | sout | "done";
|
---|
55 | }
|
---|