Last change
on this file since fbb5bdd was ba0e1bc, checked in by caparson <caparson@…>, 23 months ago |
Added supporting library routines for cofor impl
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Rev | Line | |
---|
[e4c3819] | 1 | #include <cofor.hfa>
|
---|
| 2 |
|
---|
| 3 | //////////////////////////////////////////////////////////////////////////////////////////
|
---|
| 4 | // cofor ( uC++ COFOR )
|
---|
| 5 |
|
---|
[ba0e1bc] | 6 | thread cofor_task {
|
---|
[e4c3819] | 7 | ssize_t low, high;
|
---|
| 8 | __cofor_body_t loop_body;
|
---|
| 9 | };
|
---|
| 10 |
|
---|
[ba0e1bc] | 11 | static void ?{}( cofor_task & this, ssize_t low, ssize_t high, __cofor_body_t loop_body ) {
|
---|
[e4c3819] | 12 | this.low = low;
|
---|
| 13 | this.high = high;
|
---|
| 14 | this.loop_body = loop_body;
|
---|
| 15 | }
|
---|
| 16 |
|
---|
[ba0e1bc] | 17 | void main( cofor_task & this ) with( this ) {
|
---|
[e4c3819] | 18 | for ( ssize_t i = low; i < high; i++ )
|
---|
| 19 | loop_body(i);
|
---|
| 20 | }
|
---|
| 21 |
|
---|
[11ab0b4a] | 22 | void __Cofor__( ssize_t low, ssize_t high, __cofor_body_t loop_body ) libcfa_public {
|
---|
[e4c3819] | 23 | ssize_t range = high - low;
|
---|
| 24 | if ( range <= 0 ) return;
|
---|
| 25 | ssize_t nprocs = get_proc_count( *active_cluster() );
|
---|
| 26 | if ( nprocs == 0 ) return;
|
---|
| 27 | ssize_t threads = range < nprocs ? range : nprocs;
|
---|
| 28 | ssize_t stride = range / threads + 1, extras = range % threads;
|
---|
| 29 | ssize_t i = 0;
|
---|
| 30 | ssize_t stride_iter = low;
|
---|
[ba0e1bc] | 31 | cofor_task * runners[ threads ];
|
---|
[e4c3819] | 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 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.