Last active
February 25, 2021 18:27
-
-
Save Jordan-Cottle/2ecabf4e04c4eab73633bac2f485e4ff to your computer and use it in GitHub Desktop.
Generic MPI project Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <mpi.h> | |
int main(int argc, char *argv[]) | |
{ | |
MPI_Init(NULL, NULL); | |
int rank; | |
int process_count; | |
int err = MPI_Comm_size(MPI_COMM_WORLD, &process_count); | |
if (err != 0) | |
{ | |
std::cerr << "Getting comm size failed\n"; | |
return err; | |
} | |
err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); | |
if (err != 0) | |
{ | |
std::cerr << "Getting process rank failed\n"; | |
return err; | |
} | |
for (int i = 1; i < argc; ++i) | |
{ | |
std::cout << "Process " << rank << " of " << process_count << ": " << argv[i] << "\n"; | |
} | |
MPI_Finalize(); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set desired executable name | |
TARGET = HelloMPI | |
# Set number of processes to spawn when running TARGET with mpiexec | |
PROCESS_COUNT = 4 | |
# Set desired g++ options | |
GCC_FLAGS = -Wall -g -Og | |
# Set any options to pass to mpiexec | |
RUN_OPTIONS = --mca btl_base_warn_component_unused 0 \ | |
-n ${PROCESS_COUNT} | |
# Set command line args for TARGET | |
RUN_ARGS = "Hello" "World" | |
# Locate all .cpp files in project and strip the .cpp extension | |
FILES := $(shell find . -type f -name '*.cpp' -printf '%P\n' | sed 's/\.cpp//') | |
# Add .o extension to all discovered .cpp files | |
OBJS = $(addsuffix .o, ${FILES}) | |
# Shell commands | |
GCC = mpiCC | |
RUN = mpiexec ${RUN_OPTIONS} | |
run: ${TARGET} | |
${RUN} $< ${RUN_ARGS} | |
${TARGET}: ${OBJS} | |
${GCC} -o $@ $^ | |
%.o: %.cpp | |
${GCC} ${GCC_FLAGS} -o $@ -c $< | |
clean: | |
${RM} $(shell find . -type f -name '*\.o') | |
${RM} ${TARGET} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment