Skip to content

Commit

Permalink
Update examples
Browse files Browse the repository at this point in the history
  • Loading branch information
TomTheBear committed Nov 11, 2024
1 parent df94a40 commit 6fc73de
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 15 deletions.
27 changes: 14 additions & 13 deletions examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,41 +26,41 @@ 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:
sed -e "s+<PREFIX>+$(PREFIX)+g" Lua-likwidAPI.lua > 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
Expand Down
24 changes: 24 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -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 <target>` (e.g. `make C-markerAPI`).

In order to run them, for each examples exists a `run` target: `make <target>-run`


14 changes: 12 additions & 2 deletions examples/likwid-benchmark.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -297,4 +307,4 @@ if [ $# -ge 1 ]; then
fi
fi


if [ -e ./1 ]; then rm ./1; fi

0 comments on commit 6fc73de

Please sign in to comment.