-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from tskisner/more_tests
Expand unit tests.
- Loading branch information
Showing
5 changed files
with
143 additions
and
29 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
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,49 @@ | ||
import numpy as np | ||
from mpi4py import MPI | ||
|
||
from pshmem import MPIShared | ||
|
||
comm = MPI.COMM_WORLD | ||
|
||
with MPIShared((3, 5), np.float64, comm) as shm: | ||
# A copy of the data exists on every node and is initialized to zero. | ||
# There is a numpy array "view" of that memory available with slice notation | ||
# or by accessing the "data" member: | ||
if comm.rank == 0: | ||
# You can get a summary of the data by printing it: | ||
print("String representation:\n") | ||
print(shm) | ||
print("\n===== Initialized Data =====") | ||
for p in range(comm.size): | ||
if p == comm.rank: | ||
print("rank {}:\n".format(p), shm.data, flush=True) | ||
comm.barrier() | ||
|
||
set_data = None | ||
set_offset = None | ||
if comm.rank == 0: | ||
set_data = np.arange(6, dtype=np.float64).reshape((2, 3)) | ||
set_offset = (1, 1) | ||
|
||
# The set() method is collective, but the inputs only matter on one rank | ||
shm.set(set_data, offset=set_offset, fromrank=0) | ||
|
||
# You can also use the usual '[]' notation. However, this call must do an | ||
# additional pre-communication to detect which process the data is coming from. | ||
# And this line is still collective and must be called on all processes: | ||
shm[set_offset] = set_data | ||
|
||
# This updated data has now been replicated to the shared memory on all nodes. | ||
if comm.rank == 0: | ||
print("======= Updated Data =======") | ||
for p in range(comm.size): | ||
if p == comm.rank: | ||
print("rank {}:\n".format(p), shm.data, flush=True) | ||
comm.barrier() | ||
|
||
# You can read from the node-local copy of the data from all processes, | ||
# using either the "data" member or slice access: | ||
if comm.rank == comm.size - 1: | ||
print("==== Read-only access ======") | ||
print("rank {}: shm[2, 3] = {}".format(comm.rank, shm[2, 3]), flush=True) | ||
print("rank {}: shm.data = \n{}".format(comm.rank, shm.data), flush=True) |
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,15 @@ | ||
#!/bin/bash | ||
|
||
|
||
docker run \ | ||
-it \ | ||
-v $(pwd):/home/pshmem \ | ||
quay.io/pypa/manylinux2014_x86_64:latest \ | ||
/bin/bash | ||
|
||
# export PATH=/opt/python/cp38-cp38/bin:${PATH} | ||
# python3 -m pip install --upgrade pip | ||
# yum -y update | ||
# yum -y install mpich-3.2-devel.x86_64 mpich-3.2-autoload.x86_64 | ||
# source /etc/profile.d/modules.sh | ||
# source /etc/profile.d/mpich-3.2-x86_64.sh |