100int main(
int argc,
char** argv) {
104 feenableexcept(FE_DIVBYZERO| FE_INVALID | FE_OVERFLOW);
131 int mpi_rank, mpi_size, mpi_root;
140 "Tag %s\nBranch %s\n\n", GIT_VERSION, GIT_BRANCH);
150 real* B_offload_array;
151 real* E_offload_array;
152 real* plasma_offload_array;
153 real* neutral_offload_array;
154 real* wall_offload_array;
155 int* wall_int_offload_array;
156 real* boozer_offload_array;
157 real* mhd_offload_array;
158 real* asigma_offload_array;
159 real* diag_offload_array;
168 &B_offload_array, &E_offload_array,
169 &plasma_offload_array, &neutral_offload_array,
170 &wall_offload_array, &wall_int_offload_array,
171 &boozer_offload_array, &mhd_offload_array,
172 &asigma_offload_array, NULL,
175 "\nInput reading or initializing failed.\n"
176 "See stderr for details.\n");
186 goto CLEANUP_FAILURE;
192 int* int_offload_array;
194 &sim, &offload_data, &B_offload_array, &E_offload_array,
195 &plasma_offload_array, &neutral_offload_array, &wall_offload_array,
196 &wall_int_offload_array, &boozer_offload_array, &mhd_offload_array,
197 &asigma_offload_array, &offload_array, &int_offload_array) ) {
198 goto CLEANUP_FAILURE;
204 "Initialized diagnostics, %.1f MB.\n",
212 goto CLEANUP_FAILURE;
223 &sim, n_tot, n_proc, ps, &offload_data, offload_array,
224 int_offload_array, &n_gathered, &pout, diag_offload_array);
230 if(
write_output(&sim, pout, n_gathered, diag_offload_array) ) {
231 goto CLEANUP_FAILURE;
252 free(int_offload_array);
253 free(diag_offload_array);
295 "\nInitializing marker states.\n");
300 for(
int i = 0; i < *n_proc; i++) {
305 "Estimated memory usage %.1f MB.\n",
306 (
sizeof(
real) * (*n_proc)) / (1024.0*1024.0));
308 "Marker states initialized.\n");
311 free(pin-start_index);
343 real** B_offload_array,
real** E_offload_array,
real** plasma_offload_array,
344 real** neutral_offload_array,
real** wall_offload_array,
345 int** wall_int_offload_array,
real** boozer_offload_array,
346 real** mhd_offload_array,
real** asigma_offload_array,
real** offload_array,
347 int** int_offload_array) {
352 offload_pack(offload_data, offload_array, *B_offload_array,
354 int_offload_array, NULL, 0);
357 offload_pack(offload_data, offload_array, *E_offload_array,
359 int_offload_array, NULL, 0);
362 offload_pack(offload_data, offload_array, *plasma_offload_array,
364 int_offload_array, NULL, 0);
367 offload_pack(offload_data, offload_array, *neutral_offload_array,
369 int_offload_array, NULL, 0);
372 offload_pack(offload_data, offload_array, *wall_offload_array,
374 int_offload_array, *wall_int_offload_array,
377 wall_int_offload_array);
379 offload_pack(offload_data, offload_array, *boozer_offload_array,
381 int_offload_array, NULL, 0);
384 offload_pack(offload_data, offload_array, *mhd_offload_array,
386 int_offload_array, NULL, 0);
389 offload_pack(offload_data, offload_array, *asigma_offload_array,
391 int_offload_array, NULL, 0);
414 "\nPreparing output.\n");
417 "\nInitializing output failed.\n"
418 "See stderr for details.\n");
422 strcpy(sim->
qid, qid);
434 sim->
hdf5_out,
"inistate", n_gather, ps_gather)) {
437 "Writing inistate failed.\n"
438 "See stderr for details.\n"
444 "\nInistate written.\n");
478 real t_sim_start = omp_get_wtime();
479 simulate(0, n_proc, pin, sim, offload_data,
480 offload_array, int_offload_array, diag_offload_array);
483 real t_sim_end = omp_get_wtime();
485 "Simulation finished in %lf s\n", t_sim_end-t_sim_start);
509 real* diag_offload_array){
514 sim->
hdf5_out,
"endstate", n_tot, ps)) {
516 "\nWriting endstate failed.\n"
517 "See stderr for details.\n");
521 "Endstate written.\n");
526 "\nCombining and writing diagnostics.\n");
527 int err_writediag = 0;
535 "\nWriting diagnostics failed.\n"
536 "See stderr for details.\n");
541 "Diagnostics written.\n");
573 struct option longopts[] = {
574 {
"in", required_argument, 0, 1},
575 {
"out", required_argument, 0, 2},
576 {
"mpi_size", required_argument, 0, 3},
577 {
"mpi_rank", required_argument, 0, 4},
578 {
"d", required_argument, 0, 5},
579 {
"options", required_argument, 0, 6},
580 {
"bfield", required_argument, 0, 7},
581 {
"efield", required_argument, 0, 8},
582 {
"marker", required_argument, 0, 9},
583 {
"wall", required_argument, 0, 10},
584 {
"plasma", required_argument, 0, 11},
585 {
"neutral", required_argument, 0, 12},
586 {
"boozer", required_argument, 0, 13},
587 {
"mhd", required_argument, 0, 14},
588 {
"asigma", required_argument, 0, 15},
613 while((c = getopt_long(argc, argv,
"", longopts, NULL)) != -1) {
618 slen = strlen(optarg);
619 if ( slen > 3 && !strcmp(optarg+slen-3,
".h5") ) {
630 slen = strlen(optarg);
631 if ( slen > 3 && !strcmp(optarg+slen-3,
".h5") ) {
681 "\nUnrecognized argument. The valid arguments are:\n");
683 "--in input file (default: ascot.h5)\n");
685 "--out output file (default: same as input)\n");
687 "--mpi_size number of independent processes\n");
689 "--mpi_rank rank of independent process\n");
691 "--d run description maximum of 250 characters\n");
701 strcpy(sim->
hdf5_in,
"ascot.h5");
706 strcpy(sim->
hdf5_in,
"ascot.h5");
742 int* temp = (
int*)malloc(n_tot*
sizeof(
int));
743 int* unique = (
int*)malloc(n_tot*
sizeof(
int));
744 int* count = (
int*)malloc((n_tot+1)*
sizeof(int));
747 for(
int i=0; i<n_tot; i++) {
756 while(count[i] > 0) {
759 for(
int j=0; j<32;j++) {
762 char endcondstr[256];
763 endcondstr[0] =
'\0';
770 strcat(endcondstr,
" and ");
774 strcat(endcondstr, temp);
778 sprintf(endcondstr,
"Aborted");
781 count[i], endcondstr);
789 for(
int i=0; i<n_tot; i++) {
790 temp[i] = (int)(ps[i].err);
796 while(count[i] > 0) {
807 "%9d markers were aborted with an error message:\n"
809 " at line %s in %s\n",
810 count[i], msg, line, file);
816 if(count[0] == n_tot && unique[0] == 0) {
818 " No markers were aborted.\n");
int B_field_init(B_field_data *Bdata, B_field_offload_data *offload_data, real *offload_array)
Initialize magnetic field data struct on target.
void B_field_free_offload(B_field_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Header file for B_field.c.
void E_field_free_offload(E_field_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
Main header file for ASCOT5.
int write_rungroup(sim_offload_data *sim, particle_state *ps, int n_tot, char *qid)
Create and store run group and marker inistate.
int pack_offload_array(sim_offload_data *sim, offload_package *offload_data, real **B_offload_array, real **E_offload_array, real **plasma_offload_array, real **neutral_offload_array, real **wall_offload_array, int **wall_int_offload_array, real **boozer_offload_array, real **mhd_offload_array, real **asigma_offload_array, real **offload_array, int **int_offload_array)
Prepare offload array to be offloaded.
int prepare_markers(sim_offload_data *sim, int n_tot, input_particle *pin, particle_state **pout, int *n_proc, real *B_offload_array)
Prepare markers for offload.
int main(int argc, char **argv)
Main function for ascot5_main.
void print_marker_summary(particle_state *ps, int n_tot)
Writes a summary of what happened to the markers during simulation.
int read_arguments(int argc, char **argv, sim_offload_data *sim)
Read command line arguments and modify sim struct accordingly.
int offload_and_simulate(sim_offload_data *sim, int n_tot, int n_proc, particle_state *pin, offload_package *offload_data, real *offload_array, int *int_offload_array, int *n_gather, particle_state **pout, real *diag_offload_array)
Offload data to target, carry out the simulation, and return to host.
int write_output(sim_offload_data *sim, particle_state *ps, int n_tot, real *diag_offload_array)
Store simulation output data.
Functions to execute main program externally.
void asigma_free_offload(asigma_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
void boozer_free_offload(boozer_offload_data *offload_data, real **offload_array)
Free offload array.
Header file containing physical and mathematical constants.
void diag_free_offload(diag_offload_data *data, real **offload_array)
Frees the offload array.
int diag_init_offload(diag_offload_data *data, real **offload_array, int Nmrk)
Initializes offload array from offload data.
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_init_results(sim_offload_data *sim, char *qid, char *run)
Initialize run group.
int hdf5_interface_read_input(sim_offload_data *sim, int input_active, real **B_offload_array, real **E_offload_array, real **plasma_offload_array, real **neutral_offload_array, real **wall_offload_array, int **wall_int_offload_array, real **boozer_offload_array, real **mhd_offload_array, real **asigma_offload_array, real **nbi_offload_array, input_particle **p, int *n_markers)
Read and initialize input data.
int hdf5_interface_write_state(char *fn, char *state, integer n, particle_state *p)
Write marker state to HDF5 output.
int hdf5_interface_write_diagnostics(sim_offload_data *sim, real *diag_offload_array, char *out)
Write diagnostics to HDF5 output.
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_offload(mhd_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
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_gather_diag(diag_offload_data *data, real *offload_array, int ntotal, int mpi_rank, int mpi_size, int mpi_root)
Gather all diagnostics to the root process.
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_offload(neutral_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
void offload_free_offload(offload_package *o, real **offload_array, int **int_offload_array)
Free offload array and set offload_package to clean state.
void offload_init_offload(offload_package *o, real **offload_array, int **int_offload_array)
Initialize offload package.
void offload_pack(offload_package *o, real **offload_array, real *pack_array, size_t pack_length, int **int_offload_array, int *int_pack_array, size_t int_pack_length)
Pack an offload array to package array.
Header file for offload.h.
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_offload(plasma_offload_data *offload_data, real **offload_array)
Free offload array and reset parameters.
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_init_offload(sim_offload_data *sim)
Initializes simulation settings.
void simulate(int id, int n_particles, particle_state *p, sim_offload_data *sim_offload, offload_package *offload_data, real *offload_array, int *int_offload_array, real *diag_offload_array)
Execute marker simulation.
Header file for simulate.c.
Magnetic field simulation data.
size_t offload_array_length
Wrapper for marker structs.
Struct to keep track of the offload array length and unpack status.
General representation of a marker.
Simulation offload struct.
B_field_offload_data B_offload_data
plasma_offload_data plasma_offload_data
neutral_offload_data neutral_offload_data
mhd_offload_data mhd_offload_data
asigma_offload_data asigma_offload_data
boozer_offload_data boozer_offload_data
wall_offload_data wall_offload_data
E_field_offload_data E_offload_data
diag_offload_data diag_offload_data
int int_offload_array_length
void wall_free_offload(wall_offload_data *offload_data, real **offload_array, int **int_offload_array)
Free offload array and reset parameters.