Skip to content

Commit 36ce49b

Browse files
Merge branch 'PyORBIT-Collaboration:main' into mpi-bcast
2 parents 85e38f9 + 6cc7421 commit 36ce49b

18 files changed

+3500
-1281
lines changed

.github/workflows/compilation.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,28 @@ jobs:
121121
- name: Print Versions
122122
run: |
123123
.github/workflows/conda-versions.sh
124+
125+
mpich:
126+
runs-on: ubuntu-latest
127+
container:
128+
image: quay.io/centos/centos:stream9
129+
steps:
130+
- name: Install packages
131+
run: |
132+
dnf group install -y "Development Tools"
133+
dnf install -y python3-devel fftw3-devel mpich-devel hwloc-devel
134+
135+
- uses: actions/checkout@v4
136+
with:
137+
fetch-depth: 0
138+
- name: Build
139+
run: |
140+
.github/workflows/pip-build-mpich.sh
141+
142+
- name: Test
143+
run: |
144+
.github/workflows/pip-tests-mpi.sh
145+
146+
- name: Print Versions
147+
run: |
148+
.github/workflows/pip-versions.sh
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
python3 -m venv .po3
2+
sed -i 's|PATH="\$VIRTUAL_ENV\/"bin":\$PATH"|PATH="\$VIRTUAL_ENV\/"bin":\$PATH"\nsource /etc/profile.d/modules.sh\nmodule load mpi/mpich-x86_64|' .po3/bin/activate
3+
. .po3/bin/activate
4+
mpirun -V
5+
pip install -U pip
6+
pip install -r requirements.txt
7+
pip install -U setuptools
8+
pip install --verbose --config-settings=setup-args="-DUSE_MPI=mpich" .

.github/workflows/pip-tests-mpi.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
. .po3/bin/activate
2+
3+
# Simple test to check if MPI was linked at all
4+
mpirun -np 2 python examples/MPI_Tests/mpi_initialization_test.py | tee test.txt
5+
calculated_sha1=$(sha1sum test.txt | awk '{ print $1 }')
6+
[ "$calculated_sha1" != "d94e03044bf06c7a42d07505b50fa58b4b30e49a" ] && exit 1
7+
8+
# Uniformly charged sphere
9+
echo "Run with Ellipsoid space charge"
10+
mpirun -np 2 python examples/SpaceCharge/sc3D/sc_3d_drift_latt_uniform_sphere_bunch.py --SC ellipsoid| tee results.txt
11+
python examples/SpaceCharge/sc3D/read_sc_numbers.py
12+
[ $? != 0 ] && exit 1
13+
14+
echo "Run with FFT3D space charge"
15+
mpirun -np 2 python examples/SpaceCharge/sc3D/sc_3d_drift_latt_uniform_sphere_bunch.py --SC fft3d| tee results.txt
16+
python examples/SpaceCharge/sc3D/read_sc_numbers.py
17+
[ $? != 0 ] && exit 1
18+
19+
# this should fail as no space charge will give incorrect sphere size
20+
echo "Run with no space charge"
21+
mpirun -np 2 python examples/SpaceCharge/sc3D/sc_3d_drift_latt_uniform_sphere_bunch.py --SC none| tee results.txt
22+
python examples/SpaceCharge/sc3D/read_sc_numbers.py
23+
[ $? == 0 ] && exit 1
24+
25+
26+
# This tests that five nodes give the same result as one node
27+
echo "Run with 1 node."
28+
mpirun -np 1 python examples/SpaceCharge/sc3D/sc_3d_drift_latt_uniform_sphere_bunch.py | tee results1.txt
29+
calculated_sha1=$(sha1sum results1.txt | awk '{ print $1 }')
30+
31+
echo "Run with 5 nodes."
32+
mpirun -np 5 python examples/SpaceCharge/sc3D/sc_3d_drift_latt_uniform_sphere_bunch.py | tee results5.txt
33+
calculated_sha5=$(sha1sum results5.txt | awk '{ print $1 }')
34+
35+
echo "Diff between two runs."
36+
echo "$calculated_sha1" "$calculated_sha5"
37+
diff results1.txt results5.txt
38+
39+
[ "$calculated_sha1" != "$calculated_sha5" ] && exit 1
40+
41+
exit 0
42+

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# PyOrbit3 package installation
1+
# PyORBIT3 package installation
22

