# Path: modred/parallel.py
# def get_hostname():
# def get_node_ID():
# def get_num_nodes():
# def get_num_MPI_workers():
# def get_rank():
# def get_num_procs():
# def is_distributed():
# def is_rank_zero():
# def barrier():
# def print_from_rank_zero(msg, output_channel='stdout'):
# def call_from_rank_zero(func, *args, **kwargs):
# def bcast(vals):
# def call_and_bcast(func, *args, **kwargs):
# def find_assignments(tasks, task_weights=None):
# def check_for_empty_tasks(task_assignments):


import os
import numpy as np
import modred as mr
from modred import parallel




# Create directory for output files
out_dir = 'tutorial_ex5_out'
if not os.path.isdir(out_dir):
    os.makedirs(out_dir)

# Create artificial sample times used as quadrature weights in POD
num_vecs = 100
quad_weights = np.logspace(1., 3., num=num_vecs)
base_vec_handle = mr.VecHandlePickle('%s/base_vec.pkl' % out_dir)
snapshots = [
    mr.VecHandlePickle(
        '%s/vec%d.pkl' % (out_dir, i),base_vec_handle=base_vec_handle,
        scale=quad_weights[i])
    for i in mr.range(num_vecs)]

# Save arbitrary snapshot data
num_elements = 2000
if parallel.is_rank_zero():
    for snap in snapshots + [base_vec_handle]:
        snap.put(np.random.random(num_elements))

# Path: modred/parallel.py
# def get_hostname():
# def get_node_ID():
# def get_num_nodes():
# def get_num_MPI_workers():
# def get_rank():
# def get_num_procs():
# def is_distributed():
# def is_rank_zero():
# def barrier():
# def print_from_rank_zero(msg, output_channel='stdout'):
# def call_from_rank_zero(func, *args, **kwargs):
# def bcast(vals):
# def call_and_bcast(func, *args, **kwargs):
# def find_assignments(tasks, task_weights=None):
# def check_for_empty_tasks(task_assignments):


# Path: modred/examples/tutorial_ex5.py
import os
import numpy as np
import modred as mr
from modred import parallel





# Create directory for output files
out_dir = 'tutorial_ex5_out'
if not os.path.isdir(out_dir):
    os.makedirs(out_dir)

# Create artificial sample times used as quadrature weights in POD
num_vecs = 100
quad_weights = np.logspace(1., 3., num=num_vecs)
base_vec_handle = mr.VecHandlePickle('%s/base_vec.pkl' % out_dir)
snapshots = [
    mr.VecHandlePickle(
        '%s/vec%d.pkl' % (out_dir, i),base_vec_handle=base_vec_handle,
        scale=quad_weights[i])
    for i in mr.range(num_vecs)]

# Save arbitrary snapshot data
num_elements = 2000
if parallel.is_rank_zero():
    for snap in snapshots + [base_vec_handle]:
        snap.put(np.random.random(num_elements))

parallel.barrier()