Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/concurrency/barrier/order.cfa

    rb5f1e850 rb2fa3c2  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // order.cfa -- validates barrier return value from barrier block
     7// order.cfa -- validates barriers the return value of
     8//                                 barrier block
    89//
    910// Author           : Thierry Delisle
    1011// 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
     12// Last Modified By :
     13// Last Modified On :
     14// Update Count     :
    1415//
     16
     17// Test validates barrier and block return value by checking
     18// that no more than one thread gets the same return value
    1519
    1620#include <concurrency/barrier.hfa>
     
    1923#include <thread.hfa>
    2024
    21 enum { NUM_LAPS = 173, NUM_THREADS = 11 };
     25const unsigned NUM_LAPS = 173;
     26const unsigned NUM_THREADS = 11;
    2227
     28// The barrier we are testing
    2329barrier bar = { NUM_THREADS };
    2430
    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
     31// The return values of the previous generation.
     32volatile unsigned * generation;
    3033
    3134thread Tester {};
    3235void 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        // Repeat a few times
     37        for(l; NUM_LAPS) {
     38                // Yield for chaos
     39                yield( prng(this, 10) );
    3640
    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
     41                // Block and what order we arrived
     42                unsigned ret = block(bar);
     43
     44                // Check what was the last generation of that last thread in this position
     45                unsigned g = generation[ret];
     46
     47                // Is it what we expect?
     48                if(g != l) {
     49                        // Complain that they are different
     50                        sout | "Gen" | l | ": Expeced generation at" | ret | "to be" | l | "was" | g;
     51                }
     52
     53                // Mark the expected next generation
     54                generation[ret] = l+1;
     55        }
    4356}
    4457
    4558int main() {
     59        // Create the data ans zero it.
    4660        volatile unsigned gen_data[NUM_THREADS];
    47         for( t; NUM_THREADS ) gen_data[t] = 0;
    48         generations = gen_data;                                                         // global points at local
     61        for(t; NUM_THREADS)
     62                gen_data[t] = 0;
    4963
    50         processor p[4];                                                                         // parallelism
    51         {                                                                                                       // run experiment
     64        generation = gen_data;
     65
     66        // Run the experiment
     67        processor p[4];
     68        {
    5269                Tester testers[NUM_THREADS];
    5370        }
Note: See TracChangeset for help on using the changeset viewer.