00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "libgomp.h"
00028
00029
00030
00031
00032 static inline void
00033 gomp_sections_init (struct gomp_work_share *ws, unsigned count)
00034 {
00035 ws->sched = GFS_DYNAMIC;
00036 ws->chunk_size = 1;
00037 ws->end = count + 1L;
00038 ws->incr = 1;
00039 ws->next = 1;
00040 #ifdef HAVE_SYNC_BUILTINS
00041
00042 if (sizeof (long) > sizeof (unsigned))
00043 ws->mode = 1;
00044 else
00045 {
00046 struct gomp_thread *thr = gomp_thread ();
00047 struct gomp_team *team = thr->ts.team;
00048 long nthreads = team ? team->nthreads : 1;
00049
00050 ws->mode = ((nthreads | ws->end)
00051 < 1UL << (sizeof (long) * __CHAR_BIT__ / 2 - 1));
00052 }
00053 #else
00054 ws->mode = 0;
00055 #endif
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 unsigned
00069 GOMP_sections_start (unsigned count)
00070 {
00071 struct gomp_thread *thr = gomp_thread ();
00072 long s, e, ret;
00073
00074 if (gomp_work_share_start (false))
00075 {
00076 gomp_sections_init (thr->ts.work_share, count);
00077 gomp_work_share_init_done ();
00078 }
00079
00080 #ifdef HAVE_SYNC_BUILTINS
00081 if (gomp_iter_dynamic_next (&s, &e))
00082 ret = s;
00083 else
00084 ret = 0;
00085 #else
00086 gomp_mutex_lock (&thr->ts.work_share->lock);
00087 if (gomp_iter_dynamic_next_locked (&s, &e))
00088 ret = s;
00089 else
00090 ret = 0;
00091 gomp_mutex_unlock (&thr->ts.work_share->lock);
00092 #endif
00093
00094 return ret;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106 unsigned
00107 GOMP_sections_next (void)
00108 {
00109 long s, e, ret;
00110
00111 #ifdef HAVE_SYNC_BUILTINS
00112 if (gomp_iter_dynamic_next (&s, &e))
00113 ret = s;
00114 else
00115 ret = 0;
00116 #else
00117 struct gomp_thread *thr = gomp_thread ();
00118
00119 gomp_mutex_lock (&thr->ts.work_share->lock);
00120 if (gomp_iter_dynamic_next_locked (&s, &e))
00121 ret = s;
00122 else
00123 ret = 0;
00124 gomp_mutex_unlock (&thr->ts.work_share->lock);
00125 #endif
00126
00127 return ret;
00128 }
00129
00130
00131
00132
00133 void
00134 GOMP_parallel_sections_start (void (*fn) (void *), void *data,
00135 unsigned num_threads, unsigned count)
00136 {
00137 struct gomp_team *team;
00138
00139 num_threads = gomp_resolve_num_threads (num_threads, count);
00140 team = gomp_new_team (num_threads);
00141 gomp_sections_init (&team->work_shares[0], count);
00142 gomp_team_start (fn, data, num_threads, team);
00143 }
00144
00145
00146
00147
00148
00149 void
00150 GOMP_sections_end (void)
00151 {
00152 gomp_work_share_end ();
00153 }
00154
00155 void
00156 GOMP_sections_end_nowait (void)
00157 {
00158 gomp_work_share_end_nowait ();
00159 }