# 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 unittest
import os
import copy
from os.path import join
from modred import parallel
    from mpi4py import MPI
            from mpi4py import MPI
    def test_find_assignments(self):
        """Tests that the correct processor assignments are determined

        Given a list of tasks, it tests that the correct assignment list is
        returned. Rather than requiring the testutil.py script to be run
        with many different numbers of procs the behavior of this function
        is mimicked by manually setting num_MPI_workers
        """
        # Assume each item in task list has equal weight
        tasks = ['1', '2', '4', '3', '6', '7', '5']
        copy_task_list = copy.deepcopy(tasks)
        parallel._num_MPI_workers = 5
        correct_assignments = [['1'], ['2'], ['4', '3'], ['6'], ['7', '5']]
        self.assertEqual(
            parallel.find_assignments(tasks), correct_assignments)

        # Check that the original list is not modified.
        self.assertEqual(tasks, copy_task_list)

        tasks = [3, 4, 1, 5]
        parallel._num_MPI_workers = 2
        correct_assignments = [[3, 4], [1, 5]]
        self.assertEqual(
            parallel.find_assignments(tasks), correct_assignments)

        # Allow for uneven weighting of items in task list
        tasks = ['1', '2', '4', '3', '6', '7', '5']
        task_weights = [1, 3, 2, 3, 3, 2, 1]
        parallel._num_MPI_workers = 5
        correct_assignments = [['1','2'], ['4'], ['3'], ['6'], ['7', '5']]

# 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/tests/testparallel.py
import unittest
import os
import copy
from os.path import join
from modred import parallel
    from mpi4py import MPI
            from mpi4py import MPI

    def test_find_assignments(self):
        """Tests that the correct processor assignments are determined

        Given a list of tasks, it tests that the correct assignment list is
        returned. Rather than requiring the testutil.py script to be run
        with many different numbers of procs the behavior of this function
        is mimicked by manually setting num_MPI_workers
        """
        # Assume each item in task list has equal weight
        tasks = ['1', '2', '4', '3', '6', '7', '5']
        copy_task_list = copy.deepcopy(tasks)
        parallel._num_MPI_workers = 5
        correct_assignments = [['1'], ['2'], ['4', '3'], ['6'], ['7', '5']]
        self.assertEqual(
            parallel.find_assignments(tasks), correct_assignments)

        # Check that the original list is not modified.
        self.assertEqual(tasks, copy_task_list)

        tasks = [3, 4, 1, 5]
        parallel._num_MPI_workers = 2
        correct_assignments = [[3, 4], [1, 5]]
        self.assertEqual(
            parallel.find_assignments(tasks), correct_assignments)

        # Allow for uneven weighting of items in task list
        tasks = ['1', '2', '4', '3', '6', '7', '5']
        task_weights = [1, 3, 2, 3, 3, 2, 1]
        parallel._num_MPI_workers = 5
        correct_assignments = [['1','2'], ['4'], ['3'], ['6'], ['7', '5']]

        self.assertEqual(parallel.find_assignments(