void free_MCMC(MCMC_info *MCMC) { int i_P, i_DS; int i_array; MCMC_DS_info *current_DS; MCMC_DS_info *next_DS; SID_log("Freeing MCMC structure...", SID_LOG_OPEN); // Parameter arrays for(i_P = 0; i_P < MCMC->n_P; i_P++) SID_free(SID_FARG MCMC->P_names[i_P]); SID_free(SID_FARG MCMC->P_names); SID_free(SID_FARG MCMC->P_init); SID_free(SID_FARG MCMC->P_new); SID_free(SID_FARG MCMC->P_last); SID_free(SID_FARG MCMC->P_chain); SID_free(SID_FARG MCMC->P_limit_min); SID_free(SID_FARG MCMC->P_limit_max); if(MCMC->n_arrays > 0) { for(i_array = 0; i_array < MCMC->n_arrays; i_array++) { SID_free(SID_FARG MCMC->array[i_array]); SID_free(SID_FARG MCMC->array_name[i_array]); } SID_free(SID_FARG MCMC->array); SID_free(SID_FARG MCMC->array_name); } // Covariance and displacement vector free_MCMC_covariance(MCMC); // Random number generator if(MCMC->RNG != NULL) free_RNG(MCMC->RNG); // Dataset arrays free_MCMC_arrays(MCMC); free_MCMC_DS(MCMC); // Communicators SID_Comm_free(&(MCMC->comm)); SID_log("Done.", SID_LOG_CLOSE); }
void SID_exit(int status){ int i_args=0; int n_days; int n_hrs; int n_mins; int n_secs; size_t max_RAM; size_t SID_max_RAM_local; int i_rank; char spacer[10]; char time_string[48]; // Deal with I/O channels fflush(SID.fp_log); SID_Barrier(SID.COMM_WORLD); if(SID.fp_in!=stdin && SID.fp_in!=NULL) fclose(SID.fp_in); // Clean-up argument stuff if(SID.args!=NULL){ while((SID_arg *)(SID.args[i_args])!=NULL){ if(SID.arg_alloc[i_args]) free(((SID_arg *)(SID.args[i_args]))->val); i_args++; } if(i_args>0){ free(SID.arg_alloc); free(SID.arg_set); } } // Clean-up any memory still allocated // Report execution statistics if(status!=ERROR_SYNTAX){ if(SID.I_am_Master){ fprintf(SID.fp_log,"\n"); fprintf(SID.fp_log,"Run statistics:\n"); fprintf(SID.fp_log,"--------------\n"); (void)time(&(SID.time_stop)); n_secs =(int)(SID.time_stop-SID.time_start); seconds2ascii(n_secs,time_string); fprintf(SID.fp_log,"Time elapsed=%s.\n",time_string); } // Report memory usage if(SID.I_am_Master){ fprintf(SID.fp_log,"\nMemory usage:\n"); fprintf(SID.fp_log,"------------\n"); } #if USE_MPI SID_Barrier(SID.COMM_WORLD); SID_Allreduce(&(SID.max_RAM_local),&max_RAM,1,SID_SIZE_T,SID_SUM,SID.COMM_WORLD); if(SID.n_proc>1){ for(i_rank=0;i_rank<SID.n_proc;i_rank++){ SID_max_RAM_local=SID.max_RAM_local; if(i_rank!=MASTER_RANK) SID_Bcast(&SID_max_RAM_local,sizeof(size_t),i_rank,SID.COMM_WORLD); if(SID.I_am_Master){ if(SID.n_proc>1000){ if((float)SID.max_RAM_local/(float)SIZE_OF_MEGABYTE>1.) fprintf(SID.fp_log,"Peak for rank %4d=%4.2lf Gb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_GIGIBYTE); else if((float)SID.max_RAM_local/(float)SIZE_OF_KILOBYTE>1.) fprintf(SID.fp_log,"Peak for rank %4d=%4.2lf Mb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_MEGABYTE); else fprintf(SID.fp_log,"Peak for rank %4d=%4.2lf kb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_KILOBYTE); strcpy(spacer," "); } else if(SID.n_proc>100){ if((float)SID.max_RAM_local/(float)SIZE_OF_MEGABYTE>1.) fprintf(SID.fp_log,"Peak for rank %3d=%4.2lf Gb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_GIGIBYTE); else if((float)SID.max_RAM_local/(float)SIZE_OF_KILOBYTE>1.) fprintf(SID.fp_log,"Peak for rank %3d=%4.2lf Mb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_MEGABYTE); else fprintf(SID.fp_log,"Peak for rank %3d=%4.2lf kb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_KILOBYTE); strcpy(spacer," "); } else if(SID.n_proc>10){ if((float)SID.max_RAM_local/(float)SIZE_OF_MEGABYTE>1.) fprintf(SID.fp_log,"Peak for rank %2d=%4.2lf Gb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_GIGIBYTE); else if((float)SID.max_RAM_local/(float)SIZE_OF_KILOBYTE>1.) fprintf(SID.fp_log,"Peak for rank %2d=%4.2lf Mb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_MEGABYTE); else fprintf(SID.fp_log,"Peak for rank %2d=%4.2lf kb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_KILOBYTE); strcpy(spacer," "); } else{ if((float)SID.max_RAM_local/(float)SIZE_OF_MEGABYTE>1.) fprintf(SID.fp_log,"Peak for rank %d=%4.2lf Gb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_GIGIBYTE); else if((float)SID.max_RAM_local/(float)SIZE_OF_KILOBYTE>1.) fprintf(SID.fp_log,"Peak for rank %d=%4.2lf Mb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_MEGABYTE); else fprintf(SID.fp_log,"Peak for rank %d=%4.2lf kb\n",i_rank,(float)SID_max_RAM_local/(float)SIZE_OF_KILOBYTE); strcpy(spacer," "); } } SID_Barrier(SID.COMM_WORLD); } } #else strcpy(spacer,"\0"); max_RAM=SID.max_RAM_local; #endif if(SID.I_am_Master){ if((float)max_RAM/(float)SIZE_OF_MEGABYTE>1.) fprintf(SID.fp_log,"Peak total %s=%4.2lf Gb\n",spacer,(float)max_RAM/(float)SIZE_OF_GIGIBYTE); else if((float)max_RAM/(float)SIZE_OF_KILOBYTE>1.) fprintf(SID.fp_log,"Peak total %s=%4.2lf Mb\n",spacer,(float)max_RAM/(float)SIZE_OF_MEGABYTE); else fprintf(SID.fp_log,"Peak total %s=%4.2lf kb\n",spacer,(float)max_RAM/(float)SIZE_OF_KILOBYTE); } } // Free some arrays SID_free(SID_FARG SID.time_start_level); SID_free(SID_FARG SID.time_stop_level); SID_free(SID_FARG SID.time_total_level); SID_free(SID_FARG SID.flag_use_timer); SID_free(SID_FARG SID.IO_size); SID_free(SID_FARG SID.My_node); // Finalize MPI SID_Comm_free(&(SID.COMM_WORLD)); #if USE_MPI_IO MPI_Info_free(&(SID.file_info)); #endif #if USE_MPI MPI_Finalize(); #endif exit(status); }