Skip to content

Instantly share code, notes, and snippets.

@hnrck
Created January 5, 2019 12:49
Show Gist options
  • Save hnrck/db21441b783dc1511388bd19cc4adf49 to your computer and use it in GitHub Desktop.
Save hnrck/db21441b783dc1511388bd19cc4adf49 to your computer and use it in GitHub Desktop.
Open MPI with CXX headers installation test file with generic Makefile
#include <iostream>
#include <memory>
#include <vector>
#include <mpicxx.h>
int main() {
MPI::Init();
const auto world_size = MPI::COMM_WORLD.Get_size();
const auto world_rank = MPI::COMM_WORLD.Get_rank();
auto name = std::vector<char>(MPI_MAX_PROCESSOR_NAME, std::allocator<char>());
auto name_size = 0;
MPI::Get_processor_name(&name[0], name_size);
std::cout << "Hello, world! From processor " << &name[0] << ", rank " << world_rank + 1 << "/" << world_size
<< std::endl;
MPI::Finalize();
return 0;
}
BIN?=main
OMPI_CC=clang++ mpic++
MPICXX?=mpic++
MPIRUN?=mpirun
EXT?=cpp
LINKS?=
NB_SLOTS?=2
SRCS=$(shell find . -name "*."$(EXT))
DIRS=$(shell find ./* -type d)
OBJS=$(patsubst %.$(EXT),%.o,$(SRCS))
INCS=$(addprefix -I, $(DIRS))
CPPFLAGS+=-std=c++17 -Wall $(INCS)
LDFLAGS+=$(addprefix -l, $(LINKS))
.PHONY: all run clean
all: $(BIN)
$(EXT).o: $(SRCS)
$(CXX) $(CPPFLAGS) -c $<
$(BIN): $(OBJS)
$(MPICXX) $(CPPFLAGS) -o $(BIN) $(notdir $(OBJS)) $(LDFLAGS)
run: all
-$(MPIRUN) ./$(BIN)
runn: all
-$(MPIRUN) -n $(NB_SLOTS) ./$(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