Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages | Examples

TestServer_MPI.cc

#include "mpi.h"

#include <unistd.h>
#include <iostream>
#include <cassert>
#include "ColCOWS.hh"
 
#include "echo.hh"
#ifdef ORBACUS_ORB
#include "echo_skel.hh" 
#endif

using namespace std;

//===========================================================================//

int main(int argc, char** argv) {

  char c;
  int psize, prank;

  //=======================================//
  string local_ws_id    = "B";
  string local_ws_kind  = "TestServer";
  string node_kind      = "regular_node";
  //=======================================//

  // initialisation
  if(argc == 1) {
  }
  else if(argc >= 3) {
    local_ws_id   = argv[1];
    local_ws_kind = argv[2];
  }
  else {
    cerr << "usage: [local_ws_id] [local_ws_kind] [ORB options]" << endl;
    return 0;
  }

  // MPI initialisation
  MPI_Init(&argc,&argv);
  MPI_Comm_size(MPI_COMM_WORLD,&psize);
  MPI_Comm_rank(MPI_COMM_WORLD,&prank);

  //! Pointer on the ORB
  CORBA::ORB_ptr _orbp;
  PortableServer::POA_var _poa;
  PortableServer::POAManager_var  _poa_man;

  // start corba server
  _orbp = CORBA::ORB_init(argc, argv);
    
  // Obtain a reference of the root POA
  CORBA::Object_var objref = _orbp->resolve_initial_references("RootPOA");
  _poa = PortableServer::POA::_narrow(objref);

  // Get and  Activate the POA Manager
  _poa_man = _poa->the_POAManager( );
  _poa_man->activate( );


  cout << endl << "**************** CREATE NODES ****************" << endl;
  ColCOWS::Node * collectiveNode = NULL;

  // create local nodes
  ColCOWS::Node * localNode;

  localNode = ColCOWS::Node::NewNode( local_ws_id,      // WorkSpace ID 
                                      local_ws_kind,    // WorkSpace kind
                                      node_kind,         // Node kind
                                      prank,             // Rank of the node
                                      psize,             // Number of nodes
                                      _orbp );           // ORB pointer
                                      
  cout << endl << "**************** ACTIVATION ****************" << endl;

  // activation
  localNode->activate();

  localNode->waitActivation();

  if (prank == 0) {
    cout << endl << "To call 'echo' press any key (x - exit) > " << flush; cin >> c;

    while (c != 'x') {

      if (c == 't') {
      }
      else { 
        cout << endl << endl << "**************** EXPERIMENT 2 ****************" << endl << endl;

        ColCOWS::RemoteWorkspaceManager * ws_manager = localNode->getRemoteWorkspaceManager();
        cout << "Got " << ws_manager->size() << " num connection ..." << endl;

        ColCOWS::RemoteWorkspaceManager::iterator wsm_it, wsm_it_begin, wsm_it_end;
        wsm_it_begin = ws_manager->begin();
        wsm_it_end = ws_manager->end();

        for (wsm_it = wsm_it_begin; wsm_it != wsm_it_end; wsm_it++  )
          {
            cout << "for connection " << wsm_it->first  << endl;
            ColCOWS::WorkspaceDesc * ws_desc = wsm_it->second;
            
            vector< ColCOWS::ExtObjectDesc >  ref_vec;
            vector< ColCOWS::ExtObjectDesc >::iterator  ref_it;
            
            ws_desc->getObjectDescVec(ref_vec, "" , "echo", "echo-echo");
            cout << "Got " << ref_vec.size() << " references ..." << endl;
            
            for (ref_it = ref_vec.begin(); ref_it != ref_vec.end(); ++ref_it  ){
              if (! CORBA::is_nil(ref_it->obj_ref)) {
                Echo_var echo = Echo::_narrow(ref_it->obj_ref);
                
                cout << "( " << ref_it->num_node << " "  << ref_it->obj_id << ":"  << ref_it->obj_kind
                     << " ) -> echo() = " << echo->echoString("new coucou !!") << endl;
              }
            }
          } 
      }

      cout << endl << "(x - exit) > " << flush; cin >> c;

    }

    cout << endl << "**************** DISCONNECT ALL ****************" << endl;

    localNode->disconnectAll();


    cout << endl << "**************** DEACTIVATION ****************" << endl;
    
    localNode->deactivate();

  }
  MPI_Barrier(MPI_COMM_WORLD);

  localNode->waitDeactivation();


  // deactivate POA
  _poa_man->deactivate(true,true);

  // shutdown ORB
  if(!CORBA::is_nil(_orbp))
    _orbp->shutdown(1); // do not wait for completion


  MPI_Finalize();

  // goodbye !  
  cerr << "return OK" << endl;
  return 0;
}

// EOF


Generated on Tue Jun 21 12:55:56 2005 for ColCOWS by  doxygen 1.4.1