Skip to content

Commit

Permalink
Add simple MPI tests
Browse files Browse the repository at this point in the history
- Communicator of the correct size
- Point to point communication works between nodes
  • Loading branch information
rjanalik committed Oct 3, 2024
1 parent 6d05156 commit 120ebb6
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ci/templates/test_image.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@ test_job_test_image_gromacs-{{os}}{{osver}}-spack{{spackver}}-{{archstr[arch]}}:
{% if arch == "rocm" -%}
- echo "TODO Lets ignore ROCm for now"
{%- endif %}

##### mpi_simple

build_job_test_image_mpi_simple-{{os}}{{osver}}-spack{{spackver}}-{{archstr[arch]}}:
stage: build_test_image
extends:
- {{container_builder[arch]}}
variables:
DOCKERFILE: "test/mpi_simple/Dockerfile.mpi_simple"
PERSIST_IMAGE_NAME: "{{registry_path}}/test-mpi_simple:spack{{spackver}}-{{os}}{{osver}}-{{archstr[arch]}}"
DOCKER_BUILD_ARGS: '["BUILDIMG={{registry_build_image_name_tag}}", "RUNTIMEIMG={{registry_runtime_image_name_tag}}", "TARGET={{spack_target}}"]'
SLURM_JOB_NUM_NODES: 2
SLURM_NTASKS: 2
SLURM_MPI_TYPE: pmi2

test_job_test_image_mpi_simple-{{os}}{{osver}}-spack{{spackver}}-{{archstr[arch]}}:
stage: test_test_image
extends:
- {{container_runner[arch]}}
image: "{{registry_path}}/test-mpi_simple:spack{{spackver}}-{{os}}{{osver}}-{{archstr[arch]}}"
script:
- hostname
- /src/mpi_send_recv
34 changes: 34 additions & 0 deletions test/mpi_simple/Dockerfile.mpi_simple
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
ARG BUILDIMG
FROM $BUILDIMG as builder

RUN apt-get update \
&& env DEBIAN_FRONTEND=noninteractive TZ=Europe/Zurich apt-get -yqq install --no-install-recommends build-essential

ARG TARGET
RUN spack-install-helper \
"$TARGET"


# copy only relevant parts to the final container
ARG RUNTIMEIMG
FROM $RUNTIMEIMG

# it is important to keep the paths, otherwise your installation is broken
# all these paths are created with the above `spack-install-helper` invocation
COPY --from=builder /opt/spack-environment /opt/spack-environment
COPY --from=builder /opt/software /opt/software
COPY --from=builder /opt/._view /opt/._view
COPY --from=builder /etc/profile.d/z10_spack_environment.sh /etc/profile.d/z10_spack_environment.sh

# Some boilerplate to get all paths correctly - fix_spack_install is part of the base image
# and makes sure that all important things are being correctly setup
RUN fix_spack_install

RUN apt-get update \
&& env DEBIAN_FRONTEND=noninteractive TZ=Europe/Zurich apt-get -yqq install --no-install-recommends build-essential

# Finally do what we need
COPY . /src

RUN cd /src \
&& mpicc mpi_send_recv.c -o mpi_send_recv
66 changes: 66 additions & 0 deletions test/mpi_simple/mpi_send_recv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/****************************************************************
* *
* This file has been written as a sample solution to an *
* exercise in a course given at the CSCS Summer School. *
* It is made freely available with the understanding that *
* every copy of this file must include this header and that *
* CSCS take no responsibility for the use of the enclosed *
* teaching material. *
* *
* Purpose: A program to try MPI_Comm_size and MPI_Comm_rank. *
* *
* Contents: C-Source *
****************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <mpi.h>


int main(int argc, char *argv[])
{
/* declare any variables you need */
int rank;
int size;
int number;
MPI_Status status;

MPI_Init(&argc, &argv);

/* Get the rank of each process */
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

/* Get the size of the communicator */
MPI_Comm_size(MPI_COMM_WORLD, &size);

/* Write code such that every process writes its rank and the size of the communicator,
* but only process 0 prints "hello world*/
printf("Process %d out of %d.\n", rank, size);

/* Check communicator size */
if (size != 2) {
printf("Error: Proces %d: communicator size %d, expected 2.\n", rank, size);
MPI_Finalize();
exit(1);
}

/* Check send, receive */
if (rank == 0) {
number = 42;
printf("Process %d: sending number %d\n", rank, number);
MPI_Send(&number, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}

if (rank == 1) {
MPI_Recv(&number, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, &status);
printf("Process %d: received number %d\n", rank, number);
if (number != 42) {
printf("Error: Process %d: received %d, expected 42.\n", rank, number);
MPI_Finalize();
exit(1);
}
}

MPI_Finalize();
return 0;
}

0 comments on commit 120ebb6

Please sign in to comment.