Skip to content

Instantly share code, notes, and snippets.

@project-tuva
project-tuva / MPIFileHandler.py
Created July 23, 2018 21:14
logging with mpi4py
# -*- coding: utf-8 -*-
"""
Created on Wed Feb 14 16:17:38 2018
This handler is used to deal with logging with mpi4py in Python3.
@author: cheng
@reference:
https://cvw.cac.cornell.edu/python/logging
https://groups.google.com/forum/#!topic/mpi4py/SaNzc8bdj6U
@project-tuva
project-tuva / mpi4py_logger.py
Created August 2, 2018 07:43 — forked from JohnCEarls/mpi4py_logger.py
Creates a file handler that uses a shared mpi file for logging using the base python logging module. Based on Lisandro's post at https://groups.google.com/forum/#!topic/mpi4py/SaNzc8bdj6U in the mpi4py newsgroup.
import logging
from mpi4py import MPI
class MPIFileHandler(logging.FileHandler):
def __init__(self,filename, mode=MPI.MODE_WRONLY|MPI.MODE_CREATE|MPI.MODE_APPEND , encoding=None, delay=0, comm=MPI.COMM_WORLD ):
encoding = None
self.baseFilename = os.path.abspath(filename)
self.mode = mode
self.encoding = encoding
self.comm = comm