Skip to content

Instantly share code, notes, and snippets.

@aprell
Created June 18, 2012 10:03
Show Gist options
  • Save aprell/2947727 to your computer and use it in GitHub Desktop.
Save aprell/2947727 to your computer and use it in GitHub Desktop.
OpenMP: #pragma omp for (static)
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void do_sth(void) { return; }
int main(void)
{
int i, n = 100;
#pragma omp for schedule(static)
for (i = 0; i < n; i++)
do_sth();
return 0;
}
==============================================================================
After OpenMP lowering and expansion:
==============================================================================
/* libgomp/barrier.c:
* - GOMP_barrier
*/
int main(void)
{
int i, n = 100;
int num_threads;
int thread_num;
int chunk_size;
int from, to;
num_threads = __builtin_omp_get_num_threads();
thread_num = __builtin_omp_get_thread_num();
chunk_size = n / num_threads;
chunk_size += (chunk_size * num_threads != n);
from = chunk_size * thread_num;
to = from + chunk_size;
if (to > 100)
to = 100;
for (i = from; i < to; i++) {
do_sth();
}
__builtin_GOMP_barrier();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment