Exemplo n.º 1
0
int
MRNetBE::mHandshake(void)
{
    VCOMP_COUT("Starting lash-up handshake..." << endl);
    //
    MRN::PacketPtr packet;
    const bool recvShouldBlock = true;
    int tag = 0;
    // This will setup the protocol stream.
    auto status = mNet->recv(&tag, packet, &mProtoStream, recvShouldBlock);
    if (1 != status) {
        static const string f = "Stream::Recv";
        GLADIUS_CERR << utils::formatCallFailed(f, GLADIUS_WHERE) << endl;
        return GLADIUS_ERR_MRNET;
    }
    int ping = -1;
    status = packet->unpack("%d", &ping);
    if (0 != status) {
        static const string f = "PacketPtr::unpack";
        GLADIUS_CERR << utils::formatCallFailed(f, GLADIUS_WHERE) << endl;
        return GLADIUS_ERR_MRNET;
    }
    if (toolcommon::MRNetCoreTags::InitHandshake != tag) {
        static const string errs = "Received Invalid Tag From Tool Front-End";
        GLADIUS_CERR << errs << endl;
        return GLADIUS_ERR;
    }
    if (ping != GladiusMRNetProtoFilterMagic) {
        static const string errs = "Received Invalid Data From Tool Front-End";
        GLADIUS_CERR << errs << endl;
        return GLADIUS_ERR;
    }
    int pong = -ping;
    status = mProtoStream->send(tag, "%d", pong);
    if (-1 == status) {
        static const string f = "Stream::Send";
        GLADIUS_CERR << utils::formatCallFailed(f, GLADIUS_WHERE) << endl;
        return GLADIUS_ERR_MRNET;
    }
    status = mProtoStream->flush();
    if (-1 == status) {
        static const string f = "Stream::Flush";
        GLADIUS_CERR << utils::formatCallFailed(f, GLADIUS_WHERE) << endl;
        return GLADIUS_ERR_MRNET;
    }
    //
    return GLADIUS_SUCCESS;
}
Exemplo n.º 2
0
/**
 * Receives valid plugin name and path from FE.
 */
