Indiana University
University Information Technology Services
  
What are archived documents?
Login>>
Login

Login is for authorized groups (e.g., UITS, OVPIT, and TCC) that need access to specialized Knowledge Base documents. Otherwise, simply use the Knowledge Base without logging in.

Close

ARCHIVED: On Libra, how do I compile an OpenMP program?

Note: UITS will retire Libra in spring 2009. Accounts are available on Quarry, a general-purpose Unix computing environment. For more, see ARCHIVED: About the Libra retirement.

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.

This is document aqpl in domain all.
Last modified on June 30, 2009.

Comments/Questions/Corrections

Use this form to offer suggestions, corrections, and additions to the Knowledge Base. We welcome your input!

If you are affiliated with Indiana University and would like assistance with a specific computing problem, please use the Ask a Consultant form, or contact your campus Support Center.

Contact Information

Note: We will reply to your comment at this address. If your message concerns a problem receiving email, please enter an alternate email address.