Skip to content

Commit

Permalink
new test script; updated container files
Browse files Browse the repository at this point in the history
  • Loading branch information
moustakas committed Dec 17, 2024
1 parent 7d34083 commit 6b4e070
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 19 deletions.
18 changes: 10 additions & 8 deletions docker/Containerfile-base
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM ubuntu:24.04

RUN mkdir -p /src
WORKDIR /src

RUN mkdir -p /src
RUN apt-get -y clean && apt -y update && apt install -y apt-utils && apt -y upgrade

RUN DEBIAN_FRONTEND=noninteractive \
Expand All @@ -11,7 +11,6 @@ RUN DEBIAN_FRONTEND=noninteractive \
gfortran \
wget \
git \
pkg-config \
libbz2-dev \
libgsl-dev \
libssl-dev \
Expand All @@ -25,7 +24,7 @@ RUN DEBIAN_FRONTEND=noninteractive \
python3-pip \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

ARG mpich=4.1.1
ARG mpich=3.4.3
ARG mpich_prefix=mpich-$mpich

ENV FFLAGS="-fallow-argument-mismatch" \
Expand All @@ -34,8 +33,8 @@ ENV FFLAGS="-fallow-argument-mismatch" \
RUN wget --no-check-certificate -nv https://www.mpich.org/static/downloads/$mpich/$mpich_prefix.tar.gz \
&& tar xvzf $mpich_prefix.tar.gz \
&& cd $mpich_prefix \
&& ./configure \
&& make -j 4 \
&& ./configure --with-device=ch4:ofi \
&& make -j 16 \
&& make install \
&& make clean \
&& cd .. \
Expand All @@ -44,8 +43,11 @@ RUN wget --no-check-certificate -nv https://www.mpich.org/static/downloads/$mpic

RUN /sbin/ldconfig

SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/bin/bash"]
ENV PIP_ROOT_USER_ACTION=ignore

RUN ln -s "$(which python3)" /usr/bin/python

RUN pip3 install --break-system-packages mpi4py \
&& rm -Rf /root/.cache/pip

LABEL Maintainer="John Moustakas [email protected]"
15 changes: 5 additions & 10 deletions docker/Containerfile-test
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,29 @@
# podman-hpc build --tag desihub/fastspecfit-test --file ./Containerfile-test .
# podman-hpc migrate desihub/fastspecfit-test
# podman-hpc run --rm -it desihub/fastspecfit-test /bin/bash
# srun --ntasks=2 podman-hpc run --rm --mpi --entrypoint= -it desihub/fastspecfit-test /usr/local/bin/test-mpi-fastspecfit --mp=4
# srun --ntasks=2 podman-hpc run --rm --mpi -it desihub/fastspecfit-test /usr/local/bin/test-mpi-fastspecfit --mp=4

FROM desihub/fastspecfit-base:1.0

WORKDIR /src

RUN ln -s "$(which python3)" /usr/bin/python

ENV PIP_ROOT_USER_ACTION=ignore

RUN for x in \
wheel \
setuptools \
pytest \
numpy \
# numpy \
numba \
mpi4py \
ipython \
ipykernel \
; do pip3 install --break-system-packages $x; done \
&& rm -Rf /root/.cache/pip

COPY test-mpipool /usr/local/bin/test-mpipool
RUN chmod +x /usr/local/bin/test-mpipool

COPY test-mpi-fastspecfit /usr/local/bin/test-mpi-fastspecfit
RUN chmod +x /usr/local/bin/test-mpi-fastspecfit

# set prompt and default shell
SHELL ["/bin/bash", "-c"]
ENTRYPOINT ["/bin/bash", "-c"]
CMD ["/bin/bash"]

LABEL Maintainer="John Moustakas [email protected]"
13 changes: 12 additions & 1 deletion docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ podman-hpc migrate desihub/fastspecfit-base:1.0
podman-hpc push desihub/fastspecfit-base:1.0
```

podman-hpc run --userns keep-id --rm --volume=/dvs_ro/cfs/cdirs --volume=/pscratch -it fastspecfit-base:1.0 /bin/bash
Check the versions:
```
podman-hpc run --rm -it desihub/fastspecfit-base:1.0 mpirun --version
podman-hpc run --rm -it desihub/fastspecfit-base:1.0 python -m mpi4py --version
podman-hpc run --rm -it desihub/fastspecfit-base:1.0 python -m mpi4py --mpi-std-version
podman-hpc run --rm -it desihub/fastspecfit-base:1.0 python -m mpi4py --mpi-lib-version
```

```
srun --ntasks=4 podman-hpc run --rm -it --mpi desihub/fastspecfit-base:1.0 python -m mpi4py.bench helloworld
```


###

Expand Down
23 changes: 23 additions & 0 deletions docker/test-mpipool
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env python

from mpi4py.futures import MPIPoolExecutor
import numpy as np

def calculate_pi(n):
"""Calculate Pi using Monte Carlo method."""
x = np.random.rand(n)
y = np.random.rand(n)
inside_circle = (x**2 + y**2) <= 1
return 4 * np.sum(inside_circle) / n

if __name__ == "__main__":
mp = 16
n_points = 100000
with MPIPoolExecutor(mp) as P:
chunk_size = n_points // mp

results = P.map(calculate_pi, [chunk_size] * mp)
pi_approx = np.mean(list(results))

if P.is_master():
print(f"Approximation of pi: {pi_approx}")

0 comments on commit 6b4e070

Please sign in to comment.