Skip to content

Instantly share code, notes, and snippets.

@aprell
Created June 18, 2012 10:06
Show Gist options
  • Save aprell/2947731 to your computer and use it in GitHub Desktop.
Save aprell/2947731 to your computer and use it in GitHub Desktop.
OpenMP: #pragma omp for (dynamic)
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
void do_sth_else(void) { return; }
int main(void)
{
int i, n = 100;
#pragma omp for schedule(runtime)
for (i = 0; i < n; i++)
do_sth_else();
return 0;
}
==============================================================================
After OpenMP lowering and expansion:
==============================================================================
/* libgomp/loop.c:
* GOMP_loop_runtime_start
* GOMP_loop_runtime_next
* GOMP_loop_end
*/
extern bool GOMP_loop_runtime_start(long start, long end, long incr, long *istart, long *iend);
extern bool GOMP_loop_runtime_next(long *istart, long *iend);
extern void GOMP_loop_end(void);
int main(void)
{
int from, to;
int i;
__builtin_GOMP_loop_runtime_start(0, n, 1, &from, &to);
do {
for (i = from; i < to; i++) {
do_sth_else();
}
} while (__builtin_GOMP_loop_runtime_next(&from, &to));
__builtin_GOMP_loop_end();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment