Advertisement
Guest User

Untitled

a guest
Dec 7th, 2015
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.50 KB | None | 0 0
  1. ---------- entry.cpp ----------
  2.  
  3. #include <divine.h>
  4. #include <divine/problem.h>
  5. #include <mpi.h>
  6. #include <cstdlib>
  7.  
  8. int _mpi_num_processes = 0;
  9. int _mpi_exit_barrier = 0;
  10.  
  11. extern "C" {
  12.     int main(...);
  13.     struct global_ctor { int prio; void (*fn)(); };
  14.  
  15.     int _divine_invoke_main( int mainproto )
  16.     {
  17.         switch ( mainproto ) {
  18.             case 0: return main();
  19.             case 1: return main( 0 );
  20.             case 2: return main( 0, 0 );
  21.             case 3: return main( 0, 0, 0 );
  22.             default: __divine_problem( 1, "don't know how to run main()" );
  23.         }
  24.     }
  25.  
  26.     void _divine_invoke_main_mpi( void *mainproto )
  27.     {
  28.         // run main
  29.         int r = _divine_invoke_main( *((int *) mainproto) );
  30.  
  31.         // check whether MPI_Finalize has been called
  32.         int finalized; MPI_Finalized( &finalized );
  33.         if ( !finalized ) {
  34.             __divine_problem( Other,
  35.                     "MPI_Finalize not called before program termination" );
  36.         }
  37.  
  38.         // synchronize thread exits because it's needed apparently TODO desc
  39.         __divine_interrupt_mask();
  40.         ++_mpi_exit_barrier;
  41.  
  42.         while ( !(_mpi_exit_barrier == _mpi_num_processes &&
  43.                 __divine_get_tid() == 0) ) {
  44.             __divine_interrupt_unmask();
  45.             __divine_interrupt_mask();
  46.         }
  47.  
  48.         exit( r ); // only thread 0 gets here
  49.     }
  50.  
  51.     void _divine_start( int ctorcount, void *ctors, int mainproto )
  52.     {
  53.         global_ctor *c = reinterpret_cast< global_ctor * >( ctors );
  54.         for ( int i = 0; i < ctorcount; ++i ) {
  55.             c->fn();
  56.             c ++;
  57.         }
  58.  
  59.         if ( _mpi_num_processes == 0 ) {
  60.             // normal startup (no MPI): run main in one thread
  61.             int r = _divine_invoke_main( mainproto );
  62.             exit( r );
  63.         } else {
  64.             // MPI startup: perform global MPI initialization...
  65.             _divine_mpi_global_initialize();
  66.  
  67.             // ...and run main in the specified number of MPI processes (which
  68.             // are implemented as threads currently)
  69.             for ( int i = 0; i < _mpi_num_processes - 1; ++i ) {
  70.                 __divine_new_thread( _divine_invoke_main_mpi,
  71.                         (void *) &mainproto );
  72.             }
  73.             _divine_invoke_main_mpi( (void *) &mainproto );
  74.         }
  75.     }
  76. }
  77.  
  78. ---------- mpi.cpp ----------
  79.  
  80. void _divine_mpi_global_initialize() {
  81.     // initialize internal globals
  82.     _initialized_ = new (nofail) bool[_mpi_num_processes] {};
  83.     _finalized_ = new (nofail) bool[_mpi_num_processes] {};
  84.     _buffer_attached_ = new (nofail) bool[_mpi_num_processes] {};
  85.  
  86.     assert(_mpi_num_processes == 2); //DEBUG
  87.  
  88.     _attached_buffer_ = new (nofail) char*[2/*_mpi_num_processes*/]; // {}; //XXX
  89.     _attached_buffer_size_ = new (nofail) int[2/*_mpi_num_processes*/]; // {}; //XXX
  90.     _queue_head_ = new (nofail) PMEHeader*[2/*_mpi_num_processes*/]; // {}; //XXX
  91.     _queue_tail_ = new (nofail) char*[2/*_mpi_num_processes*/]; // {}; //XXX
  92.     _num_entries_ = new (nofail) int[2/*_mpi_num_processes*/] {};
  93.  
  94.     // create predefined datatypes and reduction operations
  95.     create_predefined_datatypes();
  96.     create_predefined_reduction_operations();
  97.  
  98.     // create the empty group
  99.     MPI_GROUP_EMPTY = new (nofail) _Group {};
  100.  
  101.     // prepare predefined communicators
  102.     MPI_COMM_WORLD_ = new (nofail) MPI_Comm[2/*_mpi_num_processes*/] {}; //DEBUG
  103.     MPI_COMM_SELF_ = new (nofail) MPI_Comm[2/*_mpi_num_processes*/] {}; //DEBUG
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement