HX_RESULT CBaseArchiver2::CreateDirObjects() { HX_RESULT hResult = HXR_OK; if (m_DirStatus == DIR_INITIALIZING) { // Figure out what directories we need to create CreateDirectoryList(); // Move on to the directory creating state m_DirStatus = DIR_CREATING; CreateDirObjects(); } else if (m_DirStatus == DIR_CREATING) { if (m_ulDirsCreated == m_ulDirsNeeded) { // We are done creating directories m_DirStatus = DIR_DONE; CreateFileObjects(); } else { // Create the next directory hResult = m_pFileCreator-> CreateArchiveDir(m_ppDirectoryList[m_ulDirsCreated]); if ((HXR_OK != hResult) && (m_DirStatus != DIR_DONE)) { ArchiveDirectoryReady(hResult); } // ... Flow continues in ::ArchiveDirectoryReady() } } else { // Invalid state HX_ASSERT(0); } return HXR_OK; }
int main(int argc, char** argv) { bookType* bt; int bookCnt = 0, i; char nullString[]="\0"; char inputFile[FILE_LEN] = {0}; char* inputFolder = nullString; char* timeFile = nullString; char* outputFile = nullString; double* simMat; int nprocs, myrank, error; double timeStart, timeMid, timeEnd, timeElapsed; double timeParaElapsed, timeSerialElapsed, timeParaEnd, timeParaStart; int initSecond; int ntag = 100; MPI_Status status; MPI_Init(&argc, &argv); struct timeval init_tv; gettimeofday(&init_tv, (struct timezone*)0); initSecond = init_tv.tv_sec; // record the start time wallTime( &timeStart, &initSecond); ////////////////////////// // Argument process commandLineFlagType flag[] = { {"inputFolder", _string, &inputFolder }, {"timeFile", _string, &timeFile }, {"outputFile", _string, &outputFile }, }; // set the number of processes int numFlags = sizeof ( flag ) / sizeof ( commandLineFlagType ); usageErrorType parseErrorCode = parseArgs ( argc, argv, numFlags, flag ) ; if ( parseErrorCode == argError || parseErrorCode == parseError ) { usage( argv[0] ); return ( 1 ); } // make sure the "inputFolder" contains a "/" in the end if (inputFolder[strlen(inputFolder) - 1] != '/') { char* tmpIF = (char*) malloc(strlen(inputFolder)+2); strcpy(tmpIF, inputFolder); strcat(tmpIF, "/"); inputFolder = tmpIF; } error = MPI_Comm_size(MPI_COMM_WORLD, &nprocs); error = MPI_Comm_rank(MPI_COMM_WORLD, &myrank); wallTime( &timeParaStart, &initSecond); // word load shared among nprocs nodes, all nodes work parallelly struct dirent *dir; char *filename; DIR* d; d = opendir(inputFolder); if (d) { while ((dir = readdir(d)) != NULL) { if (dir->d_type == DT_REG) { bookCnt ++; i = bookCnt % nprocs; if (i == myrank) { strcpy(inputFile, dir->d_name); bt = (bookType*) malloc(sizeof(bookType)); memset(bt, 0, sizeof(bookType)); bt->fileName = (char*) malloc(strlen(inputFolder) + strlen(inputFile) + 1); strcpy(bt->fileName, inputFolder); strcat(bt->fileName, inputFile); // 2. fill the structs with the desired content (P) CreateFileObjects(bt); // 3. sort the word list according to the word frequency (P) SortWordForBook(bt); // DebugPrintList(bt->wordList); RemoveStopWords(bt); char wordFile[FILE_LEN] = {0}; sprintf(wordFile, "words/%s.dat", inputFile); DebugPrintList(bt->wordList, wordFile); } // MPI_Send(inputFile, FILE_LEN, MPI_CHAR, i, ntag, MPI_COMM_WORLD); // printf("Node %d sent %s to %d\n", myrank, inputFile, i); } } } else { perror("Folder read error"); return ERROR_READ; } closedir(d); wallTime( &timeParaEnd, &initSecond); printf("rank=%d np=%d\n", myrank, nprocs); // tell node 0 that the work is done if (myrank != 0) { MPI_Send(&myrank, 1, MPI_INT, 0, ntag, MPI_COMM_WORLD); } if (myrank == 0) { int numSum = 0; int num = 0; // wait until all other nodes report for (i = 1; i < nprocs; i++) { MPI_Recv(&num, 1, MPI_INT, i, ntag, MPI_COMM_WORLD, &status); numSum += num; } printf("numSum=%d nprocs=%d\n", numSum, nprocs); if (numSum != (nprocs - 1)*(nprocs)/2) { printf("Some node didn't report\n"); return 1; } wallTime( &timeEnd, &initSecond); timeElapsed = timeEnd - timeStart; timeParaElapsed = timeParaEnd - timeParaStart; timeSerialElapsed = timeElapsed - timeParaElapsed; printf("SaveTime(%d): %1f %1f %1f %1f \n", nprocs, timeStart, timeParaStart, timeParaEnd, timeEnd); pSaveRunStat(timeStart, timeEnd, timeElapsed, timeSerialElapsed, timeFile); } // all nodes receive file name // MPI_Recv(inputFile, FILE_LEN, MPI_CHAR, 0, ntag, MPI_COMM_WORLD, &status); // printf("Node %d recv %s (%d)\n", myrank, inputFile, i); MPI_Finalize () ; return 0; }