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