Indiana University
University Information Technology Services
  
What are archived documents?

On Libra, how do I compile an OpenMP program?

You can compile OpenMP programs on the SMP nodes of the Libra Cluster (libra43, libra47, libra48, libra49, and libra50) with the -qsmp=omp option using the threaded compiler mode. For example, you would compile a Fortran 90 program without a link to the library myprog.f using the following command:

xlf90_r -qfixed -qsmp=omp -o omp_test omparallel.f

Here is a sample program, omparallel.f:

program hello INTEGER I, XP, ID INTEGER OMP_GET_NUM_PROCS INTEGER OMP_GET_NUM_THREADS INTEGER OMP_GET_THREAD_NUM CHARACTER(50) message call OMP_SET_NUM_THREADS(7) message = ' Is the number of threads in omp_get_num_threads' !$OMP PARALLEL PRIVATE(ID) ID = OMP_GET_THREAD_NUM() print *, 'Hello World from thread = ', ID XP = OMP_GET_NUM_THREADS() call WORK(ID) if (ID .EQ. 0) then write(6,*) XP, message end if !$OMP END PARALLEL stop end subroutine WORK(PID) CHARACTER(12) message INTEGER PID message = 'Hello, world' write(6,*) message, " I am ", PID, " and I am working " end subroutine

Output from this program looks like:

Hello World from thread = 0 Hello World from thread = 1 Hello, world I am 1 and I am working Hello World from thread = 4 Hello, world I am 4 and I am working Hello World from thread = 2 Hello, world I am 2 and I am working Hello World from thread = 3 Hello, world I am 3 and I am working Hello World from thread = 6 Hello, world I am 6 and I am working Hello World from thread = 5 Hello, world I am 5 and I am working Hello, world I am 0 and I am working 7 Is the number of threads in omp_get_num_threads

You would compile a C program using this command:

xlf90_r -qfixed -qsmp=omp -o omp_test omparallel.c

Note: If the program links to any library, usually the library must be thread-safe (i.e., it must guarantee to shared memory processes that use threads an independent function for each thread that makes the call), at least to use OpenMP to perform parallelization.

Also see:

This is document aqpl in domain all.
Last modified on February 06, 2008.
Please tell us, did you find the answer to your question?