From b93d5115a40ca6e914517aaa3b3eead3a1efedee Mon Sep 17 00:00:00 2001 From: Joern Behrens <joern.behrens@uni-hamburg.de> Date: Fri, 18 Jun 2021 12:42:36 +0200 Subject: [PATCH] initial commit of HelloMP --- .gitignore | 5 +++++ Hello.c | 33 +++++++++++++++++++++++++++++++++ Makefile | 33 +++++++++++++++++++++++++++++++++ README.md | 41 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 Hello.c create mode 100644 Makefile diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b097b01 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +# compilation residuals +*.o + +# main file +Hello diff --git a/Hello.c b/Hello.c new file mode 100644 index 0000000..a65bff3 --- /dev/null +++ b/Hello.c @@ -0,0 +1,33 @@ +/***************************************************************** + + NAME: + Hello + + Description: + this is about the simplest program thinkable to demonstrate + parallel execution with OpenMP + + VERSION(S): + 1. original version j. behrens 6/2021 + +*****************************************************************/ + +#include <stdio.h> +#include <omp.h> + +int main(int argc, char** argv) +{ + +/* local declarations */ + int thrd_id; + +/* this is the main print statement parallelized! */ + +#pragma omp parallel private(thrd_id) + { + thrd_id = omp_get_thread_num(); + printf("Hello from process Number %d\n", thrd_id); + } + + return 0; +} /* end of main */ diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..baa4198 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +# sample makefile for the C PPTemplate +# j. behrens 06/2021 + +CC = gcc +# +# THIS OPTION IS FOR THE DATA PARALLEL VERSION (-mp) +CCFLAGS = -fopenmp -I/opt/local/include + +DATLIBS= -lgomp -lm + +OBJECTS = \ +Hello.o + + +# default make + +all:: + @make Hello + @make clear + +# make object files + +.c.o: + ${CC} ${CCFLAGS} -c $< + +# make target (executable) + +Hello: ${OBJECTS} + ${CC} ${CCFLAGS} -o $@ ${OBJECTS} ${LIBS} + +clear:: + @rm *.o + diff --git a/README.md b/README.md index 217ab61..2b884c9 100644 --- a/README.md +++ b/README.md @@ -1 +1,40 @@ -# HelloMP \ No newline at end of file +# HelloMP + +Yet another Hello World Program + +## Description and Purpose + +This O(1)-line code demonstrates parallelization with OpenMP + +## Contents of this Project + +``` +README - this file +Makefile - Makefile tested for macOS +Hello.c - parallelized "Hello World" C-program +``` + +## What do do here + +**First**, build the executable by typing + +``` +%> make +``` + +If this fails, you have to adjust your path and settings, however, +I don't know how... + +**Second**, set up the number of threads (e.g. to four) + +``` +%> export OMP_NUM_THREADS=4 +``` + +**Third**, run the program + +``` +%> Hello +``` + +(c) 2021, Jörn Behrens (joern.behrens@uni-hamburg.de) -- GitLab