Created
April 9, 2015 00:46
-
-
Save glennklockwood/3db975ddec8e93867296 to your computer and use it in GitHub Desktop.
Parallelizing only the innermost loop with OpenMP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <omp.h> | |
int main ( void ) { | |
int i, j; | |
int me, n; | |
#pragma omp parallel private(i,j,me,n) | |
{ | |
me = omp_get_thread_num(); | |
n = omp_get_num_threads(); | |
printf( "Hello from %d/%d\n", me, n ); | |
#pragma omp barrier | |
for ( i = 0; i < 100; i++ ) { | |
#pragma omp for | |
for ( j = 0; j < 10; j++ ) { | |
printf( "I am %d processing %d,%d\n", me, i, j ); | |
usleep( 500000 ); | |
} | |
#pragma omp barrier | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment