Last change
on this file since 075c6d5 was
b2fa3c2,
checked in by Peter A. Buhr <pabuhr@…>, 18 months ago
|
fix comments referring to concurrency directory
|
-
Property mode set to
100644
|
File size:
1.2 KB
|
Line | |
---|
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 | // generation.cfa -- simple test that validates barriers by printing alphabetical generations |
---|
8 | // |
---|
9 | // Author : Thierry Delisle |
---|
10 | // Created On : Thu Mar 31 16:43:45 2022 |
---|
11 | // Last Modified By : |
---|
12 | // Last Modified On : |
---|
13 | // Update Count : |
---|
14 | // |
---|
15 | |
---|
16 | // Test validates barrier by having each thread print ABCD... |
---|
17 | // If the barrier is correct it should print all As, all Bs, etc. |
---|
18 | |
---|
19 | unsigned NUM_THREADS = 9; |
---|
20 | unsigned NUM_LAPS = 53; |
---|
21 | |
---|
22 | #include <concurrency/barrier.hfa> |
---|
23 | #include <fstream.hfa> |
---|
24 | #include <mutex_stmt.hfa> |
---|
25 | #include <thread.hfa> |
---|
26 | |
---|
27 | // The barrier we are testing |
---|
28 | barrier bar = { NUM_THREADS }; |
---|
29 | |
---|
30 | |
---|
31 | thread Tester {}; |
---|
32 | void main( Tester & this ) { |
---|
33 | // Repeat the experiment a few times |
---|
34 | for(NUM_LAPS) |
---|
35 | // For each letters |
---|
36 | for(c; 'A' ~= 'Z') { |
---|
37 | // Yield for chaos |
---|
38 | yield( prng(this, 10) ); |
---|
39 | |
---|
40 | // Print the generation, no newline because |
---|
41 | mutex(sout) sout | c | nonl; |
---|
42 | |
---|
43 | // Yield again for more chaos |
---|
44 | yield( prng(this, 10) ); |
---|
45 | |
---|
46 | // Block on the barrier |
---|
47 | block(bar); |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | int main() { |
---|
52 | processor p[4]; |
---|
53 | { |
---|
54 | Tester testers[NUM_THREADS]; |
---|
55 | } |
---|
56 | sout | nl; |
---|
57 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.