| 1 | #include <civlc.cvh>
|
|---|
| 2 | #include <omp.h>
|
|---|
| 3 | #include <civl-omp.cvh>
|
|---|
| 4 | #include <stdbool.h>
|
|---|
| 5 |
|
|---|
| 6 | // implementations of functions in omp.h go here...
|
|---|
| 7 |
|
|---|
| 8 | struct omp_lock_t{
|
|---|
| 9 | _Bool lock;
|
|---|
| 10 | };
|
|---|
| 11 |
|
|---|
| 12 | /************************** OMP LIB Implementations *******************************/
|
|---|
| 13 |
|
|---|
| 14 | void omp_init_lock(omp_lock_t *slock){
|
|---|
| 15 | slock->lock = false;
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | void omp_destroy_lock(omp_lock_t *slock){
|
|---|
| 19 | omp_lock_t blank;
|
|---|
| 20 | *slock = blank;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | /* Waits for the lock to available and grabs it,
|
|---|
| 24 | * AND performs a flush_all on the team, as mandated
|
|---|
| 25 | * by the OpenMP Standard. */
|
|---|
| 26 | void $omp_set_lock(omp_lock_t *slock, $omp_team team) {
|
|---|
| 27 | $atomic {
|
|---|
| 28 | $when(!slock->lock) slock->lock = true;
|
|---|
| 29 | $omp_flush_all(team);
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | /* Releases the lock
|
|---|
| 34 | * AND performs a flush_all on the team, as mandated
|
|---|
| 35 | * by the OpenMP Standard. */
|
|---|
| 36 | void $omp_unset_lock(omp_lock_t *slock, $omp_team team) {
|
|---|
| 37 | $atomic {
|
|---|
| 38 | slock->lock = false;
|
|---|
| 39 | $omp_flush_all(team);
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | /* These are replaced by $omp_set_lock and
|
|---|
| 44 | * $omp_unset_lock. Those functionsn do the
|
|---|
| 45 | * flush on the whole team, as required by
|
|---|
| 46 | * the OpenMP Standard...
|
|---|
| 47 |
|
|---|
| 48 | void omp_set_lock(omp_lock_t *slock){
|
|---|
| 49 | $atomic{
|
|---|
| 50 | $when(!slock->lock){
|
|---|
| 51 | slock->lock = true;
|
|---|
| 52 | }
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | void omp_unset_lock(omp_lock_t *slock){
|
|---|
| 57 | $atomic{
|
|---|
| 58 | slock->lock = false;
|
|---|
| 59 | }
|
|---|
| 60 | }
|
|---|
| 61 | */
|
|---|
| 62 |
|
|---|
| 63 | $abstract double OMP_time(int time_count);
|
|---|
| 64 |
|
|---|
| 65 | double omp_get_wtime() {
|
|---|
| 66 | int OMP_time_count = $next_time_count();
|
|---|
| 67 | double result = OMP_time(OMP_time_count);
|
|---|
| 68 |
|
|---|
| 69 | if (OMP_time_count > 0) {
|
|---|
| 70 | $assume(result > OMP_time(OMP_time_count-1));
|
|---|
| 71 | } else {
|
|---|
| 72 | $assume(result > 0);
|
|---|
| 73 | }
|
|---|
| 74 | return result;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | /*
|
|---|
| 79 | void omp_set_num_threads (int);
|
|---|
| 80 | int omp_get_num_threads (void);
|
|---|
| 81 | int omp_get_max_threads (void);
|
|---|
| 82 | int omp_get_thread_num (void);
|
|---|
| 83 | int omp_get_num_procs (void);
|
|---|
| 84 | int omp_in_parallel (void);
|
|---|
| 85 | void omp_set_dynamic (int);
|
|---|
| 86 | int omp_get_dynamic (void);
|
|---|
| 87 | void omp_set_nested (int);
|
|---|
| 88 | int omp_get_nested (void);
|
|---|
| 89 | void omp_init_lock (omp_lock_t *);
|
|---|
| 90 | void omp_destroy_lock (omp_lock_t *);
|
|---|
| 91 | void omp_set_lock (omp_lock_t *);
|
|---|
| 92 | void omp_unset_lock (omp_lock_t *);
|
|---|
| 93 | int omp_test_lock (omp_lock_t *);
|
|---|
| 94 | void omp_init_nest_lock (omp_nest_lock_t *);
|
|---|
| 95 | void omp_destroy_nest_lock (omp_nest_lock_t *);
|
|---|
| 96 | void omp_set_nest_lock (omp_nest_lock_t *);
|
|---|
| 97 | void omp_unset_nest_lock (omp_nest_lock_t *);
|
|---|
| 98 | int omp_test_nest_lock (omp_nest_lock_t *);
|
|---|
| 99 | double omp_get_wtime (void);
|
|---|
| 100 | double omp_get_wtick (void);
|
|---|
| 101 | */
|
|---|