Intial commit of source code samples for GitHub repo.

This commit is contained in:
Ed Braaten 2015-04-21 14:02:59 -07:00 committed by Ed Braaten
parent 5793080047
commit 9462407ba8
14 changed files with 397 additions and 1 deletions

38
openmp-c/Makefile Normal file
View file

@ -0,0 +1,38 @@
# Sample makefile to add version/compiler info via an extra
# object module linked to final binary.
#
COMPILER_VER:=$(shell gcc --version)
COMPILER_OPTS=-fopenmp
GIT_DESCRIBE:=$(shell git describe --abbrev=7 --dirty --always --tags --long)
.PHONY: all
all: hello-omp
versioninfo.txt:
@echo "@(#) Compiler version: ${COMPILER_VER}." >versioninfo.txt
@echo "@(#) Compiler options: ${COMPILER_OPTS}." >>versioninfo.txt
@echo "@(#) Git info: ${GIT_DESCRIBE}" >>versioninfo.txt
versioninfo.o: versioninfo.txt
objcopy --input binary \
--output elf64-x86-64 \
--binary-architecture i386 \
--add-section versioninfo=versioninfo.txt \
--set-section-flags versioninfo=contents,noload \
versioninfo.txt versioninfo.o
hello-omp: hello-omp.c Makefile versioninfo.o
gcc $(COMPILER_OPTS) -DVERSIONINFO="\"$(GIT_DESCRIBE)\"" hello-omp.c \
versioninfo.o -o hello-omp
.PHONY: test
test:
(export OMP_NUM_THREADS=2; ./hello-omp)
sleep 5
(export OMP_NUM_THREADS=24; ./hello-omp)
sleep 5
(export OMP_NUM_THREADS=500; ./hello-omp)
.PHONY: clean
clean:
rm -f hello-omp versioninfo.*

BIN
openmp-c/hello-omp Executable file

Binary file not shown.

43
openmp-c/hello-omp.c Normal file
View file

@ -0,0 +1,43 @@
#include <omp.h>
#include <stdio.h>
#ifdef _OPENMP
static char versionbuf[16];
static char gitversion[] = VERSIONINFO;
int main()
{
int tcount = 0;
char *versionp;
/* Tell about the version of OpenMP API we're using.
* Specification source: www.openmp.org.
*/
switch (_OPENMP) {
case 200805:
versionp = "3.0 (May 2008)"; break;
case 201107:
versionp = "3.1 (Jul 2011)"; break;
case 201307:
versionp = "4.0 (Jul 2013)"; break;
default:
sprintf(versionbuf, "(%6.6d)", _OPENMP);
versionp = versionbuf;
break;
}
printf("Using OpenMP version: %s\n", versionp);
printf("Program git commit info: %s\n", gitversion);
printf("Max threads = %d\n", omp_get_max_threads());
#pragma omp parallel
#pragma omp atomic
tcount++;
#pragma omp parallel
/* Hello parallel world... */
printf("Hello OpenMP World from thread %3.3d of %3.3d! (tcount=%d)\n",
omp_get_thread_num() + 1, omp_get_num_threads(), tcount);
}
#endif

3
openmp-c/versioninfo.txt Normal file
View file

@ -0,0 +1,3 @@
@(#) Compiler version: gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16) Copyright (C) 2013 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE..
@(#) Compiler options: -fopenmp.
@(#) Git info: e1e14b8-dirty