2017-10-20 23 views
1

私はmpi4pyというプログラムを断続的に実行しています。どのように個々のプロセスが何をしているのかを追跡できますか?並列Pythonプログラム(mpi4py)のデバッグ

私はpdb

mpiexec -n 4 xterm -e "python -m pdb my_program.py" 

を使用して、たとえば、異なる端末でプログラムを実行することができます。しかし、問題は、唯一の(私の場合〜80)多数のプロセスで現れる場合、これは面倒な取得します。さらに、pdbで例外を捕捉するのは簡単ですが、ハングがどこで発生するのか把握するためにトレースを確認する必要があります。

答えて

0

Python traceモジュールでは、プログラムの実行をトレースできます。個別に各プロセスのトレースを保存するためには、あなたが関数内のコードをラップする必要があります。その後、

def my_program(*args, **kwargs): 
    # insert your code here 
    pass 

そしてtrace.Trace.runfuncでそれを実行します。

import sys 
import trace 

# define Trace object: trace line numbers at runtime, exclude some modules 
tracer = trace.Trace(
    ignoredirs=[sys.prefix, sys.exec_prefix], 
    ignoremods=[ 
     'inspect', 'contextlib', '_bootstrap', 
     '_weakrefset', 'abc', 'posixpath', 'genericpath', 'textwrap' 
    ], 
    trace=1, 
    count=0) 

# by default trace goes to stdout 
# redirect to a different file for each processes 
sys.stdout = open('trace_{:04d}.txt'.format(COMM_WORLD.rank), 'w') 

tracer.runfunc(my_program) 

今、各プロセスのトレースが可能になります別のファイルtrace_0001.txtなどで書かれています。低レベルの呼び出しを省略するには、とignoremods引数を使用します。