100 likes | 212 Vues
This reference material discusses issues with nested software layers using MPI, providing solutions like MPI_INIT_SAFE and MPI_FINALIZE_SAFE to handle initialization and finalization more effectively. It addresses race conditions, thread safety, and correct usage scenarios.
E N D
Reference-countedINIT and FINALIZE Jeff Squyres and Brian Barrett
The Problem • INIT and FINALIZE can only be called once • Problematic for nested software layers that use MPI • …especially when the layers are unrelated • …especially in multi-threaded scenarios • MPI_INITIALIZED is not enough • Race condition between checking INITIALIZED and calling INIT • How to determine who calls MPI_FINALIZE? • FINALIZED does not help
Simple solution:INIT reference count • MPI_INIT_SAFE(argc, argv, required, provided) • Essentially the same as INIT_THREAD • But it can safely be called multiple times • Will initialize MPI exactly once the first time it is invoked • Implementation choice what to return in “provided” after the 1st call • Guaranteed safe if multiple threads call it simultaneously • Will not return until MPI is initialized • (replace _SAFE with a better name)
INIT_SAFE Barrier Keep barrier-like semantics of MPI_INIT_SAFE Application’s responsibility to make sure the barrier from MPI_INIT_SAFE calls “match” as desired
FINALIZE_SAFE • MPI_FINALIZE_SAFE(finalized) • Analogous to MPI_INIT_SAFE • After FINALIZE_SAFE has been invoked as many times as INIT_SAFE, MPI is actually finalized • finalized returns whether MPI was actually finalized • May also be desirable to make FINALIZE_SAFE return a non-fatal error if MPI has already been finalized • Prevent thread races trying to guarantee MPI finalization
Solves the problem Software layer A MPI_INIT_SAFE . . . . . MPI_FINALIZE_SAFE This INIT_SAFE is after the FINALIZE_SAFE in layer A. w00t! Software layer B MPI_INIT_SAFE . . . . . MPI_FINALIZE_SAFE Time Software layer C MPI_INIT_SAFE . . . . . MPI_FINALIZE_SAFE
Definitions • Still not allowing MPI to be initialized after it has been finalized • Amend INITIALIZED definition: • Current: “returns true if MPI_INIT has been called” • Change: “returns true if MPI has been initialized” • Amend FINALIZED definition: • Current: “returns true if MPI_FINALIZE has completed” • Change: “returns true if MPI has been finalized”
Mixing SAFE and (not) • What if one thread calls INIT[_THREAD] and another calls INIT_SAFE? • Similar issue for FINALIZE / FINALIZE_SAFE • Several choices: • Error (i.e., do not allow mixing) • If INIT called, it must be first. INIT_SAFE is OK after that • If INIT_SAFE invoked first, INIT / INIT_THREAD behaves just like INIT_SAFE (for legacy middleware) • If INIT_SAFE invoked at all, INIT / INIT_THREAD behaves just like INIT_SAFE • …?
Mixing SAFE and (not) • Finalize choices: • FINALIZE ignores ref count and finalizes everything • If initialized refcount > 1, FINALIZE acts like FINALIZE_SAFE • No notification is provided via FINALIZE as to whether MPI is actually finalized