|
| 1 | +#include "libminiomp.h" |
| 2 | + |
| 3 | +// Declaratiuon of global variable for loop work descriptor |
| 4 | +miniomp_loop_t miniomp_loop; |
| 5 | + |
| 6 | +/* The *_next routines are called when the thread completes processing of |
| 7 | + the iteration block currently assigned to it. If the work-share |
| 8 | + construct is bound directly to a parallel construct, then the iteration |
| 9 | + bounds may have been set up before the parallel. In which case, this |
| 10 | + may be the first iteration for the thread. |
| 11 | +
|
| 12 | + Returns true if there is work remaining to be performed; *ISTART and |
| 13 | + *IEND are filled with a new iteration block. Returns false if all work |
| 14 | + has been assigned. */ |
| 15 | + |
| 16 | +bool |
| 17 | +GOMP_loop_dynamic_next (long *istart, long *iend) { |
| 18 | + printf("TBI: Asking for more iterations? I gave you all at the beginning, no more left ...\n"); |
| 19 | + return(false); |
| 20 | +} |
| 21 | + |
| 22 | +/* The *_start routines are called when first encountering a loop construct |
| 23 | + that is not bound directly to a parallel construct. The first thread |
| 24 | + that arrives will create the work-share construct; subsequent threads |
| 25 | + will see the construct exists and allocate work from it. |
| 26 | +
|
| 27 | + START, END, INCR are the bounds of the loop; CHUNK_SIZE is the |
| 28 | + scheduling parameter. |
| 29 | +
|
| 30 | + Returns true if there's any work for this thread to perform. If so, |
| 31 | + *ISTART and *IEND are filled with the bounds of the iteration block |
| 32 | + allocated to this thread. Returns false if all work was assigned to |
| 33 | + other threads prior to this thread's arrival. */ |
| 34 | + |
| 35 | +bool |
| 36 | +GOMP_loop_dynamic_start (long start, long end, long incr, long chunk_size, |
| 37 | + long *istart, long *iend) |
| 38 | +{ |
| 39 | + printf("TBI: What a mess! Starting a non-static for worksharing construct and dont know what to do, I'll take it all\n"); |
| 40 | + *istart = start; |
| 41 | + *iend = end; |
| 42 | + return(true); |
| 43 | +} |
| 44 | + |
| 45 | +/* The GOMP_loop_end* routines are called after the thread is told that |
| 46 | + all loop iterations are complete. The first version synchronize |
| 47 | + all threads; the nowait version does not. */ |
| 48 | + |
| 49 | +void |
| 50 | +GOMP_loop_end (void) { |
| 51 | + printf("TBI: Finishing a for worksharing construct with non static schedule\n"); |
| 52 | +} |
| 53 | + |
| 54 | +void |
| 55 | +GOMP_loop_end_nowait (void) { |
| 56 | + printf("TBI: Finishing a for worksharing construct with non static schedule, with nowait clause\n"); |
| 57 | +} |
| 58 | + |
| 59 | +#if 0 |
| 60 | +// Only implement this if really needed, i.e. you find a case in which it is invoked |
| 61 | + |
| 62 | +/* The GOMP_parallel_loop_* routines pre-initialize a work-share construct |
| 63 | + to avoid one synchronization once we get into the loop. The compiler |
| 64 | + does not invoke the *_start routine for the work-share. And of course, |
| 65 | + the compiler does not invoke GOMP_loop_end. These routines should create |
| 66 | + the team of threads to execute the work-share in parallel */ |
| 67 | + |
| 68 | +void |
| 69 | +GOMP_parallel_loop_dynamic (void (*fn) (void *), void *data, |
| 70 | + unsigned num_threads, long start, long end, |
| 71 | + long incr, long chunk_size, unsigned flags) |
| 72 | +{ |
| 73 | + printf("TBI: What another mess! Directly starting a parallel and a non-static for worksharing construct! I am lost!\n"); |
| 74 | + // Here you should pre-initialize the work-sharing structures as done in |
| 75 | + // GOMP_loop_dynamic_start; only the master thread is doing this, the other |
| 76 | + // threads in the team do not reach this point |
| 77 | + GOMP_parallel (fn, data, num_threads, flags); |
| 78 | +} |
| 79 | +#endif |
0 commit comments