Skip to content

Update cylcache #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 94 additions & 45 deletions How-To/Utilities/create Cylinder basis (parallel).py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# coding: utf-8

import pyEXP
import numpy as np
from mpi4py import MPI
import numpy as np
import argparse
import pyEXP

# Helper for nice parallel printing
#
def pprint(str="", end="\n", comm=MPI.COMM_WORLD):
"""Print for MPI parallel programs: Only rank 0 prints *str*."""
if comm.rank == 0:
print(str, end=end)

# Get the basis config
print(str+end, end='')
# A default and example cylindrical basis config
#
disk_config = """
id : cylinder
parameters :
acyl : 1.0
hcyl : 0.1
lmaxfid : 48
nmaxfid : 48
lmaxfid : 64
nmaxfid : 64
mmax : 10
nmax : 32
ncylodd : 6
ncylnx : 256
ncylny : 128
ncylr : 2000
Expand All @@ -32,50 +34,97 @@ def pprint(str="", end="\n", comm=MPI.COMM_WORLD):
rcylmax : 20
ashift : 0
logr : true
density : true
expcond : true
deproject : true
eof_file : .eof.cache.file_new
ignore : true
vflag : 16
cachename : eof.cache.file
"""

# Initialize MPI
#
world_comm = MPI.COMM_WORLD
world_size = world_comm.Get_size()
my_rank = world_comm.Get_rank()
def main():
global disk_config

# Just for info and to convince yourself check that MPI is working on
# your system
#
pprint("============================================================================")
pprint("Compute a Cylindrical basis on multiple nodes or on a laptop with MPI")
pprint("============================================================================")
# Initialize MPI
#
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
args = None

world_comm.Barrier()
print("World size is {} and my rank is {}".format(world_size, my_rank))
# Only root process parses and sends arguments to all processes
#
if rank == 0:

world_comm.Barrier()
pprint("============================================================================")
parser = argparse.ArgumentParser(
prog="cylcache",
description="Construction a cylindrical basis specified by a YAML config file",
epilog="Running with no arguments will use the default config provided as a template. Typical usage: mpirun -np 8 cylcache -c my_config.yaml"
)
parser.add_argument("-c", "--config", dest="config_file", help="The YAML basis config used construct a basis")
parser.add_argument("-t", "--template", dest="template_file", help="Write a sample default YAML basis config and exit")

# Begin calculation and start stopwatch
#
t_start = MPI.Wtime()
# Parse in input arguments
#
try:
args = parser.parse_args()
except:
args = None

# Pass the namespace to all processes
#
args = comm.bcast(args, root=0)

# Help?
#
if args is None:
MPI.Finalize()
exit(0)
else:
# Receive the namespace from the root process
#
args = comm.bcast(None, root=0)

# Construct the basis instance
#
disk_basis = pyEXP.basis.Basis.factory(disk_config)
# Help?
#
if args is None:
MPI.Finalize()
exit(0)

world_comm.Barrier()
# User asked for a template YAML file
#
if (args.template_file):
if rank == 0:
file = open(args.template_file, 'w')
file.write(disk_config)
MPI.Finalize()
exit(0)

pprint("============================================================================")
pprint("Calculation finished")
# User passed a config file
#
if (args.config_file):
file = open(args.config_file)
disk_config = file.read()

# Stop stopwatch
#
world_comm.Barrier()
t_diff = MPI.Wtime() - t_start
# Just for info and to convince yourself check that MPI is working
#
pprint("============================================================================")

# Begin calculation and start stopwatch
#
t_start = MPI.Wtime()

# Construct the basis instance
#
disk_basis = pyEXP.basis.Basis.factory(disk_config)

comm.Barrier()

pprint("---- Calculation finished")

# Stop stopwatch
#
comm.Barrier()
t_diff = MPI.Wtime() - t_start

pprint("---- Computed basis in {}".format(t_diff))
pprint("============================================================================")
MPI.Finalize()

pprint("Computed basis in {}".format(t_diff))
pprint("============================================================================")
if __name__ == "__main__":
main()
130 changes: 130 additions & 0 deletions How-To/Utilities/create cylinder basis
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env python3
# coding: utf-8

from mpi4py import MPI
import numpy as np
import argparse
import pyEXP

# Helper for nice parallel printing
#
def pprint(str="", end="\n", comm=MPI.COMM_WORLD):
"""Print for MPI parallel programs: Only rank 0 prints *str*."""
if comm.rank == 0:
print(str+end, end='')

# A default and example cylindrical basis config
#
disk_config = """
id : cylinder
parameters :
acyl : 1.0
hcyl : 0.1
lmaxfid : 64
nmaxfid : 64
mmax : 10
nmax : 32
ncylnx : 256
ncylny : 128
ncylr : 2000
rnum : 200
pnum : 1
tnum : 80
rcylmin : 0.001
rcylmax : 20
ashift : 0
logr : true
cachename : eof.cache.file
"""

def main():
global disk_config

# Initialize MPI
#
comm = MPI.COMM_WORLD
size = comm.Get_size()
rank = comm.Get_rank()
args = None

# Only root process parses and sends arguments to all processes
#
if rank == 0:

parser = argparse.ArgumentParser(
prog="cylcache",
description="Construction a cylindrical basis specified by a YAML config file",
epilog="Running with no arguments will use the default config provided as a template. Typical usage: mpirun -np 8 cylcache -c my_config.yaml"
)
parser.add_argument("-c", "--config", dest="config_file", help="The YAML basis config used construct a basis")
parser.add_argument("-t", "--template", dest="template_file", help="Write a sample default YAML basis config and exit")

# Parse in input arguments
#
try:
args = parser.parse_args()
except:
args = None

# Pass the namespace to all processes
#
args = comm.bcast(args, root=0)

# Help?
#
if args is None:
MPI.Finalize()
exit(0)
else:
# Receive the namespace from the root process
#
args = comm.bcast(None, root=0)

# Help?
#
if args is None:
MPI.Finalize()
exit(0)

# User asked for a template YAML file
#
if (args.template_file):
if rank == 0:
file = open(args.template_file, 'w')
file.write(disk_config)
MPI.Finalize()
exit(0)

# User passed a config file
#
if (args.config_file):
file = open(args.config_file)
disk_config = file.read()

# Just for info and to convince yourself check that MPI is working
#
pprint("============================================================================")

# Begin calculation and start stopwatch
#
t_start = MPI.Wtime()

# Construct the basis instance
#
disk_basis = pyEXP.basis.Basis.factory(disk_config)

comm.Barrier()

pprint("---- Calculation finished")

# Stop stopwatch
#
comm.Barrier()
t_diff = MPI.Wtime() - t_start

pprint("---- Computed basis in {}".format(t_diff))
pprint("============================================================================")
MPI.Finalize()

if __name__ == "__main__":
main()
8 changes: 4 additions & 4 deletions Tutorials/Coefficients/read and plot coefficients.ipynb

Large diffs are not rendered by default.

Loading