Changeset e4c3819


Ignore:
Timestamp:
Sep 19, 2023, 10:26:17 AM (7 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
master
Children:
60f69f0
Parents:
a2c2363
Message:

refactor cofor.hfa into cofor.cfa, adjust Makefile.am to handle cofor.cfa

Files:
1 added
2 edited
2 moved

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    ra2c2363 re4c3819  
    1111## Created On       : Sun May 31 08:54:01 2015
    1212## Last Modified By : Peter A. Buhr
    13 ## Last Modified On : Wed Aug 30 21:22:45 2023
    14 ## Update Count     : 263
     13## Last Modified On : Mon Sep 18 17:06:56 2023
     14## Update Count     : 264
    1515###############################################################################
    1616
     
    118118        concurrency/mutex_stmt.hfa \
    119119        concurrency/channel.hfa \
    120         concurrency/actor.hfa \
    121     concurrency/cofor.hfa
     120        concurrency/actor.hfa
    122121
    123122inst_thread_headers_src = \
     
    131130        concurrency/mutex.hfa \
    132131        concurrency/select.hfa \
    133         concurrency/thread.hfa
     132        concurrency/thread.hfa \
     133        concurrency/cofor.hfa
    134134
    135135thread_libsrc = ${inst_thread_headers_src} ${inst_thread_headers_src:.hfa=.cfa} \
  • libcfa/src/concurrency/cofor.hfa

    ra2c2363 re4c3819  
    33//////////////////////////////////////////////////////////////////////////////////////////
    44// cofor ( uC++ COFOR )
    5 typedef void (*cofor_body_t)( long );
    6 thread co_runner {
    7     long lo, hi;
    8     cofor_body_t loop_body;
    9 };
     5typedef void (*__cofor_body_t)( ssize_t );
    106
    11 void ?{}( co_runner & this, long lo, long hi, cofor_body_t loop_body ) {
    12     this.lo = lo;
    13     this.hi = hi;
    14     this.loop_body = loop_body;
    15 }
     7void cofor( ssize_t low, ssize_t high, __cofor_body_t loop_body );
    168
    17 void main( co_runner & this ) with( this ) {
    18     for ( long i = lo; i < hi; i++ )
    19         loop_body(i);
    20 }
    21 
    22 void cofor( long lo, long hi, cofor_body_t loop_body ) {
    23     long range = hi - lo;
    24     if ( range <= 0 ) return;
    25     long nprocs = get_proc_count( *active_cluster() );
    26     if ( nprocs == 0 ) return;
    27     long threads = range < nprocs ? range : nprocs;
    28     long stride = range / threads + 1, extras = range % threads;
    29     long i = 0;
    30     long stride_iter = lo;
    31     co_runner * runners[ threads ];
    32     for ( i; threads ) {
    33         runners[i] = alloc();
    34     }
    35     for ( i = 0; i < extras; i += 1, stride_iter += stride ) {
    36         (*runners[i]){ stride_iter, stride_iter + stride, loop_body };
    37     }
    38     stride -= 1;
    39     for ( ; i < threads; i += 1, stride_iter += stride ) {
    40         (*runners[i]){ stride_iter, stride_iter + stride, loop_body };
    41     }
    42     for ( i; threads ) {
    43         delete( runners[i] );
    44     }
    45 }
    46 
    47 #define COFOR( lidname, low, high, body ) \
    48     { \
    49         void loopBody( long lidname ) { \
    50             body \
    51         } \
    52         cofor( low, high, loopBody ); \
    53     }
     9#define COFOR( lidname, low, high, loopbody ) \
     10        { \
     11                void __CFA_loopLambda__( ssize_t lidname ) { \
     12                        loopbody \
     13                } \
     14                cofor( low, high, __CFA_loopLambda__ ); \
     15        }
    5416
    5517//////////////////////////////////////////////////////////////////////////////////////////
    5618// parallel (COBEGIN/COEND)
    5719typedef void (*parallel_stmt_t)( void * );
    58 thread para_runner {
    59     parallel_stmt_t body;
    60     void * arg;
    61 };
    6220
    63 void ?{}( para_runner & this, parallel_stmt_t body, void * arg ) {
    64     this.body = body;
    65     this.arg = arg;
    66 }
    67 
    68 void main( para_runner & this ) with( this ) { body( arg ); }
    69 
    70 void parallel( parallel_stmt_t * stmts, void ** args, size_t num ) {
    71     para_runner * runners[ num ];
    72     for ( i; num )
    73         (*(runners[i] = malloc())){ stmts[i], args[i] };
    74     for ( i; num )
    75         delete( runners[i] );
    76 }
    77 
     21void parallel( parallel_stmt_t * stmts, void ** args, size_t num );
Note: See TracChangeset for help on using the changeset viewer.