bool validate(const std::vector<char> &firstLine, std::istream &input, ebi::vcf::Parser &validator, std::vector<std::unique_ptr<ebi::vcf::ReportWriter>> &outputs) { std::vector<char> line; line.reserve(default_line_buffer_size); validator.parse(firstLine); write_errors(validator, outputs); while (ebi::util::readline(input, line).size() != 0) { validator.parse(line); write_errors(validator, outputs); } validator.end(); write_errors(validator, outputs); return validator.is_valid(); }
int main(int argc, char** argv) { initialize_global_variables(); int ret = init_mpi(&argc, &argv); if (ret != POTFIT_SUCCESS) { shutdown_mpi(); return EXIT_FAILURE; } read_input_files(argc, argv); g_mpi.init_done = 1; ret = broadcast_params_mpi(); switch (ret) { case POTFIT_ERROR_MPI_CLEAN_EXIT: shutdown_mpi(); return EXIT_SUCCESS; case POTFIT_ERROR: shutdown_mpi(); return EXIT_FAILURE; } g_calc.ndim = g_pot.opt_pot.idxlen; g_calc.ndimtot = g_pot.opt_pot.len; // main force vector, all forces, energies, stresses, etc. will be stored here g_calc.force = (double*)Malloc(g_calc.mdim * sizeof(double)); // starting positions for the force vector set_force_vector_pointers(); #if defined(APOT) #if defined(MPI) MPI_Bcast(g_pot.opt_pot.table, g_calc.ndimtot, MPI_DOUBLE, 0, MPI_COMM_WORLD); #endif // MPI update_calc_table(g_pot.opt_pot.table, g_pot.calc_pot.table, 1); #endif // APOT if (g_mpi.myid > 0) { start_mpi_worker(g_calc.force); } else { #if defined(MPI) if (g_mpi.num_cpus > g_config.nconf) { warning("You are using more CPUs than you have configurations!\n"); warning("While this will not do any harm, you are wasting %d CPUs.\n", g_mpi.num_cpus - g_config.nconf); } #endif // MPI time_t start_time; time_t end_time; time(&start_time); if (g_param.opt && g_calc.ndim > 0) { run_optimization(); } else if (g_calc.ndim == 0) { printf( "\nOptimization disabled due to 0 free parameters. Calculating " "errors.\n"); } else { printf("\nOptimization disabled. Calculating errors.\n\n"); } time(&end_time); #if defined(APOT) double tot = calc_forces(g_pot.opt_pot.table, g_calc.force, 0); #else double tot = calc_forces(g_pot.calc_pot.table, g_calc.force, 0); #endif // APOT #if defined(UQ) return uncertainty_quantification(tot,g_files.sloppyfile); #endif //UQ write_pot_table_potfit(g_files.endpot); return 0; { int format = -1; switch (g_pot.format_type) { case POTENTIAL_FORMAT_UNKNOWN: error(1, "Unknown potential format detected! (%s:%d)\n", __FILE__, __LINE__); case POTENTIAL_FORMAT_ANALYTIC: format = 0; break; case POTENTIAL_FORMAT_TABULATED_EQ_DIST: format = 3; break; case POTENTIAL_FORMAT_TABULATED_NON_EQ_DIST: format = 4; break; } printf("\nPotential in format %d written to file \t%s\n", format, g_files.endpot); } if (g_param.writeimd == 1) write_pot_table_imd(g_files.imdpot); if (g_param.plot == 1) write_plotpot_pair(&g_pot.calc_pot, g_files.plotfile); if (g_param.write_lammps == 1) write_pot_table_lammps(); // will not work with MPI #if defined(PDIST) && !defined(MPI) write_pairdist(&g_pot.opt_pot, g_files.distfile); #endif // PDIST && !MPI // write the error files for forces, energies, stresses, ... write_errors(g_calc.force, tot); /* calculate total runtime */ if (g_param.opt && g_mpi.myid == 0 && g_calc.ndim > 0) { printf("\nRuntime: %d hours, %d minutes and %d seconds.\n", (int)difftime(end_time, start_time) / 3600, ((int)difftime(end_time, start_time) % 3600) / 60, (int)difftime(end_time, start_time) % 60); printf("%d force calculations, each took %f seconds\n", g_calc.fcalls, (double)difftime(end_time, start_time) / g_calc.fcalls); } #if defined(MPI) calc_forces(NULL, NULL, 1); /* go wake up other threads */ #endif // MPI } /* myid == 0 */ // do some cleanups before exiting #if defined(MPI) // kill MPI shutdown_mpi(); #endif // MPI free_allocated_memory(); return 0; }