ADT
ast-experimental
|
Last change
on this file since d40555e was 7bc84b8, checked in by Peter A. Buhr <pabuhr@…>, 3 years ago |
|
remove unsigned cast for prng calls
|
-
Property mode
set to
100644
|
|
File size:
1.3 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 | // 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 |
|
|---|
| 17 | // Test validates barrier by having each thread print ABCD...
|
|---|
| 18 | // If the barrier is correct it should print all As, all Bs, etc.
|
|---|
| 19 |
|
|---|
| 20 | unsigned NUM_THREADS = 9;
|
|---|
| 21 | unsigned NUM_LAPS = 53;
|
|---|
| 22 |
|
|---|
| 23 | #include <concurrency/barrier.hfa>
|
|---|
| 24 | #include <fstream.hfa>
|
|---|
| 25 | #include <mutex_stmt.hfa>
|
|---|
| 26 | #include <thread.hfa>
|
|---|
| 27 |
|
|---|
| 28 | // The barrier we are testing
|
|---|
| 29 | barrier bar = { NUM_THREADS };
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | thread Tester {};
|
|---|
| 33 | void main( Tester & this ) {
|
|---|
| 34 | // Repeat the experiment a few times
|
|---|
| 35 | for(NUM_LAPS)
|
|---|
| 36 | // For each letters
|
|---|
| 37 | for(c; 'A' ~= 'Z') {
|
|---|
| 38 | // Yield for chaos
|
|---|
| 39 | yield( prng(this, 10) );
|
|---|
| 40 |
|
|---|
| 41 | // Print the generation, no newline because
|
|---|
| 42 | mutex(sout) sout | c | nonl;
|
|---|
| 43 |
|
|---|
| 44 | // Yield again for more chaos
|
|---|
| 45 | yield( prng(this, 10) );
|
|---|
| 46 |
|
|---|
| 47 | // Block on the barrier
|
|---|
| 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.