//******************************************************************** // Virtual World Data Server Client for Scientific Visualization Data // vwcMasterSlave classes for MPI // // // UCLA - OAC // Joan Slottow February 1999 // //******************************************************************** #ifndef vwc_masterslave #include "masterSlave.h" #endif //------------------------------------------------------------------------ //************************************************************************ // Class: vwcMasterSlave //************************************************************************ //------------------------------------------------------------------------ //************************************************************************ // constructor //************************************************************************ vwcMasterSlave::vwcMasterSlave( ) { } //************************************************************************ // destructor //************************************************************************ vwcMasterSlave::~vwcMasterSlave( ) { } //************************************************************************ // print //************************************************************************ void vwcMasterSlave::print( ) const { } //************************************************************************ // initialize // this must be the first function you call after the constructor //************************************************************************ void vwcMasterSlave::initialize( int argc, char *argv[ ] ) { int i; MPI::Init( argc,argv ); oMSMyNodeId = MPI::COMM_WORLD.Get_rank( ); oMSNOfNodes = MPI::COMM_WORLD.Get_size( ); oMSNOfSlaveNodes = oMSNOfNodes - 1; } //************************************************************************ // send //************************************************************************ void vwcMasterSlave::send( const char* msg, const int& to ) const { int len = strlen( ( char* )msg ); MPI::COMM_WORLD.Send( &len, 1, MPI::INT, to, ( int )1 ); MPI::COMM_WORLD.Send( msg, len, MPI::CHAR, to, ( int )1 ); } //************************************************************************ // receive //************************************************************************ void vwcMasterSlave::receive( char* msg, int& from ) const { int len; MPI::Status status; MPI::COMM_WORLD.Recv( &len, 1, MPI::INT, MPI::ANY_SOURCE, MPI::ANY_TAG, status ); from = ( ( int )status.Get_source( ) ); MPI::COMM_WORLD.Recv( msg, len, MPI::CHAR, from, MPI::ANY_TAG ); msg[ len ] = '\0'; } //************************************************************************ // runMasterSlave //************************************************************************ void vwcMasterSlave::runMasterSlave( ) { //********************************************************************* // Node ID 0 is the master, rest are slaves //********************************************************************* if ( oMSMyNodeId == 0) runMaster( ); else runSlave( ); MPI::Finalize( ); }