int main(int argc, char *argv[]) { int nNumInputs = 0; IRLOG_IOStruct *pInput = NULL; int rec_type; int bAllRecords = 1; int bExcludeType = 0; if (argc < 2) { printf("%s irlogfile [REC_TYPE]\n", argv[0]); return -1; } pInput = IRLOG_CreateInputStruct(argv[1]); if (pInput == NULL) { printf("Error setting up file '%s'\n", argv[1]); return -1; } if (argc > 2) { if (strcmp(argv[2], "RLOG_EVENT") == 0) { bAllRecords = 0; rec_type = RLOG_EVENT_TYPE; } if (strcmp(argv[2], "RLOG_ARROW") == 0) { bAllRecords = 0; rec_type = RLOG_ARROW_TYPE; } if (strcmp(argv[2], "RLOG_STATE") == 0) { bAllRecords = 0; rec_type = RLOG_STATE_TYPE; } if (strcmp(argv[2], "RLOG_COMM") == 0) { bAllRecords = 0; rec_type = RLOG_COMM_TYPE; } if (strcmp(argv[2], "RLOG_ENDLOG") == 0) { bAllRecords = 0; rec_type = RLOG_ENDLOG_TYPE; } } if (argc > 3) { if (strcmp(&argv[3][1], "exclude") == 0) bExcludeType = 1; } while (1) { if (bExcludeType) { if (pInput->header.type != rec_type) PrintRecord(pInput); } else { if ((bAllRecords) || (pInput->header.type == rec_type)) PrintRecord(pInput); } if (IRLOG_GetNextRecord(pInput)) { IRLOG_CloseInputStruct(&pInput); break; } } return 0; }
int main(int argc, char *argv[]) { RLOG_FILE_HEADER header; RLOG_State_list *pState; int nNumInputs; IRLOG_IOStruct *pInput; IRLOG_IOStruct **ppInput; int nMaxRank = 0; int nMinRank = MAX_RANK; int nNumStates = 0; int type, length; int nMaxLevel = 0; int nNumLevels = 0; int nTotalNumEvents = 0; int nNumEvents; RecursionStruct *pLevel; FILE *fout; int i, j; int nRank; if (argc < 3) { MPL_error_printf("Usage:\nirlog2rlog out.rlog in0.irlog in1.irlog ...\nirlog2rlog out.rlog n\n"); return 0; } if (argc == 3 && IsNumber(argv[2])) { GenerateNewArgv(&argc, &argv, atoi(argv[2])); } nNumInputs = argc - 2; /* open the output rlog file */ fout = fopen(argv[1], "wb"); if (fout == NULL) { MPL_error_printf("unable to open output file '%s'\n", argv[1]); return -1; } /* read the arrows from all the files in order */ ppInput = (IRLOG_IOStruct**)MPL_malloc(nNumInputs * sizeof(IRLOG_IOStruct*)); for (i=0; i<nNumInputs; i++) { ppInput[i] = IRLOG_CreateInputStruct(argv[i+2]); if (ppInput[i] == NULL) { MPL_error_printf("Unable to create an input structure for '%s', skipping\n", argv[i+2]); } } for (i=0; i<nNumInputs; i++) { if (ppInput[i] == NULL) { for (j=i; j<nNumInputs-1; j++) ppInput[j] = ppInput[j+1]; nNumInputs--; i--; } } MPL_msg_printf("reading the arrows from all the input files.\n");fflush(stdout); ReadAllArrows(ppInput, nNumInputs); nNumInputs = argc - 2; /* read, parse and save all the data from the irlog files */ for (i=0; i<nNumInputs; i++) { pInput = IRLOG_CreateInputStruct(argv[i+2]); if (pInput == NULL) { MPL_error_printf("Unable to create an input structure for '%s', skipping\n", argv[i+2]); } else { MPL_msg_printf("reading irlog file: %s\n", argv[i+2]);fflush(stdout); for(;;) { switch (pInput->header.type) { case RLOG_STATE_TYPE: SaveState(&pInput->record.state); break; case RLOG_COMM_TYPE: nMaxRank = (pInput->record.comm.rank > nMaxRank) ? pInput->record.comm.rank : nMaxRank; nMinRank = (pInput->record.comm.rank < nMinRank) ? pInput->record.comm.rank : nMinRank; break; case RLOG_IARROW_TYPE: /* SaveArrow(&pInput->record.iarrow); */ break; case RLOG_EVENT_TYPE: SaveEvent(&pInput->record.event); break; default: MPL_error_printf("Unknown irlog record type: %d\n", pInput->header.type); break; } if (IRLOG_GetNextRecord(pInput)) { IRLOG_CloseInputStruct(&pInput); break; } } } } /* set the fields in the header */ header.nMinRank = FindMinRank(g_pLevel); header.nMaxRank = FindMaxRank(g_pLevel); if (nMinRank != header.nMinRank) MPL_error_printf("minimum event rank %d does not equal the minimum comm record rank %d\n", header.nMinRank, nMinRank); if (nMaxRank != header.nMaxRank) MPL_error_printf("maximum event rank %d does not equal the maximum comm record rank %d\n", header.nMaxRank, nMaxRank); /* write header */ MPL_msg_printf("writing header.\n");fflush(stdout); type = RLOG_HEADER_SECTION; length = sizeof(RLOG_FILE_HEADER); /* fwrite(&type, sizeof(int), 1, fout); */ WriteFileData(&type, sizeof(int), fout); /* fwrite(&length, sizeof(int), 1, fout);*/ WriteFileData(&length, sizeof(int), fout); /* fwrite(&header, sizeof(RLOG_FILE_HEADER), 1, fout); */ WriteFileData(&header, sizeof(RLOG_FILE_HEADER), fout); /* write states */ if (g_pList) { MPL_msg_printf("writing states.\n");fflush(stdout); } pState = g_pList; while (pState) { nNumStates++; pState = pState->next; } type = RLOG_STATE_SECTION; length = nNumStates * sizeof(RLOG_STATE); /* fwrite(&type, sizeof(int), 1, fout); */ WriteFileData(&type, sizeof(int), fout); /* fwrite(&length, sizeof(int), 1, fout); */ WriteFileData(&length, sizeof(int), fout); pState = g_pList; while (pState) { /* fwrite(pState, sizeof(RLOG_STATE), 1, fout); */ WriteFileData(pState, sizeof(RLOG_STATE), fout); pState = pState->next; } /* write arrows */ if (g_fArrow) { MPL_msg_printf("writing arrows.\n");fflush(stdout); type = RLOG_ARROW_SECTION; length = ftell(g_fArrow); /* fwrite(&type, sizeof(int), 1, fout); */ WriteFileData(&type, sizeof(int), fout); /* fwrite(&length, sizeof(int), 1, fout); */ WriteFileData(&length, sizeof(int), fout); AppendFile(fout, g_fArrow); } /* write events */ while (g_pLevel) { pLevel = FindMinLevel(g_pLevel); nNumLevels = FindMaxRecursion(g_pLevel, pLevel->rank); nRank = pLevel->rank; /* count the events for this rank */ nNumEvents = 0; for (i=0; i<nNumLevels; i++) { pLevel = GetLevel(pLevel->rank, i); nNumEvents += pLevel->num_events; } /* write an event section for this rank */ type = RLOG_EVENT_SECTION; length = sizeof(int) + sizeof(int) + (nNumLevels * sizeof(int)) + (nNumEvents * sizeof(RLOG_EVENT)); /* fwrite(&type, sizeof(int), 1, fout); */ WriteFileData(&type, sizeof(int), fout); /* fwrite(&length, sizeof(int), 1, fout); */ WriteFileData(&length, sizeof(int), fout); /* fwrite(&nRank, sizeof(int), 1, fout); */ WriteFileData(&nRank, sizeof(int), fout); /* fwrite(&nNumLevels, sizeof(int), 1, fout); */ WriteFileData(&nNumLevels, sizeof(int), fout); for (i=0; i<nNumLevels; i++) { pLevel = GetLevel(nRank, i); /* fwrite(&pLevel->num_events, sizeof(int), 1, fout); */ WriteFileData(&pLevel->num_events, sizeof(int), fout); } for (i=0; i<nNumLevels; i++) { MPL_msg_printf("writing event level %d:%d\n", nRank, i);fflush(stdout); pLevel = GetLevel(nRank, i); AppendFile(fout, pLevel->fout); } /* remove this rank from the list of levels */ RemoveLevel(nRank); } /* free resources */ while (g_pList) { pState = g_pList; g_pList = g_pList->next; MPL_free(pState); } if (g_fArrow) { fclose(g_fArrow); unlink(g_pszArrowFilename); } if (s_bFreeArgv) MPL_free(argv); return 0; }