mirror of
https://github.com/OpenMP/Examples.git
synced 2025-04-07 23:22:11 +01:00
31 lines
603 B
C
31 lines
603 B
C
/*
|
|
* @@name: tasking.10c
|
|
* @@type: C
|
|
* @@compilable: yes
|
|
* @@linkable: no
|
|
* @@expect: success
|
|
*/
|
|
#include <omp.h>
|
|
void work() {
|
|
omp_lock_t lock;
|
|
omp_init_lock(&lock);
|
|
#pragma omp parallel
|
|
{
|
|
int i;
|
|
#pragma omp for
|
|
for (i = 0; i < 100; i++) {
|
|
#pragma omp task
|
|
{
|
|
// lock is shared by default in the task
|
|
omp_set_lock(&lock);
|
|
// Capture data for the following task
|
|
#pragma omp task
|
|
// Task Scheduling Point 1
|
|
{ /* do work here */ }
|
|
omp_unset_lock(&lock);
|
|
}
|
|
}
|
|
}
|
|
omp_destroy_lock(&lock);
|
|
}
|