-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Communicator of the correct size - Point to point communication works between nodes
- Loading branch information
Showing
3 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
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
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
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 |
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
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; | ||
} |