Exemplo n.º 1
0
void
MessageManager::sendMessage(KernelMessage* msg, int dest) {

    AggregationSendCriteria whatToDo;

    SerializedInstance* toSend = msg->serialize();

    whatToDo = getSendCriteriaInFixedPessimism(msg, toSend->getSize());

    switch (whatToDo) {
    case SEND_AND_WRITE:
        sendMessage();
        writeMessage(toSend, dest);
        break;
    case WRITE_AND_SEND:
    case SEND:
        writeMessage(toSend, dest);
        sendMessage();
        break;
    case WRITE:
        writeMessage(toSend, dest);
        break;
    case SEND_WRITE_SEND:
        sendMessage();
        writeMessage(toSend, dest);
        sendMessage();
        break;
    case DO_NOT_SEND:
        writeMessage(toSend, dest);
        break;
    default:
        cerr << "Invalid aggregation criterion received, writing the message anyway";
        cerr << " " << whatToDo << endl;
        writeMessage(toSend, dest);
        break;
    }

    incrementReceiveCriterion();
    checkToReceive();
    delete toSend;
}
Exemplo n.º 2
0
/// Used in optimistic fossil collection to save the state of the stream.
void
TimeWarpSimulationStream::saveCheckpoint(std::ofstream* outFile, unsigned int saveTime) {
    char del = '_';

    // If there is an input file, save the position of the file at the checkpoint time.
    if (inFileQueue != NULL) {
        outFile->write(&del, sizeof(del));

        std::multiset< InFileData >::iterator it = inFileQueue->begin();
        while (it != inFileQueue->end() && it->getTime().getApproximateIntTime() < saveTime) {
            it++;
        }

        // If there are no position saves after the checkpoint time, use the current
        // position in the file.
        streampos curPos;
        if (it != inFileQueue->end()) {
            curPos = it->getPosition();
        } else {
            curPos = inFileQueue->access()->tellg();
        }

        outFile->write((char*)(&curPos), sizeof(curPos));
    }

    // If there is an output file, save all data that is less than the checkpoint time
    // and save the current end of file position.
    if (outFileQueue != NULL) {
        const VTime* time;
        unsigned int timeSize;
        const char* timePtr;
        SerializedInstance* toWrite;
        const string* line;
        unsigned int lineSize;

        std::multiset< FileData >::iterator it = outFileQueue->begin();
        while (it != outFileQueue->end() && it->getTime().getApproximateIntTime() < saveTime) {
            time = &it->getTime();
            toWrite = new SerializedInstance(time->getDataType());
            time->serialize(toWrite);

            timePtr = &toWrite->getData()[0];
            timeSize = toWrite->getSize();

            line = it->getLine();
            lineSize = line->size();

            outFile->write((char*)(&timeSize), sizeof(timeSize));
            outFile->write(&del, sizeof(del));
            outFile->write(timePtr, timeSize);
            outFile->write(&del, sizeof(del));
            outFile->write((char*)(&lineSize), sizeof(lineSize));
            outFile->write(line->c_str(), lineSize);

            it++;
        }
        outFile->write(&del, sizeof(del));

        streampos end = outFileQueue->getEOFPosition();
        outFile->write((char*)(&end), sizeof(end));
    }
}