source: CIVL/text/include/civlc-omp.cvh@ ee38d17

1.23 2.0 main test-branch
Last change on this file since ee38d17 was cbdbd4e, checked in by Manchun Zheng <zmanchun@…>, 12 years ago

added checking for workshared constructs.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1618 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 6.8 KB
Line 
1// civlc-omp.cvh: header file for CIVL-C support functions for OpenMP.
2
3#ifndef __CIVLC_OMP__
4#define __CIVLC_OMP__
5
6#include <civlc.cvh>
7#include <domain.cvh>
8
9/** Important notes:
10 * 1. none of those variables that comprise a shared object should ever
11 * be accessed directly. All access must happen through $omp_read/write,
12 * including the local views, status, and shared view.
13 */
14
15/* *********************** Types *********************** */
16
17/* The status of a shared variable (or component of a shared
18 * variable). For each shared variable, there is a "local view",
19 * for each thread, which is a copy of the shared variable in
20 * the thread scope. There is also the shared variable proper.
21 * The local copy may be either empty or full. Flush operations
22 * copy data between the local and shared copies, and modify
23 * the empty/full bit. */
24typedef enum $omp_var_status {
25 EMPTY, // local is empty
26 FULL, // local is occupied, no writes to it have been made
27 MODIFIED // local is occupied, writes have been made to it
28} $omp_var_status;
29
30/* An enumerated type specifying the different kinds of OpenMP
31 * "worksharing" constructs. */
32typedef enum $omp_worksharing_kind {
33 LOOP,
34 BARRIER,
35 SECTIONS,
36 SINGLE
37} $omp_worksharing_kind;
38
39/* global shared object, containing a reference to a shared variable.
40 * A handle type. */
41typedef struct OMP_gshared * $omp_gshared;
42
43/* local view of a shared object, belonging to a single
44 * thread, with reference to the global object, and
45 * a local copy and a status of the shared object.
46 * The type of the status variable is obtained from
47 * the type of the original variable by replacing
48 * all leaf nodes in the type tree with "int".
49 * A handle type. */
50typedef struct OMP_shared * $omp_shared;
51
52/* the worksharing information that a thread needs for executing
53 * a worksharing region. It contains the kind of the worksharing
54 * region, the location of the region, the status of the region
55 * and the subdomain (iterations/sections/task assigned to the thread).
56 */
57typedef struct OMP_work_record $omp_work_record;
58
59/* global team object, represents a team of threads executing
60 * in a parallel region. A handle type. This is where all the
61 * state needed to correctly execute a parallel region will
62 * be stored. This includes a global barrier, and a worksharing
63 * queue for every thread. */
64typedef struct OMP_gteam * $omp_gteam;
65
66/*
67 * local object belonging to a single thread and referencing the
68 * global team object. A handle type. It also includes the local
69 * views of all shared data and a local barrier. */
70typedef struct OMP_team * $omp_team;
71
72
73/* *********************** Functions *********************** */
74
75/* creates new global team object, allocating object in heap
76 * in specified scope. Number of threads that will be in the
77 * team is nthreads. */
78$omp_gteam $omp_gteam_create($scope scope, int nthreads);
79
80/* destroys the global team object. All shared objects
81 * associated to the team must have been destroyed before
82 * calling this function. */
83void $omp_gteam_destroy($omp_gteam gteam);
84
85/* creates new local team object for a specific thread. */
86$omp_team $omp_team_create($scope scope, $omp_gteam gteam, int tid);
87
88/* destroys the local team object */
89void $omp_team_destroy($omp_team team);
90
91/* creates new global shared object, associated to the given
92 * global team. A pointer to the shared variable that this
93 * object corresponds to is given. */
94$omp_gshared $omp_gshared_create($omp_gteam gteam, void *original);
95
96/* destroys the global shared object, copying the content
97 * to the original variable. */
98void $omp_gshared_destroy($omp_gshared gshared);
99
100/* creates a local shared object, returning handle to it.
101 * The local copy of the shared object is initialized
102 * by copying the values from the original variable referenced to
103 * by the gshared object. The status variable is initialized to FULL.
104 * The created shared object is appended
105 * to the shared queue of the $omp_team object. */
106$omp_shared $omp_shared_create($omp_team team,
107 $omp_gshared gshared, void *local, void *status);
108
109/* destroys the local shared object */
110void $omp_shared_destroy($omp_shared shared);
111
112/* called by a thread to read a shared object.
113 * ref is a pointer into the local copy of the shared variable.
114 * The result of the read is stored in the
115 * memory unit pointed to by result.
116 * assumes ref is a pointer to a scalar.
117 */
118void $omp_read($omp_shared shared, void *result, void *ref);
119
120/* called by a thread to write to the shared object.
121 * ref is a pointer into the local copy of the shared variable.
122 * The value to be written is taken
123 * from the memory unit pointed to by value.
124 * assumes ref is a pointer to a scalar.
125 */
126void $omp_write($omp_shared shared, void *ref, void *value);
127
128/* applies the associative operator
129 * specified by op to the local copy and the corresponding shared copy,
130 * and writes the result back to the shared copy.
131 * This happens in one atomic step. Example: you can
132 * use this to add some value to a shared variable,
133 * using CIVL_SUM for op.
134 * assumes local is a pointer to a scalar.
135 */
136void $omp_apply_assoc($omp_shared shared,
137 $operation op,
138 void *local);
139
140/* performs an OpenMP flush operation on the shared object
141 */
142void $omp_flush($omp_shared shared, void *ref);
143
144/* performs an OpenMP flush operation on all shared
145 * objects. This is the default in OpenMP if no argument
146 * is specified for a flush construct. */
147void $omp_flush_all($omp_team team);
148
149/* performs a barrier only. Note however that usually
150 * (always?) a barrier is accompanied by a flush-all,
151 * so $omp_barrier_and_flush should be used instead.
152 */
153void $omp_barrier($omp_team team);
154
155/* combines a barrier and a flush on all shared objects
156 * owned by the team. Implicit in many OpenMP worksharing
157 * constructs. */
158void $omp_barrier_and_flush($omp_team team);
159
160/* called by a thread when it reaches an omp for loop,
161 * this function returns the subset of the loop domain
162 * specifying the iterations that this thread will execute,
163 * according to the given policy. In general, this
164 * function is nondeterministic.
165 * The dimension of the domain returned equals the
166 * dimension of the given domain loop_dom.
167 */
168$domain $omp_arrive_loop($omp_team team, int location, $domain loop_dom,
169 $domain_strategy strategy);
170
171/* called by a thread when it reaches an omp sections
172 * construct, this function returns the subset of the
173 * integers 0..numSections-1 specifying the indexes of
174 * the sections that this thread will execute. The sections
175 * are numbered from 0 in increasing order. */
176$domain(1) $omp_arrive_sections($omp_team team, int location, int numSections);
177
178/* called by a thread when it reaches on omp single
179 * construct, returns the thread ID of the thread that
180 * will execute the single construct. */
181int $omp_arrive_single($omp_team team, int location);
182
183#endif
Note: See TracBrowser for help on using the repository browser.