Tuesday, June 29, 2010

openmp in westgrid

1. Example:
------------------------------------------------------
#include<iostream>
#include<iomanip>

#include<ctime>
using namespace std;

int
main()
{


double
sum=0;

double
w =0;
double
startime,endtime;
startime = clock();

int
nsim =1.234e6;
//#pragma omp parallel for private(w) reduction(+:sum) schedule(static,1)
#pragma omp parallel for

for
(int i = 0; i <=nsim; i++)
{


w = i*i;
sum = sum + w;
}


endtime = clock();
cout<<"sum="<< setprecision(5)<<sum<<endl;

cout<<"time pass "<<(endtime - startime)/CLOCKS_PER_SEC<<"second"<<endl;
return
(0);
}

---------------------------------------
2. Makefile in glacier.westgrid.ca
--------------------------------------
CC = icpc
CFLAGS = -g -O3 -openmp
OBJECTS = *cpp

main.exe : $(OBJECTS)
$(CC) $(CFLAGS) $(OBJECTS) -o main.exe

%.o : %.c
$(CC) $(CFLAGS) -c $<
----------------------------------------------
3. submit to the queue:
-------------------------------------

#!/bin/bash
#PBS -S /bin/bash
#PBS -l nodes=1:ppn=2
#PBS -l mem=2000mb
#PBS -l walltime=120:00:00
#PBS -M jiansen@triumf.ca
# Script for running OpenMP sample program main.exe on 2 processors on glacier


# If this file is "run_main.pbs", submit with "qsub run_main.pbs"

# Check on some basics:

echo "Running on host: " `hostname`
echo "Changing to directory from which PBS script was submitted."
cd $PBS_O_WORKDIR
echo "Current working directory is now: " `pwd`
# Note: The OMP_NUM_THREADS should match the number of processors requested.

echo "Node file: $PBS_NODEFILE :"
echo "---------------------"
cat $PBS_NODEFILE
echo "---------------------"
echo "JOb name: $PBS_JOBNAME"

NUM_PROCS=`/bin/awk 'END {print NR}' $PBS_NODEFILE`
echo "Running on $NUM_PROCS processors."
echo "Starting main.exe at `date`"


main.exe > run-main-pbs.out$PBS_JOBID


echo "main.exe run completed at `date`"

No comments:

Post a Comment