void ExitProcess (ProcessData * pData, ScoringData * sData, WavesData * wData) { freeProcessMemory (&pData, &sData, &wData); mprintf(1, "before finalize \n", 1); MPI_Finalize (); mprintf(1, "after finalize \n", 1); }
static void deallocProcess(int pid){ /* Retorno los semaforos al sistema */ semRetID(proc[pid%MAX_PROCESS].semChild); semRetID(proc[pid%MAX_PROCESS].semFather); /* Libero la memoria */ freeProcessMemory(pid); /* Libero el slot */ proc[pid%MAX_PROCESS].status = FREE; }
int main (int argc, char * argv[]) { MOATypeDimn seqNum; MOATypeShape * seqLen = NULL; char * * sequences = NULL, * * seqName = NULL, msg[MID_MESSAGE_SIZE]; long partitionSize; long ID1; int stype, MPI_return; /*char ufilename[SHORT_MESSAGE_SIZE];*/ int ret; ProcessData * pData; ScoringData * sData; WavesData * wData; TBFlag = 1; prevNow = NULL; prevNow = mmalloc ((MOATypeInd) sizeof *prevNow); currNow = NULL; //currNow = mmalloc ((MOATypeInd) sizeof *currNow); currNow = getTime(); if (currNow == NULL) { printf ("Could not read current time. Exiting.\n"); return -1; } ID1 = getpid(); printf("[%d]>PID = %ld Started at time (%d, %d, %d, %d)\n", myProcid, ID1, currNow->tm_yday, currNow->tm_hour, currNow->tm_min, currNow->tm_sec); /* 1. Process Arguments*/ processArguments(argc, argv, &seqNum, &sequences, &seqName, &seqLen, &stype, &partitionSize); /*strcpy (ufilename, outputfilename);*/ strcpy (outPrefix, "b"); /*sprintf (outputfilename, "mmtb%s", ufilename);*/ init_output(); sprintf (msg, "Program Arguments: debuglevel = %d maxAlignmentsNumber = %d Epsilons= %ld Alignment Type = %d stype %d outputfilename = %s partitionSize = %ld\n", pdebug, maxAlignmentsNumber, Epsilons, AlignmentType, stype, outputfilename, partitionSize); mprintf (1, msg, 1); /*2. Do the Master Tasks: Synchronize with Slaves to trace back*/ /* one path for now*/ ret = initProcessMemory(&pData, &sData, &wData, seqNum, seqLen, sequences, seqName, stype, partitionSize); if (ret != 0) { mprintf (1, " Could not initialize process memory\n", 1); freeProcessMemory (&pData, &sData, &wData); return -1; } /*3. Load Tensor Partitions Computed*/ ret = restoreCheckPoint (pData, wData); if (ret != 0) { printf (" Could not read Slave data from checkpoint file\n"); freeProcessMemory (&pData, &sData, &wData); return -1; } if (pData->computedPartitions <= 0) { mprintf (1, " No Partitions read in this process\n", 1); /*ExitProcess (pData);*/ /*return -1;*/ } else { sprintf (msg, "read Slave data from checkpoint file partitions %ld last score in last partition is %ld sqm %ld sqlen0 %ld %ld %ld\n", pData->partitionsCount, pData->msaAlgn->elements[pData->msaAlgn->elements_ub - 1].val, pData->seqNum, pData->seqLen[0], pData->seqLen[1], pData->seqLen[2]); mprintf(3, msg, 1); } tbMaster(pData, wData); /* Getting Process Resources Usage ===================== */ struct rusage usageRec; double utime, stime; ret = getrusage(RUSAGE_SELF, &usageRec); if (ret == 0) { //printf ("[%d]Resources Usage: UTime %ld, STime %ld, Mem %ld, Virt %ld\n", myProcid, usageRec.ru_utime.tv_sec, usageRec.ru_stime.tv_sec, usageRec.ru_maxrss, usageRec.ru_ixrss); utime = (double) usageRec.ru_utime.tv_sec + 1.e-6 * (double) usageRec.ru_utime.tv_usec; stime = (double) usageRec.ru_stime.tv_sec + 1.e-6 * (double) usageRec.ru_stime.tv_usec; //printf ("[%d]Resources Usage: UTime %f, STime %f\n", myProcid, utime, stime); } else printf ("Failed to retrieve Process Resources Usage, errno %d\n", errno); //struct mallinfo info; //info = mallinfo(); //printf("[%d] STime\tUTime\theap\tMemory\t\n",myProcid); //printf("[%d] %f\t%f\t%d\t%d\n", myProcid, stime, utime, info.arena, info.usmblks + info.uordblks); printf("STime\tUTime\n"); printf("%f\t%f\n", stime, utime); currNow = getTime(); printf("Finalized at time (%d, %d, %d, %d)\n", currNow->tm_yday, currNow->tm_hour, currNow->tm_min, currNow->tm_sec); freeProcessMemory (&pData, &sData, &wData); return 0; }
/* ============================================================================ function MainProcess: seqNum: Number of sequences in string sequences (ex. 3) sequences: holds the sequences. (ex. [GTGCAACGTACT]) seqLen: Array of the length of each sequence in sequences. (ex. 5,4,3) ======= which means that we have three sequences GTGCA, ACGT, and ACT. stype: Scoring type (1: linear score, 2: PAM250 if protein, 3: BLOSUM if protein) partitionSize: Partion Size ============================================================================== */ void MainProcess (MOATypeDimn seqNum, char * * sequences, char * * seqName, MOATypeShape * seqLen, int stype, long partitionSize) { ProcessData * pData = NULL; ScoringData * sData = NULL; WavesData * wData = NULL; MOATypeDimn k; MOATypeInd i; int ret, startflag; struct rusage usageRec; double utime, stime; MPI_Status status; double t_start, t_finish; char command[2000]; #ifndef NDEBUG char msg[SHORT_MESSAGE_SIZE]; int dbglevel = 0; MOATypeInd j; #endif t_start = MPI_Wtime(); /* print the input arguments ============================================*/ //PrintSequencies (0, seqNum, sequences, seqLen); #ifndef NDEBUG sprintf(msg, ">>>>MainProcess: Scoring Type: %d\n>>>>Partition Size: %ld\n", stype, partitionSize); mprintf(dbglevel, msg, 1); #endif /* Initialize Process Memory pData (function located in partitioning.c*/ ret = initProcessMemory(&pData, &sData, &wData, seqNum, seqLen, sequences, seqName, stype, partitionSize); if (ret != 0) { mprintf (0, ">>>>MainProcess: Error Initializing Process Data, Exiting\n", 1); fflush (stdout); return; } /* if restore previouse run read check point data here, do not calculate waves */ pData->OCout = NULL; pData->OCin = NULL; if (Mode != Distributed) { /* Construct MOA record */ pData->msaAlgn = NULL; createMOAStruct(&pData->msaAlgn); if (createMOA(seqLen, seqNum, pData->msaAlgn, 0, 0) < 0) return; wData->wavesTotal = 1; wData->AllpartsInWave = mmalloc((MOATypeInd) sizeof *wData->AllpartsInWave); wData->AllpartsInWave[0] = 1; pData->waveNo = 0; pData->partNo = 0; pData->partitionsCount = 1; /*pData->OCout = mmalloc((MOATypeInd) sizeof *(pData->OCout)); if (pData->OCout == NULL) { mprintf(1, "Couldn't create memory for OCout while adding an OC. Exiting.\n", 3); printf("Couldn't create memory for OCout while . Exiting.\n",); return; } pData->OCout[0].wavesOC = 0; pData->OCout[0].WOCO = NULL; */ #ifndef NDEBUG sprintf (msg, "[%d]>ScoreCompThread[%ld]: Will call ComputePartitionScores\n", myProcid, pData->computedPartitions); mprintf (dbglevel, msg, 1); #endif /* Compute Scored for Current Partition*/ if (Algorithm == DP) DPComputeScores (pData, sData, wData); else if (Algorithm == SP) DPComputeScores (pData, sData, wData); /* Print elements ======================================================= */ //printMOA_scr(pData->msaAlgn, 0); /* Print Indexes ========================================================*/ //printMOA_scr(pData->msaAlgn, 1); pData->computedPartitions ++; checkPoint (pData, sData); } else { if (RestoreFlag == 1) { /* restore data */ restoreCheckPoint (pData, wData); pData->globalWaveNo = pData->waveNo; } else { pData->partNo = 0; pData->waveNo = 0; if (myProcid == 0) { printf ("[%d] Calculating waves and partitions .... ", myProcid); calcWaves (pData, wData); currNow = getTime(); printf("[%d] Done Calculating waves and partitions time (%d, %d, %d, %d)\n", myProcid, currNow->tm_yday, currNow->tm_hour, currNow->tm_min, currNow->tm_sec); fflush(stdout); if( checkPointWavesCalculations (pData, wData) == 0) { startflag = 1; for (i=1; i<ClusterSize; i++) MPI_Send(&startflag, 1, MPI_INT, i, 0, MOAMSA_COMM_WORLD); } else { printf ("[%d]Couldn't write Waves calculations, Exiting\n", myProcid); return; } } else { //printf ("[%d] waiting for start flag\n", myProcid); MPI_Recv(&startflag, 1, MPI_INT, 0, 0, MOAMSA_COMM_WORLD, &status); //printf ("[%d] received start flag = %d\n", myProcid, startflag); printf ("[%d] Reading waves and partitions .... ", myProcid); if (restoreWavesCalculations(pData, wData) != 0) { printf ("[%d]Couldn't read Waves calculations, Exiting\n", myProcid); return; } printf ("done.\n"); fflush(stdout); } } #ifndef NDEBUG sprintf(msg, "[%d]>MainProcess: Current Wave: %ld - Current Partition: %ld - Total Partitions in Process: %ld\n", myProcid, pData->waveNo, pData->partNo, pData->partitionsCount); mprintf(dbglevel, msg, 1); #endif ScoreCompThread (pData, sData, wData); } if (myProcid == 0) { t_finish = MPI_Wtime(); /* Getting Process Resources Usage ===================== */ ret = getrusage(RUSAGE_SELF, &usageRec); if (ret == 0) { //printf ("[%d]Resources Usage: UTime %ld, STime %ld, Mem %ld, Virt %ld\n", myProcid, usageRec.ru_utime.tv_sec, usageRec.ru_stime.tv_sec, usageRec.ru_maxrss, usageRec.ru_ixrss); utime = (double) usageRec.ru_utime.tv_sec + 1.e-6 * (double) usageRec.ru_utime.tv_usec; stime = (double) usageRec.ru_stime.tv_sec + 1.e-6 * (double) usageRec.ru_stime.tv_usec; //printf ("[%d]Resources Usage: UTime %f, STime %f\n", myProcid, utime, stime); } else printf ("[%d]Failed to retrieve Process Resources Usage, errno %d\n", myProcid, errno); //struct mallinfo info; //info = mallinfo(); //printf("[%d] STime\tUTime\theap\tMemory\t\n",myProcid); //printf("[%d] %f\t%f\t%d\t%d\n", myProcid, stime, utime, info.arena, info.usmblks + info.uordblks); printf("STime\tUTime\n"); printf("%f\t%f\n", stime, utime); printf ("Elsp-time: %f\n", t_finish - t_start); fflush(stdout); sprintf (command, "prstat 1 1 > /export/home/mhelal1/thesis/exp/run/prstatus/prst_%s", outputfilename); i = system (command); } /* Free allocated memory and exit routine ===================== */ freeProcessMemory (&pData, &sData, &wData); }