Skip to content

Instantly share code, notes, and snippets.

@auriza
Created April 17, 2018 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save auriza/d00a76bd3b1a6e67e92e64f7189bae31 to your computer and use it in GitHub Desktop.
Save auriza/d00a76bd3b1a6e67e92e64f7189bae31 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <unistd.h>
#include <omp.h>
int main() {
int i, j;
int n = 5;
// for --> imbalance
// for collapse(2) --> undefined: inner-loop depends on outer-loop (j <= i)
// task --> balance
#pragma omp parallel
{
#pragma omp single private(i,j)
for (i = 0; i < n; i++)
for (j = 0; j <= i; j++)
#pragma omp task
{
printf("[%d]: (%d, %d)\n", omp_get_thread_num(), i, j);
sleep(1);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment