Changeset b5f1e850 for tests/concurrency


Ignore:
Timestamp:
Nov 11, 2024, 10:33:51 PM (5 weeks ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
0cb3479
Parents:
a3af522
Message:

update barrier test programs after changes

File:
1 edited

Legend:

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

    ra3af522 rb5f1e850  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // order.cfa -- validates barriers the return value of
    8 //                                 barrier block
     7// order.cfa -- validates barrier return value from barrier block
    98//
    109// Author           : Thierry Delisle
    1110// Created On       : Fri Apr 01 11:39:09 2022
    12 // Last Modified By :
    13 // Last Modified On :
    14 // Update Count     :
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Sun Nov 10 11:22:56 2024
     13// Update Count     : 20
    1514//
    16 
    17 // Test validates barrier and block return value by checking
    18 // that no more than one thread gets the same return value
    1915
    2016#include <concurrency/barrier.hfa>
     
    2319#include <thread.hfa>
    2420
    25 const unsigned NUM_LAPS = 173;
    26 const unsigned NUM_THREADS = 11;
     21enum { NUM_LAPS = 173, NUM_THREADS = 11 };
    2722
    28 // The barrier we are testing
    2923barrier bar = { NUM_THREADS };
    3024
    31 // The return values of the previous generation.
    32 volatile unsigned * generation;
     25volatile unsigned generation = 0;                                               // count laps
     26void last() {
     27        generation += 1;                                                                        // last thread at barrier advances
     28}
     29volatile unsigned * generations;                                                // global array pointer
    3330
    3431thread Tester {};
    3532void main( Tester & this ) {
    36         // Repeat a few times
    37         for(l; NUM_LAPS) {
    38                 // Yield for chaos
    39                 yield( prng(this, 10) );
     33        for ( l; NUM_LAPS ) {
     34                yield( prng( this, 10 ) );                                              // yield for chaos
     35                unsigned int order = block( bar, last );                // block at barrier
    4036
    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         }
     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
    5643}
    5744
    5845int main() {
    59         // Create the data ans zero it.
    6046        volatile unsigned gen_data[NUM_THREADS];
    61         for(t; NUM_THREADS)
    62                 gen_data[t] = 0;
     47        for( t; NUM_THREADS ) gen_data[t] = 0;
     48        generations = gen_data;                                                         // global points at local
    6349
    64         generation = gen_data;
    65 
    66         // Run the experiment
    67         processor p[4];
    68         {
     50        processor p[4];                                                                         // parallelism
     51        {                                                                                                       // run experiment
    6952                Tester testers[NUM_THREADS];
    7053        }
Note: See TracChangeset for help on using the changeset viewer.