Пример #1
0
void
Xfer::Process()
{
    ReadPendingMessages();

    // While there are complete messages, read and process them.
    while (bufferedInput.Size() > 0)
    {
        int     curOpcode;
        int     curLength;
        bufferedInput.ReadInt(&curOpcode);
        bufferedInput.ReadInt(&curLength);

        bool    bytesNeedToBeSkipped = true;
        if (curOpcode < subjectList.size())
        {
            if (subjectList[curOpcode])
            {
                debug5 << "Xfer::Process: Opcode=" << curOpcode
                    << ", len=" << curLength
                    << ", type="
                    << subjectList[curOpcode]->TypeName().c_str() << endl;

                // Read the object into its local copy.
                subjectList[curOpcode]->Read(bufferedInput);

                // Indicate that we want Xfer to ignore update messages if
                // it gets them while processing the Notify.
                SetUpdate(false);
                subjectList[curOpcode]->Notify();
                bytesNeedToBeSkipped = false;
            }
        }

        if (bytesNeedToBeSkipped)
        {
            debug1 << "Xfer::Process: Opcode " << curOpcode
                   << " is unknown! Skipping " << curLength << " bytes." << endl;
            unsigned char uchar;
            for (int i = 0; i < curLength; ++i)
                bufferedInput.Read(&uchar);
        }
    }
}
Пример #2
0
void
MPIXfer::Process()
{
    ReadPendingMessages();

    // While there are complete messages, read and process them.
    while(bufferedInput.Size() > 0)
    {
        int curOpcode;
        int curLength;
        bufferedInput.ReadInt(&curOpcode);
        bufferedInput.ReadInt(&curLength);

        if(subjectList[curOpcode])
        {
            if(PAR_UIProcess())
            {
                int i, msgLength = curLength + sizeof(int)*2;
#ifdef VISIT_BLUE_GENE_P
                // Make the buffer be 32-byte aligned
                unsigned char *buf = 0;
                posix_memalign((void **)&buf, 32, msgLength);
#else
                unsigned char *buf = (unsigned char*)malloc(msgLength * sizeof(unsigned char));
#endif
                unsigned char *tmp = buf;

                // Add the message's opcode and length into the buffer
                // that we'll broadcast to other processes so their
                // Xfer objects know what's up.
                unsigned char *cptr = (unsigned char *)&curOpcode;
                for(i = 0; i < sizeof(int); ++i)
                    *tmp++ = *cptr++;
                cptr = (unsigned char *)&curLength;
                for(i = 0; i < sizeof(int); ++i)
                    *tmp++ = *cptr++;

                // Transcribe the message into a buffer that we'll
                // communicate to other processes and also a new
                // temporary connection that we'll feed to the interested
                // object.
                BufferConnection newInput;
                unsigned char c;
                for(i = curLength; i > 0; --i)
                {
                    // Read a character from the input connection.
                    bufferedInput.ReadChar(&c);

                    *tmp++ = c;
                    newInput.WriteChar(c);
                }

                // Send the current opcode and message length. Note that we
                // use VisIt_MPI_Bcast for this call since we need to match
                // what's happening in PAR_EventLoop in the engine. This version
                // of bcast allows engines to reduce their activity instead of
                // using a spin-wait bcast.
                if (slaveProcessInstruction)
                    slaveProcessInstruction();
                VisIt_MPI_Bcast((void *)&msgLength, 1, MPI_INT,
                                0, VISIT_MPI_COMM);

                // Use regular bcast since the previous call to bcast will
                // already have gotten the attention of the other processors.
                MPI_Bcast((void *)buf, msgLength, MPI_UNSIGNED_CHAR,
                          0, VISIT_MPI_COMM);
                free(buf);

                // Read the object from the newInput into its local copy.
                subjectList[curOpcode]->Read(newInput);
            }
            else
            {
                // Non-UI Processes can read the object from *input.
                subjectList[curOpcode]->Read(bufferedInput);
            }

            // Indicate that we want Xfer to ignore update messages if
            // it gets them while processing the Notify.
            SetUpdate(false);
            subjectList[curOpcode]->Notify();
        }
    }
}