From 6fc73de191fe37c0a648423603b3848e73af56a9 Mon Sep 17 00:00:00 2001 From: Thomas Roehl Date: Mon, 11 Nov 2024 17:36:48 +0100 Subject: [PATCH] Update examples --- examples/Makefile | 27 ++++++++++++++------------- examples/README.md | 24 ++++++++++++++++++++++++ examples/likwid-benchmark.sh | 14 ++++++++++++-- 3 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 examples/README.md diff --git a/examples/Makefile b/examples/Makefile index 11fb852ed..b9fe555ae 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -3,9 +3,10 @@ include ../config.mk include ../make/include_$(COMPILER).mk LIKWID_BINDIR ?= $(PREFIX)/bin -LIKWID_INCLUDE ?= -I$(PREFIX)/include -LIKWID_LIBDIR ?= -L$(PREFIX)/lib -LIKWID_LIB ?= -llikwid +LIKWID_INCDIR ?= $(PREFIX)/include +LIKWID_INCLUDE ?= -I$(LIKWID_INCDIR) +LIKWID_LIBDIR ?= $(PREFIX)/lib +LIKWID_LIB ?= -L$(LIKWID_LIBDIR) LIKWID_DEFINES ?= -DLIKWID_PERFMON all: C-markerAPI C-likwidAPI F-markerAPI Lua-likwidAPI C-markerAPI-run C-likwidAPI-run Lua-likwidAPI-run F-markerAPI-run @@ -25,33 +26,33 @@ help: @echo "To run the built example append '-run' to the name and add it to make: make C-likwidAPI-run" C-markerAPI: - $(CC) -fopenmp $(LIKWID_DEFINES) $(LIKWID_INCLUDE) $(LIKWID_LIBDIR) C-markerAPI.c -o C-markerAPI $(LIKWID_LIB) -lm + $(CC) -fopenmp $(LIKWID_DEFINES) $(LIKWID_INCLUDE) $(LIKWID_LIB) C-markerAPI.c -o C-markerAPI -llikwid -lm C-markerAPI-run: C-markerAPI - LD_LIBRARY_PATH=$(PREFIX)/lib $(LIKWID_BINDIR)/likwid-perfctr -C 0 -g INSTR_RETIRED_ANY:FIXC0 -m ./C-markerAPI + LD_LIBRARY_PATH=$(LIKWID_LIBDIR):$LD_LIBRARY_PATH $(LIKWID_BINDIR)/likwid-perfctr -C 0 -g INSTR_RETIRED_ANY:FIXC0 -m ./C-markerAPI C-likwidAPI: - $(CC) -fopenmp $(LIKWID_INCLUDE) $(LIKWID_LIBDIR) C-likwidAPI.c -o C-likwidAPI $(LIKWID_LIB) -lm + $(CC) -fopenmp $(LIKWID_INCLUDE) $(LIKWID_LIB) C-likwidAPI.c -o C-likwidAPI -llikwid -lm C-likwidAPI-run: C-likwidAPI - ./C-likwidAPI + LD_LIBRARY_PATH=$(LIKWID_LIBDIR):$LD_LIBRARY_PATH ./C-likwidAPI C-internalMarkerAPI: - $(CC) -g -fopenmp $(LIKWID_DEFINES) $(LIKWID_INCLUDE) $(LIKWID_LIBDIR) C-internalMarkerAPI.c -o C-internalMarkerAPI $(LIKWID_LIB) -lm + $(CC) -g -fopenmp $(LIKWID_DEFINES) $(LIKWID_INCLUDE) $(LIKWID_LIB) C-internalMarkerAPI.c -o C-internalMarkerAPI -llikwid -lm C-internalMarkerAPI-run: C-internalMarkerAPI - LD_LIBRARY_PATH=$(PREFIX)/lib ./C-internalMarkerAPI + LD_LIBRARY_PATH=$(LIKWID_LIBDIR):$LD_LIBRARY_PATH ./C-internalMarkerAPI monitoring: - $(CC) $(LIKWID_INCLUDE) $(LIKWID_LIBDIR) monitoring.c -o monitoring $(LIKWID_LIB) -lm + $(CC) $(LIKWID_INCLUDE) $(LIKWID_LIB) monitoring.c -o monitoring -llikwid -lm monitoring-run: monitoring ./monitoring F-markerAPI: F-markerAPI.F90 - @if [ -x $(FC) ]; then $(FC) -fopenmp $(LIKWID_DEFINES) $(LIKWID_INCLUDE) $(LIKWID_LIBDIR) F-markerAPI.F90 -o F-markerAPI $(LIKWID_LIB) -lm; else echo "No Fortran compiler found"; fi + @if [ -x $(FC) ]; then $(FC) -fopenmp $(LIKWID_DEFINES) $(LIKWID_INCLUDE) $(LIKWID_LIB) F-markerAPI.F90 -o F-markerAPI -llikwid -lm; else echo "No Fortran compiler found"; fi F-markerAPI-run: F-markerAPI - @if [ -x F-markerAPI ]; then $(LIKWID_BINDIR)/likwid-perfctr -C 0 -g INSTR_RETIRED_ANY:FIXC0 -m ./F-markerAPI; else echo "No executable F-markerAPI found"; fi + @if [ -x F-markerAPI ]; then LD_LIBRARY_PATH=$(LIKWID_LIBDIR):$LD_LIBRARY_PATH $(LIKWID_BINDIR)/likwid-perfctr -C 0 -g INSTR_RETIRED_ANY:FIXC0 -m ./F-markerAPI; else echo "No executable F-markerAPI found"; fi Lua-likwidAPI: @@ -59,7 +60,7 @@ Lua-likwidAPI: chmod +x Lua-likwidAPI Lua-likwidAPI-run: Lua-likwidAPI - ./Lua-likwidAPI + LD_LIBRARY_PATH=$(LIKWID_LIBDIR):$LD_LIBRARY_PATH ./Lua-likwidAPI clean: rm -f C-markerAPI C-likwidAPI F-markerAPI Lua-likwidAPI monitoring C-internalMarkerAPI diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 000000000..3c2f7c232 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,24 @@ +-------------------------------------------------------------------------------- +Examples +-------------------------------------------------------------------------------- + +This folder contains some examples showcasing the usage of LIKWID, either by +using the full LIKWID API or the MarkerAPI used for instrumenting user codes. + +All compilable examples are also listed with `make help`. The command `make` +without target tries to build and run all compilable examples. It reuses the settings +of the LIKWID build from `../config.mk`. + +- `C-markerAPI`: LIKWID's MarkerAPI in C/C++ applications +- `F-markerAPI`: LIKWID's MarkerAPI in Fortran applications +- `C-nvMarkerAPI.c`: LIKWID's Nvidia GPU related NvMarkerAPI in C/C++ applications +- `C-likwidAPI`: Using the full LIKWID API in C/C++ applications +- `Lua-likwidAPI`: Use the full LIKWID API in Lua +- `monitoring`: Showcase how to use LIKWID for system-wide monitoring +- `likwid-benchmark.sh`: Legacy version of [MachineState](https://github.com/RRZE-HPC/MachineState). Please use MachineState if you need something like this. + +All examples can be built directly by `make ` (e.g. `make C-markerAPI`). + +In order to run them, for each examples exists a `run` target: `make -run` + + diff --git a/examples/likwid-benchmark.sh b/examples/likwid-benchmark.sh index a4276a68c..74daa2258 100755 --- a/examples/likwid-benchmark.sh +++ b/examples/likwid-benchmark.sh @@ -187,7 +187,7 @@ if [ -e /sys/devices/virtual/powercap ]; then fi ##### Currently loaded modules -if [ $(module 2>/dev/null || echo $?) -eq 0 ]; then +if [ $(module 1>/dev/null 2>/dev/null; echo $?) -eq 0 ]; then header "Modules" module list fi @@ -196,6 +196,8 @@ fi CC="" if [ $(which icc 2>/dev/null | wc -l ) == 1 ]; then CC=$(which icc) +elif [ $(which icx 2>/dev/null | wc -l ) == 1 ]; then + CC=$(which icx) elif [ $(which gcc 2>/dev/null | wc -l ) == 1 ]; then CC=$(which gcc) elif [ $(which clang 2>/dev/null | wc -l ) == 1 ]; then @@ -212,6 +214,10 @@ fi CXX="" if [ $(which g++ 2>/dev/null | wc -l ) == 1 ]; then CXX=$(which g++) +elif [ $(which icpc 2>/dev/null | wc -l ) == 1 ]; then + CC=$(which icpc) +elif [ $(which icpx 2>/dev/null | wc -l ) == 1 ]; then + CC=$(which icpx) elif [ $(which pgc++ 2>/dev/null | wc -l ) == 1 ]; then CC=$(which pgc++) fi @@ -223,8 +229,12 @@ fi FORTRAN="" if [ $(which ifort 2>/dev/null | wc -l ) == 1 ]; then FORTRAN=$(which ifort) +elif [ $(which ifx 2>/dev/null | wc -l ) == 1 ]; then + FORTRAN=$(which ifx) elif [ $(which gfortran 2>/dev/null | wc -l ) == 1 ]; then FORTRAN=$(which gfortran) +elif [ $(which flang 2>/dev/null | wc -l ) == 1 ]; then + FORTRAN=$(which flang) elif [ $(which pgf90 2>/dev/null | wc -l ) == 1 ]; then FORTRAN=$(which pgf90) fi @@ -297,4 +307,4 @@ if [ $# -ge 1 ]; then fi fi - +if [ -e ./1 ]; then rm ./1; fi