int
MRNetBE::mPluginInfoRecv(
    string &validPluginName,
    string &pathToValidPlugin
) {
    VCOMP_COUT("Receiving plugin info from front-end..." << endl);
    //
    MRN::PacketPtr packet;
    MRN::Stream *stream = nullptr;
    const bool recvShouldBlock = true;
    int tag = 0;
    auto status = mNet->recv(&tag, packet, &stream, recvShouldBlock);
    if (1 != status) {
        static const string f = "Network::Recv";
        GLADIUS_CERR << utils::formatCallFailed(f, GLADIUS_WHERE) << endl;
        return GLADIUS_ERR_MRNET;
    }
    // Make sure that we are dealing with a tag that we are expecting...
    if (toolcommon::MRNetCoreTags::PluginNameInfo != tag) {
        static const string errs = "Received Invalid Tag From Tool Front-End";
        GLADIUS_CERR << errs << endl;
        return GLADIUS_ERR;
    }
    char *pluginName = nullptr;
    char *pluginPath = nullptr;
    status = packet->unpack("%s %s", &pluginName, &pluginPath);
    if (0 != status) {
        static const string f = "PacketPtr::unpack";
        GLADIUS_CERR << utils::formatCallFailed(f, GLADIUS_WHERE) << endl;
        return GLADIUS_ERR_MRNET;
    }
    // Set returns.
    validPluginName = string(pluginName);
    pathToValidPlugin = string(pluginPath);
    //
    free(pluginName);
    free(pluginPath);
    //
    VCOMP_COUT("Front-End Plugin Info:" << endl);
    VCOMP_COUT("*Name: " << validPluginName << endl);
    VCOMP_COUT("*Path: " << pathToValidPlugin << endl);
    //
    return GLADIUS_SUCCESS;
}
Exemplo n.º 3
0
bool StopTrace::handleResultPackage(MRN::PacketPtr packet, MRN::Stream* stream) {
  map<MRN::Stream*, StopTrace*>::iterator it = waitingForResults.find(stream);

  if (it == waitingForResults.end()) {
    return DYSECTWARN(false, "Unexpected packet on result stream!");
  }

  StopTrace* action = it->second;
  char* data;
  int dataSize;
  if (packet->unpack("%ac", &data, &dataSize) != 0) {
    return DYSECTFATAL(false, "Unexpected global result package content!");
  }

  action->trace->processGlobalResult(data, dataSize);

  waitingForResults.erase(it);
  TraceAPI::processedGlobalRes(action->trace);

  free(data);

  return true;
}
Exemplo n.º 4
0
int
main( int argc, char* argv[] )
{
    int ret = 0;
    MRN::Network* net = NULL;

    try
    {
        int myNid = FindMyNid();

        // connect to the MRNet
        net = MRN::Network::CreateNetworkBE( argc, argv );
        assert( net != NULL );
        int myRank = net->get_LocalRank();
        //fprintf( stderr, "BE[%d] done creating MRNet net BE\n", myRank );
        //fflush( stderr );

        // receive the ALPS apid for the application to be monitored
        MRN::Stream* strm = NULL;
        MRN::PacketPtr pkt;
        int tag = 0;
        int rret = net->recv( &tag, pkt, &strm );
        //fprintf( stderr, "BE[%d] received ALPS apid msg\n", myRank );
        //fflush( stderr );
        if( rret == -1 )
        {
            throw XTMException( "BE[%d] failed to receive control message from FE" );
        }
        if( tag != XTM_APID )
        {
            std::ostringstream mstr;
            mstr << "BE[" << myRank << "] expected XTM_APID message, got tag=" << tag << std::ends;
            throw XTMException( mstr.str().c_str() );
        }
        uint64_t apid = (uint64_t)-1;
        pkt->unpack( "%uld", &apid );
        //fprintf( stderr, "BE[%d] received apid=%lu\n", myRank, apid );
        //fflush( stderr );

#ifdef TOOL_CODE_GOES_HERE
        // ---- BEGIN TOOL-SPECIFIC CODE REGION ----
        // 1. attach to local application process(es)
        // 2. indicate to tool FE that we are attached
        // 3. handle application process events until it finishes
        // ---- END TOOL-SPECIFIC CODE REGION ----
#else
        // fake to the FE as if we have connected to the application and
        // waited for it to finish
        tag = XTM_APPOK;
        int dummyVal = 1;
        int sret = strm->send( tag, "%d", dummyVal );
        if( sret == -1 )
        {
            fprintf( stderr, "BE[%d] send of app OK msg failed\n", myRank );
            fflush( stderr );
        }
        int fret = strm->flush();
        if( fret == -1 )
        {
            fprintf( stderr, "BE[%d] flush of app OK msg failed\n", myRank );
            fflush( stderr );
        }
        if( (sret == -1) || (fret == -1) )
        {
            std::ostringstream mstr;
            mstr << "BE[" << myRank << "] failed to send app OK msg to FE" << std::ends;
            throw XTMException( mstr.str().c_str() ); 
        }
        //fprintf( stderr, "BE[%d] sent app OK message to FE\n", myRank );
        //fflush( stderr );

        sleep( 5 );
#endif

        //fprintf( stderr, "BE[%d] sending app done message to FE\n", myRank );
        //fflush( stderr );
        tag = XTM_APPDONE;
        int appExitCode = 1;
        sret = strm->send( tag, "%d", appExitCode );
        if( sret == -1 )
        {
            fprintf( stderr, "BE[%d] send of app done msg failed\n", myRank );
            fflush( stderr );
        }
        fret = strm->flush();
        if( fret == -1 )
        {
            fprintf( stderr, "BE[%d] flush of app done msg failed\n", myRank );
            fflush( stderr );
        }
        if( (sret == -1) || (fret == -1) )
        {
            std::ostringstream mstr;
            mstr << "BE[" << myRank << "] failed to send app exit code to FE" << std::ends;
            throw XTMException( mstr.str().c_str() ); 
        }
        //fprintf( stderr, "BE[%d] sent app done message to FE\n", myRank );
        //fflush( stderr );
        
        // wait for termination message from FE
        rret = net->recv( &tag, pkt, &strm );
        if( rret == -1 )
        {
            std::ostringstream mstr;
            mstr << "BE[" << myRank << "] failed to receive control message from FE" << std::ends;
            throw XTMException( mstr.str().c_str() ); 
        }
        if( tag != XTM_EXIT )
        {
            std::ostringstream mstr;
            mstr << "BE[" << myRank << "] expected XTM_EXIT message, got tag=" << tag << std::ends;
            throw XTMException( mstr.str().c_str() );
        }

        // clean up
        //fprintf( stderr, "BE[%d] exiting\n", myRank );
        //fflush( stderr );

        net->waitfor_ShutDown();
        delete net;
    }
    catch( std::exception& e )
    {
        fprintf( stderr, "!!BE EXCEPTION!! %s\n", e.what() );
        ret = 1;
    }

    return ret;
}
Exemplo n.º 5
0
DysectErrorCode FE::requestBackendSetup(const char *libPath) {

  struct timeval start, end;
  gettimeofday(&start, NULL);

  MRN::Communicator* broadcastCommunicator = network->get_BroadcastCommunicator();

  controlStream = network->new_Stream(broadcastCommunicator, MRN::TFILTER_SUM, MRN::SFILTER_WAITFORALL);
  if(!controlStream) {
    return Error;
  }

  // Check for pending acks
  int ret = statFE->receiveAck(true);
  if (ret != STAT_OK) {
    return Error;
  }

  //
  // Send library path to all backends
  //
  if (controlStream->send(PROT_LOAD_SESSION_LIB, "%s", libPath) == -1) {
    return Error;
  }

  if (controlStream->flush() == -1) {
    return Error;
  }

  //
  // Block and wait for all backends to acknowledge
  //
  int tag;
  MRN::PacketPtr packet;
  
  Err::verbose(true, "Block and wait for all backends to confirm library load...");
  if(controlStream->recv(&tag, packet, true) == -1) {
    return Error;
  }

  int numIllBackends = 0;
  //
  // Unpack number of ill backends
  //
  if(packet->unpack("%d", &numIllBackends) == -1) {
    return Error;
  }

  if(numIllBackends != 0) {
    fprintf(stderr, "Frontend: %d backends reported error while loading session library '%s'\n", numIllBackends, libPath);
    return Error;
  }

  //
  // Broadcast request for notification upon finishing
  // stream binding.
  // Do not wait for response until all init packets have been broadcasted.
  //
  Err::verbose(true, "Broadcast request for notification upon finishing stream binding");
  if(controlStream->send(DysectGlobalReadyTag, "") == -1) {
    return Error;
  }

  if(controlStream->flush() == -1) {
    return Error;
  }

  //
  // Broadcast init packets on all created streams
  //
  Err::verbose(true, "Broadcast init packets on all created streams");
  if(Frontend::broadcastStreamInits() != OK) {
    return Error;
  }

  Err::verbose(true, "Waiting for backends to finish stream binding...");
  if(controlStream->recv(&tag, packet, true) == -1) {
    return Error;
  }

  //
  // Unpack number of ill backends
  //
  if (packet->unpack("%d", &numIllBackends) == -1) {
    return Error;
  }

  if (numIllBackends != 0) {
    fprintf(stderr, "Frontend: %d backends reported error while bindings streams\n", numIllBackends);
    return Error;
  }
  
  //
  // Kick off session
  //
  Err::verbose(true, "Kick off session");
  if (controlStream->send(DysectGlobalStartTag, "") == -1) {
    return Error;
  }

  if (controlStream->flush() == -1) {
    return Error;
  }

  gettimeofday(&end, NULL);

  // Bring both times into milliseconds

  long startms = ((start.tv_sec) * 1000) + ((start.tv_usec) / 1000);
  long endms = ((end.tv_sec) * 1000) + ((end.tv_usec) / 1000);

  long elapsedms = endms - startms;
  
  Err::info(true, "DysectAPI setup took %ld ms", elapsedms);
  
  return OK;
}