Harvard |  FAS |  GSAS |  Division of Science |  HUIT 

OpenMP Software on Odyssey

 

This page is intended to help you compiling and running you OpenMP applications on the RC cluster. Currently we have both the Intel and GNU compiler suits available. Below are simple example OpenMP codes.

Fortran:

!=====================================================================
! Program: omp_test.f90
!=====================================================================
program omp_test
implicit none
integer(4) :: nthreads
integer(4) :: tid
integer(4) :: omp_get_num_threads
integer(4) :: omp_get_thread_num
!$omp parallel private( tid )
tid = omp_get_thread_num()
write(6,*)"Thread ID:", tid
if ( tid == 0 ) then
nthreads = omp_get_num_threads()
write(6,*)"Number of threads = ", nthreads
end if
!$omp end parallel
stop "End of program."
end program omp_test

C++:

//====================================================================
// Program: omp_test.cpp
//====================================================================
#include <iostream>
#include <string>
#include <sstream>
#include <math.h>
#include <omp.h>
using namespace std;

int main()
{
int nthreads, tid;
#pragma omp parallel private( tid)
{
tid = omp_get_thread_num();
nthreads = omp_get_num_threads();
cout << "Thread ID: " << tid << endl;
if ( tid == 0 ){
cout << "Number of threads = " << nthreads << endl;
}
}
return 0;
}

Compile the program

Intel, Fortran 90: [username@rclogin02 ~]$ ifort -o omp_test.x omp_test.f90 -openmp
Intel, C++: [username@rclogin02 ~]$ icpc -o omp_test.x omp_test.cpp -openmp
GNU, Fortran 90: [username@rclogin02 ~]$ gfortran -o omp_test.x omp_test.f90 -fopenmp
GNU, C++: [username@rclogin02 ~]$ g++ -o omp_test.x omp_test.cpp -fopenmp

You could use the following LSF batch-job submission script to submit the job to the queue:

#!/bin/sh
#BSUB -n 8
#BSUB -J omp_test
#BSUB -o omp_test.out
#BSUB -e omp_test.err
#BSUB -R "span[ptile=8]"
#BSUB -q short_parallel

export OMP_NUM_THREADS=8
./omp_test.x

Please note that the OpenMP codes will only run on machines with Intel cores. You can ensure this by running only on the following queues:

  • short_parallel
  • normal_parallel
  • long_parallel

References


This page was created by Plamen G. Krastev
Last modified on April 12, 2013 by plamenkrastev@fas.harvard.edu

Site last updated May 23, 2013