예제 #1
0
void DFO_TableTranspose::SetDesc(SC_StringArray& descStr, 
                                    const char*     desc,
                                    int             nreq)
{
    int ndesc = descStr.Size();
    if (ndesc < nreq)
    {
        for (int i = ndesc; i < nreq; i++)
        {
            char tempStr[80];
            CopyString(tempStr, desc, 80);
            ConcatInt(i, tempStr, 3, 80);
            descStr.SetString(tempStr, i);
        }
        descStr.SetSize(nreq);
    }
}
예제 #2
0
    static void MPIMasterRun(const char* MPIappID, int maxMPIRank)
    {
        // all msgs for master ...
        NodeFile::mpiDebugRun = true;

        SC_StringArray machineNames;
        machineNames.SetStringLen(maxNameLen);
        machineNames.Alloc(maxMPIRank);
        machineNames.SetString(processorName, 0);

        // get slave processor name
        MPI_Status status;
        for (int i = 1; i < maxMPIRank; i++)
            {
                CheckMPI(MPI_Recv(processorName, maxNameLen, MPI_CHAR, i, mpiTag_ProcName, MPI_COMM_WORLD, &status), "Master get slave names");

                int currRank = status.MPI_SOURCE;
                if (currRank != i)
                    GenAppInternalError("Unexpected slave rank on slave processor name");

                machineNames.SetString(processorName, i);
            }

        time_t stTime;
        bool stTimeOK = false;
        char timeLab[80];
        const char* timeFormat = "%x %X";
        if (time(&stTime) != -1)
            {
#ifdef MSCVS2005
                tm tmOut;
                localtime_s(&tmOut, &stTime);
                strftime(timeLab, 80, timeFormat, &tmOut);
#else
                strftime(timeLab, 80, timeFormat, localtime(&stTime));
#endif
                GenAppInfoMsg("Master start time", timeLab);
                stTimeOK = true;
            }

        bool isOptRun = MPIOptimizationRun();
        int nRuns;
        if (isOptRun)
            {
                GenAppInfoMsg("MPI Run","Optimization only");
            }
        else
            {
                nRuns = MPIGetNCases();
                char nrunstr[10];
                IntToString(nRuns, nrunstr, 10);
                GenAppInfoMsg("Number of runs", nrunstr);
            }
        int nSlaves = maxMPIRank - 1;
        if (nRuns < nSlaves)
            nSlaves = nRuns;

        MPIMasterInit(nSlaves);

        if (isOptRun)
            {
                MPIRunOptimizationMaster(nSlaves);
            }
        else
            {

                MPIMasterSampling(nSlaves, maxMPIRank);

            }

        GenAppInfoMsg(MPIappID, "master run complete");

        MPIMasterCleanup(nSlaves);

        if (!isOptRun)
            {
                using namespace std;
                cout << endl << "Slave Summary" << endl;
                SC_IntArray processorCount(maxMPIRank, 0);
                for (int i = 0; i < nSlaves; i++)
                    {
                        cout << "Slave " << i + 1 << " processed " << indexCount[i] << " runs" << endl;
                        processorCount[machineNames.SearchForKey(machineNames[i + 1])] += indexCount[i];
                    }

                cout << endl << "Machine Summary" << endl;
                for (int i = 0; i < maxMPIRank; i++)
                    if (processorCount[i] > 0)
                        cout << "Machine " << machineNames[i] << " processed " << processorCount[i] << " runs" << endl;
                cout << endl;
            }

        GenAppInfoMsg(MPIappID, "all cases completed OK");

        time_t endTime;
        if (stTimeOK && (time(&endTime) != -1))
            {
                // write start time again
                GenAppInfoMsg("Master start time", timeLab);

                // and end time
#ifdef MSCVS2005
                tm tmOut;
                localtime_s(&tmOut, &endTime);
                strftime(timeLab, 80, timeFormat, &tmOut);
#else
                strftime(timeLab, 80, timeFormat, localtime(&endTime));
#endif
                GenAppInfoMsg("Master end time", timeLab);

                double deltaMin = difftime(endTime, stTime); // / 60.0;
                SC_DecFormat minConv(2);
                minConv.RealToString(deltaMin, timeLab, 80);

                GenAppInfoMsg("Elapsed seconds", timeLab);
            }
    }