3.1.8.1. c3po.services.ListingWriter module

Inheritance diagram of c3po.services.ListingWriter

Contain the class ListingWriter.

class c3po.services.ListingWriter.ListingWriter(listingFile)

Bases: object

ListingWriter allows, in association with c3po.services.tracer.tracer, to write a global coupling listing file with calculation time measurement.

ListingWriter is completed by the funtions mergeListing(), getTotalTimePhysicsDriver() and getTimesExchanger().

__init__(listingFile)

Build a ListingWriter object.

Parameters:

listingFile – A file object which has to be already open in written-binary mode (file = open("file.txt", "wb")). It has to be closed (file.close()) by caller.

enumBilan = 3
enumCloseTop = 2
enumContinue = 6
enumEntete = 1
enumInterrupt = 5
enumTerm = 4
enumTop = 0
initialize(physics, exchangers, force=False)

Clear and initialize the object.

Can be replace by a call to terminate() (optional for the first call) followed by calls to setPhysicsDriverName() and setExchangerName().

setPhysicsDriverName() and setExchangerName() can also be used after initialize(), but not before (what is set before is forgotten).

Parameters:
  • physics (list[tuple]]) – A list of tuples (object, name). object should be a PhysicsDriver, modified with c3po.services.tracer.tracer() to point on this ListingWriter object. An object that does not meet these conditions is ignored. A column (entitled with name) is created in the listing file for each of them.

  • exchangers (list[tuple]]) – A list of tuples (object, name). object should be an Exchanger object, modified with c3po.services.tracer.tracer() to point on this ListingWriter object. An object that does not meet these conditions is ignored. name allows to identify them in the final listing file.

  • force (bool) – If set to True, physics and exchangers are added even if they do not meet the previously defined conditions.

prepare()

INTERNAL

setExchangerName(exchanger, name, force=False)

Get ready to write a listing with the provided Exchanger.

Parameters:
  • exchanger (Exchanger) – A Exchanger object, modified with c3po.services.tracer.tracer() to point on this ListingWriter object. If exchanger does not meet these conditions, it is ignored. Otherwise, a lign will be written in the listing for each call of exchanger’s exchange() method .

  • name (str) – The name to use for exchanger in the listing.

  • force (bool) – If set to True, exchanger is added even if it does not meet the previously defined conditions.

setPhysicsDriverName(physics, name, force=False)

Get ready to write a listing with the provided PhysicsDriver.

Parameters:
  • physics (PhysicsDriver) – A PhysicsDriver object, modified with c3po.services.tracer.tracer() to point on this ListingWriter object. If physics does not meet these conditions, it is ignored. Otherwise, a column (entitled with name) will be created in the listing file for it.

  • name (str) – The name to use for physics in the listing.

  • force (bool) – If set to True, physics is added even if it does not meet the previously defined conditions.

terminate()

Get ready to write a new listing.

What was previously set by initialize(), setPhysicsDriverName() and setExchangerName() is forgotten.

writeAfter(sourceObject, inputVar, outputTuple, methodName, presentTime, calculationTime)

INTERNAL

writeInitialize(presentTime)

INTERNAL

writeTerminate()

INTERNAL

writeValidate(timeValid)

INTERNAL

class c3po.services.ListingWriter.MergedListingWriter(listingFile)

Bases: ListingWriter

INTERNAL

__init__(listingFile)

INTERNAL

enumExchangeElem = 9
enumExchangeEnd = 8
enumExchangeStart = 7
enumPhysicsEnd = 8
enumPhysicsStart = 7
prepare()

INTERNAL

readLastLine()

INTERNAL

writeAfterExchange(sourceObject, toWrite, methodName, involvedPhysics, runningPhysics, presentTime)

INTERNAL

writeAfterNew(sourceObject, toWrite, methodName, runningPhysics, presentTime)

INTERNAL

writeBefore(sourceObject, toWrite, methodName, runningPhysics, presentTime, calculationTime)

INTERNAL

writeBeforeExchange(sourceObject, toWrite, methodName, involvedPhysics, runningPhysics, presentTime, calculationTime)

INTERNAL

c3po.services.ListingWriter.getFormattedTime(timeValue)

INTERNAL

c3po.services.ListingWriter.getTimesExchanger(listingName, exchangerName, physicsDriverNames)

getTimesExchanger() reads a listing file produced by ListingWriter or mergeListing and returns time information about a chosen exchanger (during the last calculation).

For each PhysicsDriver involved in the exchange, the function distinguishes between exchange time and waiting time. The exchange is assumed to really begin when all involved PhysicsDriver enter the exchange. For each of them, the waiting time is the time spent in the exchange before they all enter it. The exchange time is the time from this “real beginning” to the end of the exchange (from the point of view of each PhysicsDriver).

Parameters:
  • listingName – Name of the listing file to read.

  • exchangerName – Name (given in the listing file) of the Exchanger for which time information is requested.

  • physicsDriverNames (list) – List of the names of the PhysicsDriver (given in the listing file) involved in the Exchanger. They must be really involved!

Returns:

A list of len(physicsDriverNames) elements, in the same order than physicsDriverNames. Each element is a list of two values: first the total exchange time spent by this PhysicsDriver in the Exchanger, then its total waiting time in the Exchanger.

Return type:

list

c3po.services.ListingWriter.getTotalTimePhysicsDriver(listingName, physicsDriverName, methodNames=['initialize', 'computeTimeStep', 'initTimeStep', 'solveTimeStep', 'iterateTimeStep', 'validateTimeStep', 'setStationaryMode', 'abortTimeStep', 'resetTime', 'terminate', 'save', 'restore'])

getTotalTimePhysicsDriver() reads a listing file produced by ListingWriter or mergeListing and returns the total time spent by one PhysicsDriver in indicated methods (in the last calculation).

Parameters:
  • listingName – Name of the listing file to read.

  • physicsDriverName – Name (given in the listing file) of the PhysicsDriver for which the total time is requested.

  • methodNames (list) – List of the names of the methods to take into account. By defaut: everything but "exchange": ["initialize", "computeTimeStep", "initTimeStep", "solveTimeStep", "iterateTimeStep", "validateTimeStep",  "setStationaryMode", "abortTimeStep", "resetTime", "terminate", "save", "restore"].

Return type:

The total time spent by the PhysicsDriver in the indicated methods.

c3po.services.ListingWriter.goToLastBox(listingFile)

INTERNAL

c3po.services.ListingWriter.mergeListing(listingsName, newListingName)

mergeListing() allows to merge listing files produced by ListingWriter (or by previous call to mergeListing()).

It is designed to produce a comprehensive view of a MPI calculation. Only the last listing box of the provided files are considered.

Warning

Each of the provided files must contain one and only one listing (one table).

Parameters:
  • listingsName (list) – List of the name of the listing files to merge.

  • newListingName – Name of the file to write.