| 1 |
|
|---|
| 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 | $proc owner;
|
|---|
| 10 | _Bool lock;
|
|---|
| 11 | };
|
|---|
| 12 |
|
|---|
| 13 | /********************************** State *****************************************/
|
|---|
| 14 | /* The number of times the omp_get_wtime function has been called */
|
|---|
| 15 | int OMP_time_count = 0;
|
|---|
| 16 |
|
|---|
| 17 | /************************** OMP LIB Implementations *******************************/
|
|---|
| 18 |
|
|---|
| 19 | void omp_init_lock(omp_lock_t *slock){
|
|---|
| 20 | slock->owner = $proc_null;
|
|---|
| 21 | slock->lock = true;
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 | void omp_destroy_lock(omp_lock_t *slock){
|
|---|
| 25 | omp_lock_t blank;
|
|---|
| 26 | *slock = blank;
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | void omp_set_lock(omp_lock_t *slock){
|
|---|
| 30 | $atomic{
|
|---|
| 31 | $when(!slock->lock && slock->owner == $proc_null){
|
|---|
| 32 | slock->lock = true;
|
|---|
| 33 | slock->owner == $self;
|
|---|
| 34 | }
|
|---|
| 35 | }
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | void omp_unset_lock(omp_lock_t *slock){
|
|---|
| 39 | $atomic{
|
|---|
| 40 | slock->owner = $proc_null;
|
|---|
| 41 | slock->lock = false;
|
|---|
| 42 | }
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | $abstract double OMP_time(int i);
|
|---|
| 46 |
|
|---|
| 47 | double omp_get_wtime() {
|
|---|
| 48 | double result;
|
|---|
| 49 |
|
|---|
| 50 | result = OMP_time(OMP_time_count);
|
|---|
| 51 | OMP_time_count++;
|
|---|
| 52 | return result;
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 | /*
|
|---|
| 57 | void omp_set_num_threads (int);
|
|---|
| 58 | int omp_get_num_threads (void);
|
|---|
| 59 | int omp_get_max_threads (void);
|
|---|
| 60 | int omp_get_thread_num (void);
|
|---|
| 61 | int omp_get_num_procs (void);
|
|---|
| 62 | int omp_in_parallel (void);
|
|---|
| 63 | void omp_set_dynamic (int);
|
|---|
| 64 | int omp_get_dynamic (void);
|
|---|
| 65 | void omp_set_nested (int);
|
|---|
| 66 | int omp_get_nested (void);
|
|---|
| 67 | void omp_init_lock (omp_lock_t *);
|
|---|
| 68 | void omp_destroy_lock (omp_lock_t *);
|
|---|
| 69 | void omp_set_lock (omp_lock_t *);
|
|---|
| 70 | void omp_unset_lock (omp_lock_t *);
|
|---|
| 71 | int omp_test_lock (omp_lock_t *);
|
|---|
| 72 | void omp_init_nest_lock (omp_nest_lock_t *);
|
|---|
| 73 | void omp_destroy_nest_lock (omp_nest_lock_t *);
|
|---|
| 74 | void omp_set_nest_lock (omp_nest_lock_t *);
|
|---|
| 75 | void omp_unset_nest_lock (omp_nest_lock_t *);
|
|---|
| 76 | int omp_test_nest_lock (omp_nest_lock_t *);
|
|---|
| 77 | double omp_get_wtime (void);
|
|---|
| 78 | double omp_get_wtick (void);
|
|---|
| 79 | */
|
|---|