diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..b097b01aa231c186e3dfd5560fd8580c093cd351 --- /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 0000000000000000000000000000000000000000..a65bff31bb681663bd430c809c81a983a612e0bc --- /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 0000000000000000000000000000000000000000..baa41981a6c13567ba55ed62950756424f853bb1 --- /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 217ab617ef6b623da2e60ef10166861da59bf1f3..2b884c9da30b6d9e20cb639aa4e7ab37dda1544b 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)