Skip to content

Instantly share code, notes, and snippets.

@hnrck
Created January 4, 2019 11:39
Show Gist options
  • Save hnrck/bb5cac3656d0ecd1253f1e768e0ca010 to your computer and use it in GitHub Desktop.
Save hnrck/bb5cac3656d0ecd1253f1e768e0ca010 to your computer and use it in GitHub Desktop.
OpenMP installation test file with generic Makefile
#include <iostream>
#include <omp.h>
int main() {
#pragma omp parallel
{
const auto ncpu = omp_get_num_procs();
const auto tid = omp_get_thread_num();
const auto npr = omp_get_num_threads();
const auto nthr = omp_get_max_threads();
#pragma omp single
{
std::cout << tid << ": NCPU\t= " << ncpu << std::endl;
std::cout << tid << ": NTHR\t= " << nthr << std::endl;
std::cout << tid << ": NPR\t= " << npr << std::endl;
}
#pragma omp critical
std::cout << tid << ": Thread n°" << tid << "/" << npr << " in OpenMP stage 1" << std::endl;
}
return 0;
}
BIN?=main
CXX?=clang++
EXT?=cpp
LINKS?=
SRCS=$(shell find . -name "*."$(EXT))
DIRS=$(shell find ./* -type d)
OBJS=$(patsubst %.$(EXT),%.o,$(SRCS))
INCS=$(addprefix -I, $(DIRS))
CPPFLAGS+=-std=c++17 -Wall -fopenmp $(INCS)
LDFLAGS+=$(addprefix -l, $(LINKS))
.PHONY: all run clean
all: $(BIN)
$(EXT).o: $(SRCS)
$(CXX) $(CPPFLAGS) -c $<
$(BIN): $(OBJS)
$(CXX) $(CPPFLAGS) -o $(BIN) $(notdir $(OBJS)) $(LDFLAGS)
run: all
-./$(BIN)
clean:
-rm -f $(notdir $(OBJS)) $(BIN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment