Commit a6976344 authored by PARWORK Lambert's avatar PARWORK Lambert
Browse files

fix openmp program

parent af58973f
#-*-makefile-*-
CC = gcc
CFLAGS = -O2 -fopenmp
##
## flags "-fopenmp" is mandatory to activate OpenMP compilation
##
bin : omp_array
omp_array : omp_array.c
${CC} ${CFLAGS} $@.c -o $@
The purpose of the following exercice is to show you how to
compile and how to submit a profram using OpenMP API
*) compilation
make
*) execution
qsub -q batch batch_omp.sh
#!/bin/bash
### run it with "qsub batch_omp.sh" #########
#jobs's name
#PBS -N test_OpenMP
#we request 1 core and 4 threads
#PBS -l nodes=1:ppn=4
#The maximum wall-clock time during which this job can run (sec)
#PBS -l walltime=60
# output log file name
#PBS -o "run-log.txt"
#output error file name
#PBS -e "run-err.txt"
# change to submission jobs directory
cd $PBS_O_WORKDIR
./omp_array
#include <omp.h>
#include <stdio.h>
#define NMAX 1000000
int main(int argc, char **argv)
{
int this_thread, // my thread index
num_threads; // #threads used during the run
int a[NMAX],i;
#pragma omp parallel
{
this_thread = omp_get_thread_num();
num_threads = omp_get_num_threads();
if (this_thread == 0) { // Only thread #0 print this
printf("#Threads used = %d\n", num_threads);
}
}
#pragma omp parallel for
for (i = 0; i < NMAX; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment