99int main(
int argc,
char** argv) {
103 feenableexcept(FE_DIVBYZERO| FE_INVALID | FE_OVERFLOW);
130 int mpi_rank, mpi_size, mpi_root;
139 "Tag %s\nBranch %s\n\n", GIT_VERSION, GIT_BRANCH);
157 "\nInput reading or initializing failed.\n"
158 "See stderr for details.\n");
168 goto CLEANUP_FAILURE;
178 goto CLEANUP_FAILURE;
189 &sim, n_tot, n_proc, ps, &n_gathered, &pout);
203 goto CLEANUP_FAILURE;
259 "\nInitializing marker states.\n");
262 for(
int i = 0; i < *n_proc; i++) {
267 "Estimated memory usage %.1f MB.\n",
268 (
sizeof(
real) * (*n_proc)) / (1024.0*1024.0));
270 "Marker states initialized.\n");
273 free(pin-start_index);
294 "\nPreparing output.\n");
297 "\nInitializing output failed.\n"
298 "See stderr for details.\n");
302 strcpy(sim->
qid, qid);
314 sim->
hdf5_out,
"inistate", n_gather, ps_gather)) {
317 "Writing inistate failed.\n"
318 "See stderr for details.\n"
324 "\nInistate written.\n");
354 real t_sim_start = omp_get_wtime();
358 real t_sim_end = omp_get_wtime();
360 "Simulation finished in %lf s\n", t_sim_end-t_sim_start);
388 sim->
hdf5_out,
"endstate", n_tot, ps)) {
390 "\nWriting endstate failed.\n"
391 "See stderr for details.\n");
395 "Endstate written.\n");
400 "\nCombining and writing diagnostics.\n");
401 int err_writediag = 0;
408 "\nWriting diagnostics failed.\n"
409 "See stderr for details.\n");
414 "Diagnostics written.\n");
446 struct option longopts[] = {
447 {
"in", required_argument, 0, 1},
448 {
"out", required_argument, 0, 2},
449 {
"mpi_size", required_argument, 0, 3},
450 {
"mpi_rank", required_argument, 0, 4},
451 {
"d", required_argument, 0, 5},
452 {
"options", required_argument, 0, 6},
453 {
"bfield", required_argument, 0, 7},
454 {
"efield", required_argument, 0, 8},
455 {
"marker", required_argument, 0, 9},
456 {
"wall", required_argument, 0, 10},
457 {
"plasma", required_argument, 0, 11},
458 {
"neutral", required_argument, 0, 12},
459 {
"boozer", required_argument, 0, 13},
460 {
"mhd", required_argument, 0, 14},
461 {
"asigma", required_argument, 0, 15},
486 while((c = getopt_long(argc, argv,
"", longopts, NULL)) != -1) {
491 slen = strlen(optarg);
492 if ( slen > 3 && !strcmp(optarg+slen-3,
".h5") ) {
503 slen = strlen(optarg);
504 if ( slen > 3 && !strcmp(optarg+slen-3,
".h5") ) {
554 "\nUnrecognized argument. The valid arguments are:\n");
556 "--in input file (default: ascot.h5)\n");
558 "--out output file (default: same as input)\n");
560 "--mpi_size number of independent processes\n");
562 "--mpi_rank rank of independent process\n");
564 "--d run description maximum of 250 characters\n");
574 strcpy(sim->
hdf5_in,
"ascot.h5");
579 strcpy(sim->
hdf5_in,
"ascot.h5");
615 int* temp = (
int*)malloc(n_tot*
sizeof(
int));
616 int* unique = (
int*)malloc(n_tot*
sizeof(
int));
617 int* count = (
int*)malloc((n_tot+1)*
sizeof(int));
620 for(
int i=0; i<n_tot; i++) {
629 while(count[i] > 0) {
632 for(
int j=0; j<32;j++) {
635 char endcondstr[256];
636 endcondstr[0] =
'\0';
643 strcat(endcondstr,
" and ");
647 strcat(endcondstr, temp);
651 sprintf(endcondstr,
"Aborted");
654 count[i], endcondstr);
662 for(
int i=0; i<n_tot; i++) {
663 temp[i] = (int)(ps[i].err);
669 while(count[i] > 0) {
680 "%9d markers were aborted with an error message:\n"
682 " at line %s in %s\n",
683 count[i], msg, line, file);
689 if(count[0] == n_tot && unique[0] == 0) {
691 " No markers were aborted.\n");
void B_field_free(B_field_data *data)
Free allocated resources.
Header file for B_field.c.
void E_field_free(E_field_data *data)
Free allocated resources.
Main header file for ASCOT5.
int main(int argc, char **argv)
Main function for ascot5_main.
int offload_and_simulate(sim_data *sim, int n_tot, int n_proc, particle_state *pin, int *n_gather, particle_state **pout)
Offload data to target, carry out the simulation, and return to host.
int prepare_markers(sim_data *sim, int n_tot, input_particle *pin, particle_state **pout, int *n_proc)
Prepare markers for offload.
void print_marker_summary(particle_state *ps, int n_tot)
Writes a summary of what happened to the markers during simulation.
int write_output(sim_data *sim, particle_state *ps, int n_tot)
Store simulation output data.
int write_rungroup(sim_data *sim, particle_state *ps, int n_tot, char *qid)
Create and store run group and marker inistate.
int read_arguments(int argc, char **argv, sim_data *sim)
Read command line arguments and modify sim struct accordingly.
Functions to execute main program externally.
void asigma_free(asigma_data *data)
Free allocated resources.
void boozer_free(boozer_data *data)
Free allocated resources.
Header file containing physical and mathematical constants.
int diag_init(diag_data *data, int Nmrk)
Initializes diagnostics data.
void diag_free(diag_data *data)
Free allocated resources.
void endcond_parse(int endcond, int *endconds)
Split endcond to an array of end conditions.
void endcond_parse2str(int endcond, char *str)
Represent end condition in human-readable format.
Header file for endcond.c.
void error_parse2str(a5err err, char *msg, char *line, char *file)
Convert error flag in string format.
int hdf5_interface_write_diagnostics(sim_data *sim)
Write diagnostics to HDF5 output.
int hdf5_interface_write_state(char *fn, char *state, integer n, particle_state *p)
Write marker state to HDF5 output.
int hdf5_interface_init_results(sim_data *sim, char *qid, char *run)
Initialize run group.
int hdf5_interface_read_input(sim_data *sim, int input_active, input_particle **p, int *n_markers)
Read and initialize input data.
void hdf5_generate_qid(char *qid)
Generate an identification number for a run.
Header file for hdf5_interface.c.
void math_uniquecount(int *in, int *unique, int *count, int n)
Find unique numbers and their frequency in given array.
void mhd_free(mhd_data *data)
Free allocated resources.
void mpi_gather_diag(diag_data *data, int ntotal, int mpi_rank, int mpi_size, int mpi_root)
Gather all diagnostics to the root process.
void mpi_my_particles(int *start_index, int *n, int n_tot, int mpi_rank, int mpi_size)
Divide markers to mpi processes.
void mpi_interface_finalize()
Finalize MPI.
void mpi_interface_init(int argc, char **argv, int *mpi_rank, int *mpi_size, int *mpi_root)
Initialize MPI.
void mpi_interface_barrier()
Wait until all processes have reached this routine.
void mpi_gather_particlestate(particle_state *ps, particle_state **ps_gather, int *n_gather, int n_tot, int mpi_rank, int mpi_size, int mpi_root)
Gather all particle states to the root process.
Header file for mpi_interface.c.
void neutral_free(neutral_data *data)
Free allocated resources.
void particle_input_to_state(input_particle *p, particle_state *ps, B_field_data *Bdata)
Converts input marker to a marker state.
Header file for particle.c.
void plasma_free(plasma_data *data)
Free allocated resources.
Header file for plasma.c.
Macros for printing console output.
#define print_out(v,...)
Print to standard output.
#define print_out0(v, rank, root,...)
Print to standard output only for root process.
void simulate(int n_particles, particle_state *p, sim_data *sim)
Execute marker simulation.
Header file for simulate.c.
Wrapper for marker structs.
General representation of a marker.
neutral_data neutral_data
void wall_free(wall_data *data)
Free allocated resources.