Example #1
0
    def mpirun_tests(args=None):
        """This is used in the "if __name__ == '__main__'" block to run all
        tests in that module.  The tests are run using mpirun.
        """
        if args is None:
            args = sys.argv[1:]

        mod = __import__('__main__')

        if '-ns' in args:
            nocap = False
        else:
            nocap = True

        tests = [n for n in args if not n.startswith('-')]
        options = [n for n in args if n.startswith('-')]

        if tests:
            for test in tests:
                tcase, _, method = test.partition('.')
                if method:
                    parent = getattr(mod, tcase)(methodName=method)
                    if hasattr(parent, 'N_PROCS') and not under_mpirun():
                        retcode = run_in_sub(getattr(mod, tcase), test, options)
                        continue
                else:
                    raise NotImplementedError("module test functions not supported yet")
                    #parent = mod
                    #method = tcase

                tspec = "%s:%s" % (mod.__file__, test)
                if MPI.COMM_WORLD.rank == 0:
                    sys.stdout.write("%s ... " % tspec)
                result = run_test(tspec, parent, method, nocap=nocap)

                if under_mpirun():
                    results = MPI.COMM_WORLD.gather(result, root=0)

                    if MPI.COMM_WORLD.rank == 0:
                        for i,r in enumerate(results):
                            if r.status != 'OK':
                                sys.stdout.write("%s\nERROR in rank %d:\n" % (r.status, i))
                                sys.stdout.write("%s\n" % r.err_msg)
                                break
                        else:
                            sys.stdout.write("%s\n" % r.status)
                else:
                    sys.stdout.write("%s\n" % r.status)

        else: # find all test methods in the file and mpi run ourselves for each one

            for k,v in getmembers(mod, isclass):
                if issubclass(v, TestCase):
                    for n, method in getmembers(v, ismethod):
                        if n.startswith('test_'):
                            testspec = k+'.'+n
                            if not hasattr(v, 'N_PROCS'):
                                print(run_test(testspec, v(methodName=n), n, nocap=nocap))
                            else:
                                retcode = run_in_sub(v, testspec, options)
Example #2
0
"""functions useful for debugging openmdao"""

import sys
from pprint import pformat

from openmdao.core.mpi_wrap import MPI, under_mpirun


if under_mpirun():
    def debug(*msg):
        newmsg = ["%d: " % MPI.COMM_WORLD.rank] + list(msg)
        for m in newmsg:
            sys.stdout.write("%s " % m)
        sys.stdout.write('\n')
        sys.stdout.flush()
else:
    def debug(*msg):
        for m in msg:
            sys.stdout.write("%s " % str(m))
        sys.stdout.write('\n')


def dump_meta(system, nest=0, out_stream=sys.stdout):
    """
    Dumps the system tree with associated metadata for the params and unknowns
    `VecWrappers`.

    Args
    ----
    system : `System`
        The node in the `System` tree where dumping begins.
Example #3
0
"""functions useful for debugging openmdao"""

import sys
from pprint import pformat

from openmdao.core.mpi_wrap import MPI, under_mpirun

if under_mpirun():

    def debug(*msg):
        newmsg = ["%d: " % MPI.COMM_WORLD.rank] + list(msg)
        for m in newmsg:
            sys.stdout.write("%s " % m)
        sys.stdout.write('\n')
        sys.stdout.flush()
else:

    def debug(*msg):
        for m in msg:
            sys.stdout.write("%s " % str(m))
        sys.stdout.write('\n')


def dump_meta(system, nest=0, out_stream=sys.stdout):
    """
    Dumps the system tree with associated metadata for the params and unknowns
    `VecWrappers`.

    Args
    ----
    system : `System`
Example #4
0
"""functions useful for debugging openmdao"""

import sys
from pprint import pformat

from openmdao.core.mpi_wrap import MPI, under_mpirun


def debug(*msg):
    for m in msg:
        sys.stdout.write("%s " % str(m))
    sys.stdout.write("\n")


if under_mpirun():  # pragma: no cover

    def debug(*msg):
        newmsg = ["%d: " % MPI.COMM_WORLD.rank] + list(msg)
        for m in newmsg:
            sys.stdout.write("%s " % m)
        sys.stdout.write("\n")
        sys.stdout.flush()


def dump_meta(system, nest=0, out_stream=sys.stdout):
    """
    Dumps the system tree with associated metadata for the params and unknowns
    `VecWrappers`.

    Args
    ----