| 1 | /* This header file defines standard types and provides
|
|---|
| 2 | * function prototypes used in the OpenMP to CIVLC transformation.
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #ifdef __CIVLC_OMP__
|
|---|
| 6 | #else
|
|---|
| 7 | #define __CIVLC_OMP__
|
|---|
| 8 |
|
|---|
| 9 | #include<civlc.h>
|
|---|
| 10 |
|
|---|
| 11 | /* *********************** Types *********************** */
|
|---|
| 12 |
|
|---|
| 13 | /* global shared object, used to represent the state of
|
|---|
| 14 | * a shared variable. A handle type.
|
|---|
| 15 | */
|
|---|
| 16 | typedef struct OMP_gshared {
|
|---|
| 17 | void * original; // pointer to original variable
|
|---|
| 18 | int size; // size of original variable
|
|---|
| 19 | void * state; // heap allocated state object
|
|---|
| 20 | int state_size; // size of state object
|
|---|
| 21 | } * $omp_gshared;
|
|---|
| 22 |
|
|---|
| 23 | /* local view of the shared object, belonging to a single
|
|---|
| 24 | * thread, with reference to the global object.
|
|---|
| 25 | * A handle type.
|
|---|
| 26 | */
|
|---|
| 27 | typedef struct OMP_shared {
|
|---|
| 28 | $omp_gshared;
|
|---|
| 29 | int tid;
|
|---|
| 30 | } * $omp_shared;
|
|---|
| 31 |
|
|---|
| 32 | /* a reference to a shared object or some part of
|
|---|
| 33 | * a shared object. This leaves the struct type
|
|---|
| 34 | * incomplete.
|
|---|
| 35 | */
|
|---|
| 36 | typedef struct OMP_ref * $omp_ref;
|
|---|
| 37 |
|
|---|
| 38 | /* The different kinds of references */
|
|---|
| 39 | typedef enum OMP_Ref_kind {
|
|---|
| 40 | IDENTITY,
|
|---|
| 41 | ARRAY_ELEMENT,
|
|---|
| 42 | MEMBER
|
|---|
| 43 | } OMP_Ref_kind;
|
|---|
| 44 |
|
|---|
| 45 | /* A reference to part of a composite structure */
|
|---|
| 46 | typedef struct OMP_subref {
|
|---|
| 47 | $omp_ref parent;
|
|---|
| 48 | int index;
|
|---|
| 49 | } * $omp_subref;
|
|---|
| 50 |
|
|---|
| 51 | /* completes the definition of struct OMP_ref */
|
|---|
| 52 | struct OMP_ref {
|
|---|
| 53 | enum OMP_Ref_kind kind;
|
|---|
| 54 | union {
|
|---|
| 55 | $omp_gshared var; // for IDENTITY
|
|---|
| 56 | $omp_subref subref; // for ARRAY_ELEMENT and MEMBER
|
|---|
| 57 | } data;
|
|---|
| 58 | };
|
|---|
| 59 |
|
|---|
| 60 | typedef struct OMP_loop_record {
|
|---|
| 61 | $domain loop_domain; // full loop domain
|
|---|
| 62 | $domain subdomain; // subdomain for this thread
|
|---|
| 63 | } OMP_loop_record;
|
|---|
| 64 |
|
|---|
| 65 | typedef struct OMP_work_record {
|
|---|
| 66 | int kind; // loop, barrier, sections, single
|
|---|
| 67 | int location; // location in model of construct
|
|---|
| 68 | _Bool arrived; // has this thread arrived yet?
|
|---|
| 69 | union {
|
|---|
| 70 | OMP_loop_record loop;
|
|---|
| 71 | $domain sections;
|
|---|
| 72 | int singletid;
|
|---|
| 73 | } data;
|
|---|
| 74 | } OMP_work_record;
|
|---|
| 75 |
|
|---|
| 76 | /* global team object, represents a team of threads executing
|
|---|
| 77 | * in a parallel region. A handle type. This is where all the
|
|---|
| 78 | * state needed to correctly execute a parallel region will
|
|---|
| 79 | * be stored. This includes all the shared object data,
|
|---|
| 80 | * and a worksharking queue for every thread.
|
|---|
| 81 | */
|
|---|
| 82 | typedef struct OMP_gteam {
|
|---|
| 83 | /* number of threads in team */
|
|---|
| 84 | int nthreads;
|
|---|
| 85 | /* work queues. Length nthreads. For each thread,
|
|---|
| 86 | * a FIFO queue of work records */
|
|---|
| 87 | OMP_work_record work[][];
|
|---|
| 88 | /* number of shared variables */
|
|---|
| 89 | int nshared;
|
|---|
| 90 | /* the shared object data. Length nshared. */
|
|---|
| 91 | $omp_gshared shared[];
|
|---|
| 92 | } * $omp_gteam;
|
|---|
| 93 |
|
|---|
| 94 | typedef struct OMP_team {
|
|---|
| 95 | $omp_gteam gteam;
|
|---|
| 96 | int tid;
|
|---|
| 97 | } * $omp_team;
|
|---|
| 98 |
|
|---|
| 99 | typedef enum OMP_Operator {
|
|---|
| 100 | OMP_SUM,
|
|---|
| 101 | OMP_PRODUCT,
|
|---|
| 102 | OMP_MAX,
|
|---|
| 103 | OMP_MIN
|
|---|
| 104 | } $omp_operator;
|
|---|
| 105 |
|
|---|
| 106 |
|
|---|
| 107 | /* *********************** Functions *********************** */
|
|---|
| 108 |
|
|---|
| 109 | /* creates new global team object, allocating object in heap
|
|---|
| 110 | * in specified scope. Number of threads that will be in the
|
|---|
| 111 | * team is nthreads.
|
|---|
| 112 | */
|
|---|
| 113 | $omp_gteam $omp_gteam_create($scope scope, int nthreads);
|
|---|
| 114 |
|
|---|
| 115 | /* destroys the global team object. All shared objects
|
|---|
| 116 | * associated to the team must have been destroyed before
|
|---|
| 117 | * calling this function.
|
|---|
| 118 | */
|
|---|
| 119 | void $omp_gteam_destroy($omp_gteam gteam);
|
|---|
| 120 |
|
|---|
| 121 | /* creates new local team object for a specific thread. */
|
|---|
| 122 | $omp_team $omp_team_create($scope scope, $omp_gteam gteam, int tid);
|
|---|
| 123 |
|
|---|
| 124 | /* destroys the local team object */
|
|---|
| 125 | void $omp_team_destroy($omp_team team);
|
|---|
| 126 |
|
|---|
| 127 | /* creates new global shared object, associated to the given
|
|---|
| 128 | * global team. A pointer to the shared variable that this
|
|---|
| 129 | * object corresponds to is given. The new object is initialized
|
|---|
| 130 | * by copying the values from the original variable.
|
|---|
| 131 | */
|
|---|
| 132 | $omp_gshared $omp_gshared_create($omp_gteam, void *original);
|
|---|
| 133 |
|
|---|
| 134 | /* destroys the global shared object, copying the content
|
|---|
| 135 | * to the original variable.
|
|---|
| 136 | */
|
|---|
| 137 | void $omp_gshared_destroy($omp_gshared gshared);
|
|---|
| 138 |
|
|---|
| 139 | /* creates a local shared object, returning handle to it */
|
|---|
| 140 | $omp_shared $omp_shared_create($omp_team team, $omp_gshared gshared);
|
|---|
| 141 |
|
|---|
| 142 | /* destroys the local shared object */
|
|---|
| 143 | void $omp_shared_destroy($omp_shared shared);
|
|---|
| 144 |
|
|---|
| 145 | /* creates a reference to the specified shared object */
|
|---|
| 146 | $omp_ref $omp_identity_ref($omp_shared shared);
|
|---|
| 147 |
|
|---|
| 148 | /* creates a reference to an element of a shared array
|
|---|
| 149 | * object. Argument ref is a reference to shared object
|
|---|
| 150 | * of array type.
|
|---|
| 151 | */
|
|---|
| 152 | $omp_ref $omp_array_element_ref($omp_ref ref, int index);
|
|---|
| 153 |
|
|---|
| 154 | /* creates a reference to a member of a structure or
|
|---|
| 155 | * union shared object. Argument ref is a reference to
|
|---|
| 156 | * the shared object of structure or union type.
|
|---|
| 157 | */
|
|---|
| 158 | $omp_ref $omp_member_ref($omp_ref ref, int fieldIndex);
|
|---|
| 159 |
|
|---|
| 160 | /* called by a thread to read a shared object pointed
|
|---|
| 161 | * to by ref. The result of the read is stored in the
|
|---|
| 162 | * memory unit pointed to by result.
|
|---|
| 163 | */
|
|---|
| 164 | void $omp_read(void *result, $omp_ref ref);
|
|---|
| 165 |
|
|---|
| 166 | /* called by a thread to write to the shared object
|
|---|
| 167 | * pointed to by ref. The value to be written is taken
|
|---|
| 168 | * from the memory unit pointed to by value.
|
|---|
| 169 | */
|
|---|
| 170 | void $omp_write($omp_ref ref, void *value);
|
|---|
| 171 |
|
|---|
| 172 | /* Reads the reference, applies the associative operator
|
|---|
| 173 | * specified by op to the read value and the value pointed
|
|---|
| 174 | * to by value, and writes the result back to ref.
|
|---|
| 175 | * This happens in one atomic step. Example: you can
|
|---|
| 176 | * use this to add some value to a shared variable,
|
|---|
| 177 | * using CIVL_SUM for op.
|
|---|
| 178 | */
|
|---|
| 179 | void $omp_apply_assoc($omp_ref ref, $omp_operator op,
|
|---|
| 180 | void *value);
|
|---|
| 181 |
|
|---|
| 182 | /* performs an OpenMP flush operation on the shared object
|
|---|
| 183 | */
|
|---|
| 184 | void $omp_flush($omp_shared shared);
|
|---|
| 185 |
|
|---|
| 186 | /* performs an OpenMP flush operation on all shared
|
|---|
| 187 | * objects. This is the default in OpenMP if no argument
|
|---|
| 188 | * is specified for a flush construct.
|
|---|
| 189 | */
|
|---|
| 190 | void $omp_flush_all($omp_team team);
|
|---|
| 191 |
|
|---|
| 192 | /* performs a barrier only. Note however that usually
|
|---|
| 193 | * (always?) a barrier is accompanied by a flush-all,
|
|---|
| 194 | * so $omp_barrier_and_flush should be used instead.
|
|---|
| 195 | */
|
|---|
| 196 | void $omp_barrier($omp_team team);
|
|---|
| 197 |
|
|---|
| 198 | /* combines a barrier and a flush on all shared objects
|
|---|
| 199 | * owned by the team. Implicit in many OpenMP worksharing
|
|---|
| 200 | * constructs.
|
|---|
| 201 | */
|
|---|
| 202 | void $omp_barrier_and_flush($omp_team team);
|
|---|
| 203 |
|
|---|
| 204 | /* called by a thread when it reaches an omp for loop,
|
|---|
| 205 | * this function returns the subset of the loop domain
|
|---|
| 206 | * specifying the iterations that this thread will execute.
|
|---|
| 207 | * The dimension of the domain returned equals the
|
|---|
| 208 | * dimension of the given domain loop_dom.
|
|---|
| 209 | */
|
|---|
| 210 | $domain $omp_arrive_loop($omp_team, $domain loop_dom);
|
|---|
| 211 |
|
|---|
| 212 | /* called by a thread when it reaches an omp sections
|
|---|
| 213 | * construct, this function returns the subset of the
|
|---|
| 214 | * integers 0..numSections-1 specifying the indexes of
|
|---|
| 215 | * the sections that this thread will execute. The sections
|
|---|
| 216 | * are numbered from 0 in increasing order.
|
|---|
| 217 | */
|
|---|
| 218 | $domain(1) $omp_arrive_sections($omp_team, int numSections);
|
|---|
| 219 |
|
|---|
| 220 | /* called by a thread when it reaches on omp single
|
|---|
| 221 | * construct, returns the thread ID of the thread that
|
|---|
| 222 | * will execute the single construct.
|
|---|
| 223 | */
|
|---|
| 224 | int $omp_arrive_single($omp_team team);
|
|---|
| 225 |
|
|---|
| 226 | #endif
|
|---|