source: tests/concurrency/barrier/order.cfa @ b5f1e850

Last change on this file since b5f1e850 was b5f1e850, checked in by Peter A. Buhr <pabuhr@…>, 6 days ago

update barrier test programs after changes

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[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//
[b5f1e850]7// order.cfa -- validates barrier return value from barrier block
[93b8cf4]8//
9// Author           : Thierry Delisle
10// Created On       : Fri Apr 01 11:39:09 2022
[b5f1e850]11// Last Modified By : Peter A. Buhr
12// Last Modified On : Sun Nov 10 11:22:56 2024
13// Update Count     : 20
[93b8cf4]14//
15
16#include <concurrency/barrier.hfa>
17#include <fstream.hfa>
18#include <mutex_stmt.hfa>
19#include <thread.hfa>
20
[b5f1e850]21enum { NUM_LAPS = 173, NUM_THREADS = 11 };
[93b8cf4]22
23barrier bar = { NUM_THREADS };
[31ef267]24
[b5f1e850]25volatile unsigned generation = 0;                                               // count laps
26void last() {
27        generation += 1;                                                                        // last thread at barrier advances
28}
29volatile unsigned * generations;                                                // global array pointer
[93b8cf4]30
31thread Tester {};
[5b7fea7]32void main( Tester & this ) {
[b5f1e850]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
[93b8cf4]43}
44
45int main() {
[31ef267]46        volatile unsigned gen_data[NUM_THREADS];
[b5f1e850]47        for( t; NUM_THREADS ) gen_data[t] = 0;
48        generations = gen_data;                                                         // global points at local
[93b8cf4]49
[b5f1e850]50        processor p[4];                                                                         // parallelism
51        {                                                                                                       // run experiment
[93b8cf4]52                Tester testers[NUM_THREADS];
53        }
54        sout | "done";
[d2ad151]55}
Note: See TracBrowser for help on using the repository browser.