33
## 1. Introduction
44
This guide provides instructions how to install PyORBIT code. <br>
@@ -107,3 +107,22 @@ Navigate to your **examples** directory and launch tracking of SNS linac.
107107
cd examples/SNS_Linac/pyorbit3_linac_model/
108108
python pyorbit3_sns_linac_mebt_hebt2.py
109109
```
110+
111+
## 5. MPI consideration
112+
By default, the build system will try to find MPI and compile against it. You can control which MPI to use with command line option when building.
113+
```bash
114+
pip install --config-settings=setup-args="-DUSE_MPI=none" .
115+
```
116+
Above will build PyORBIT without MPI even if MPI is present. You can change that option to `mpich`, `ompi`, `none` or `auto` (default).<br>
117+
| MPI flavor | Installation command |
118+
|---------------|--------------|
119+
| No MPI | `pip install --config-settings=setup-args="-DUSE_MPI=none" .` |
120+
| The first found MPI installation if any | `pip install --config-settings=setup-args="-DUSE_MPI=auto" .` |
121+
| OpenMPI | `pip install --config-settings=setup-args="-DUSE_MPI=ompi" .` |
122+
| MPICH | `pip install --config-settings=setup-args="-DUSE_MPI=mpich" .` |
123+
124+
Meson uses PKG_CONFIG to discover packages. It could be useful to help it to find your MPI installation:
125+
126+
```bash
127+
PKG_CONFIG_PATH=/opt/lib/pkgconfig pip install --verbose .
128+
```

examples/MPI_Tests/mpi_initialization_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020

2121
mpi_init = orbit_mpi.MPI_Initialized()
22-
print ("debug mpi is initialized =",mpi_init," should be not zero.")
2322

2423
rank = orbit_mpi.MPI_Comm_rank(mpi_comm.MPI_COMM_WORLD)
2524
size = orbit_mpi.MPI_Comm_size(mpi_comm.MPI_COMM_WORLD)
2625

2726
if(rank == 0):
27+
print("debug mpi is initialized =", mpi_init, " should be not zero.")
2828
print ("debug there should only one line like this rank=",rank," N CPUs = ",size)
2929

3030
n_particles = 10
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#----------------------------------------------
2+
# This is an example of a polymonial fitting
3+
#----------------------------------------------
4+
5+
import sys
6+
import math
7+
import random
8+
9+
from orbit.core.orbit_utils import Matrix
10+
from orbit.core.orbit_utils import Function
11+
from orbit.core.orbit_utils import SplineCH
12+
13+
from orbit.utils.fitting import PolynomialFit
14+
15+
random_err_range = 0.001
16+
f = Function()
17+
for i in range(15):
18+
x = 0.1*i
19+
y = -1+1.0*x**2+2.0*x**3 + 0.01*x**4
20+
y += random.uniform(-random_err_range,+random_err_range)
21+
f.add(x,y)
22+
23+
print ("polynomial for fitting = y = -1+1.0*x**2+2.0*x**3 + 0.01*x**4")
24+
print ("================Function====================================")
25+
poly = PolynomialFit(4)
26+
poly.fitFunction(f)
27+
[coef_arr,err_arr] = poly.getCoefficientsAndErr()
28+
for i in range(len(coef_arr)):
29+
print ("i=",i," coef = %8.5f +- %8.5f"%(coef_arr[i],err_arr[i]))
30+
31+
print ("================SplineCH====================================")
32+
spline = SplineCH()
33+
spline.compile(f)
34+
poly.fitSpline(f)
35+
[coef_arr,err_arr] = poly.getCoefficientsAndErr()
36+
for i in range(len(coef_arr)):
37+
print ("i=",i," coef = %8.5f +- %8.5f"%(coef_arr[i],err_arr[i]))
38+
39+
print ("Stop.")
40+
sys.exit(0)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#-------------------------------------------------------------
2+
# This is an example of Polynomial class
3+
# The methods "derivativeTo","derivative", "copyTo" and "value" are included.
4+
#-------------------------------------------------------------
5+
6+
import sys
7+
import math
8+
9+
from orbit.core.orbit_utils import Polynomial
10+
11+
poly = Polynomial(4)
12+
print ("initial order = ",poly.order())
13+
14+
poly.coefficient(2,2.0)
15+
16+
print ("========Polynomial=======")
17+
order = poly.order()
18+
for i in range(order+1):
19+
print ("i=",i," coef=",poly.coefficient(i))
20+
21+
x = 10.
22+
y = poly.value(x)
23+
print ("x=",x," y=",y)
24+
25+
poly1 = Polynomial()
26+
poly.derivativeTo(poly1)
27+
28+
print ("========Derivative polynomial=======")
29+
order = poly1.order()
30+
for i in range(order+1):
31+
print ("i=",i," coef=",poly1.coefficient(i))
32+
33+
x = 10.
34+
y = poly1.value(x)
35+
yp = poly.derivative(x)
36+
print ("x=",x," y_prime=",y," yp =",yp)
37+
38+
print ("========Copy of initial polynomial=======")
39+
poly2 = Polynomial()
40+
poly.copyTo(poly2)
41+
order = poly2.order()
42+
for i in range(order+1):
43+
print ("i=",i," coef=",poly2.coefficient(i))
44+
45+
x = 10.
46+
y = poly2.value(x)
47+
yp = poly2.derivative(x)
48+
print ("x=",x," y=",y," y_prime=",yp)
49+
50+
"""
51+
# Memory leak test
52+
count = 1
53+
while(1 < 2):
54+
poly1 = Polynomial()
55+
poly2 = Polynomial()
56+
poly.derivativeTo(poly1)
57+
poly.copyTo(poly2)
58+
count += 1
59+
if(count % 100000 == 0):
60+
print ("count=",count)
61+
"""
62+
63+
print ("Stop.")
64+
sys.exit(0)
65+

0 commit comments

Comments
 (0)