generated from MacroSight-LLC/Parallel-Scripting-Technical-Assesment-REPO1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhello-world-mpi-container.def
50 lines (38 loc) · 1.41 KB
/
hello-world-mpi-container.def
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# hello-world-mpi-container.def
Bootstrap: docker
From: ubuntu:20.04
%post
# Install required packages
apt-get update
apt-get install -y wget build-essential libopenmpi-dev
# Download and install Miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh -b -p /opt/conda
rm Miniconda3-latest-Linux-x86_64.sh
# Set up Conda environment
/opt/conda/bin/conda init
/opt/conda/bin/conda create -y -n mpi_env
/opt/conda/bin/conda activate mpi_env
/opt/conda/bin/conda install -y -c conda-forge openmpi
# Compile Hello World MPI program
mkdir /opt/hello-world
echo '#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
int world_size, world_rank, name_len;
char hostname[MPI_MAX_PROCESSOR_NAME];
MPI_Init(&argc, &argv);
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
MPI_Get_processor_name(hostname, &name_len);
printf("Hello world from processor %s, rank %d out of %d processors\n", hostname, world_rank, world_size);
MPI_Finalize();
return 0;
}' > /opt/hello-world/hello.c
mpicc /opt/hello-world/hello.c -o /opt/hello-world/hello
%environment
export PATH=/opt/conda/bin:$PATH
source /opt/conda/etc/profile.d/conda.sh
conda activate mpi_env
%runscript
/opt/conda/bin/mpirun /opt/hello-world/hello