ASCOT5
Loading...
Searching...
No Matches
Functions
ascot5_main.c File Reference

ASCOT5 stand-alone program. More...

#include <getopt.h>
#include <math.h>
#include <omp.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "ascot5.h"
#include "consts.h"
#include "wall.h"
#include "diag.h"
#include "B_field.h"
#include "plasma.h"
#include "print.h"
#include "simulate.h"
#include "particle.h"
#include "endcond.h"
#include "hdf5_interface.h"
#include "offload.h"
#include "gitver.h"
#include "mpi_interface.h"
#include "ascot5_main.h"

Go to the source code of this file.

Functions

int read_arguments (int argc, char **argv, sim_offload_data *sim)
 Read command line arguments and modify sim struct accordingly.
 
int main (int argc, char **argv)
 Main function for ascot5_main.
 
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 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 write_rungroup (sim_offload_data *sim, particle_state *ps, int n_tot, char *qid)
 Create and store run group and marker inistate.
 
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.
 
void print_marker_summary (particle_state *ps, int n_tot)
 Writes a summary of what happened to the markers during simulation.
 

Detailed Description

ASCOT5 stand-alone program.

This program reads data from input HDF5 file, simulates the given markers, and writes the output data to a HDF5 file.

The input and output files can be separate.

Example:

ascot5_main --in=in --out=out

Here "in" refers to in.h5 where input data is located and "out" to out.h5 where results will be stored. If no input argument is given the data is read from ascot.h5. If not output argument is given the results are stored in the input file.

This program assumes that the input file contains magnetic field, electric field, plasma, wall, and neutral data along with markers and options. See hdf5_input.c for details. This program uses the input fields that are marked as active (the HDF5 file can contain multiple instances of same input types but only the active one is used here).

The results are stored under /results/ group in output HDF5 file. The group is created if one does not exists. For each run a specific "run" group is created, which has the format run-XXXXXXXXXX, where "XXXXXXXXXX" is randomly generated identification number (QID). The run group holds information when the run was started, which input fields were used (referenced by their QIDs), and at least the marker initial and end states if the simulation succeeded. Also any other diagnostic data that was used is stored there.

This program uses MPI by dividing the number of markers equally to all MPI processes. The markers are not suffled so user is advised to do it beforehand to ensure work is evenly distributed. A single MPI process can be simulated with:

ascot5_main --mpi_size=size --mpi_rank=rank

where size refers to number of MPI processes and rank is the process being run (between [0, size-1]). Running the program this way does not use MPI. This is intended to be used in Condor-like environments.

You can add a description of the simulation as:

ascot5_main –d="This is a test run"

which is written in HDF5 file at the run group specific to this simulation.

In addition to output data, the simulation progress may be written in *.stdout files with each MPI process having dedicated file. See ascot5.h for details.

Definition in file ascot5_main.c.

Function Documentation

◆ read_arguments()

int read_arguments ( int argc,
char ** argv,
sim_offload_data * sim )

Read command line arguments and modify sim struct accordingly.

The command line arguments are in, out, mpi_size, and mpi_rank which correspond to input file, output file, number of MPI processes and the rank of this process. These are stored in simulation offload data struct as (default values, used if the specific argument was not given, are in parenthesis):

  • sim->hdf5_in = "in.h5" ("ascot.h5")
  • sim->hdf5_out = "out" (sim->hdf5_in is copied here)
  • sim->mpi_rank = 0
  • sim->mpi_size = 0
  • sim->desc = "No description"

If the arguments could not be parsed, this function returns a non-zero exit value.

Parameters
argcargument count as given to main()
argvargument vector as given to main()
simpointer to offload data struct
Returns
Zero if success

Definition at line 572 of file ascot5_main.c.

◆ main()

int main ( int argc,
char ** argv )

Main function for ascot5_main.

This function calls functions that read input data from the disk, and functions that initialize the offload data structs and offload arrays. Actual simulation is done by calling simulate(). Once the simulation has been completed, offload arrays are deallocated and the results are written to the disk.

MPI level parallelisation is done here as well as the offloading.

Parameters
argcargument count of the command line arguments
argvargument vector of the command line arguments
Returns
Zero if simulation was completed with no issues

Definition at line 100 of file ascot5_main.c.

◆ prepare_markers()

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.

This function initializes the marker states and allocates memory for the particle states. The input markers are read from the HDF5 file and stored in the input_particle_states array. The initial marker states are then calculated and stored in the particle_states array.

When MPI is used, the marker states are initialized only for those markers that are used in this MPI process.

Parameters
simsimulation offload data struct
n_tottotal number of markers
pinpointer to marker input array which is deallocated here
poutpointer to marker state array created here
n_procpointer to variable for number of markers for this process
B_offload_arraypointer to magnetic field data needed for marker init
Returns
zero on success

Definition at line 278 of file ascot5_main.c.

◆ pack_offload_array()

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.

When data is read, it is stored to input specific offload arrays which are packed as a single array here (two actually as one array contains integers and the other floats). The initial individual arrays are deallocated.

Parameters
simsimulation offload data struct
offload_dataempty offload package
B_offload_arraymagnetic field offload array
E_offload_arrayelectric field offload array
plasma_offload_arrayplasma offload array
neutral_offload_arrayneutrals offload array
wall_offload_arraywall offload array
wall_int_offload_arraywall integer offload array
boozer_offload_arrayboozer offload array
mhd_offload_arrayMHD data offload array
asigma_offload_arrayatomic data offload array
offload_arraypointer to common offload array created here
int_offload_arraypointer to common offload integer array created here
Returns
zero on success

Definition at line 341 of file ascot5_main.c.

◆ write_rungroup()

int write_rungroup ( sim_offload_data * sim,
particle_state * ps,
int n_tot,
char * qid )

Create and store run group and marker inistate.

Parameters
simsimulation offload data struct
psmarker state array for this process
n_tottotal number of markers in this simulation
qidunique identifier for this run group
Returns
zero on success

Definition at line 408 of file ascot5_main.c.

◆ offload_and_simulate()

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.

Parameters
simsimulation offload data struct
n_tottotal number of markers
n_procnumber of markers in this process
pinmarker state array for this process (deallocated here)
offload_datapacked offload data struct
offload_arraypacked offload array containing the input data
int_offload_arraypacked offload integer array containg the input data
n_gatherpointer for storing the number of markers in pout (either n_tot or n_proc)
poutpointer to array containing all endstates in the simulation
diag_offload_arrayarray to store output data
Returns
zero on success

Definition at line 469 of file ascot5_main.c.

◆ write_output()

int write_output ( sim_offload_data * sim,
particle_state * ps,
int n_tot,
real * diag_offload_array )

Store simulation output data.

Parameters
simsimulation offload data
psmarker endstate array to be written
n_totnumber of markers
diag_offload_arraydiagnostics offload data array
Returns
zero on success

Definition at line 508 of file ascot5_main.c.

◆ print_marker_summary()

void print_marker_summary ( particle_state * ps,
int n_tot )

Writes a summary of what happened to the markers during simulation.

This function writes a summary of marker end conditions and possible simulation-time errors. Since simulation can have billions and billions of markers, we only show how many markers had specific error or end condition.

End conditions and errors are printed in human-readable format.

This function is called by the root MPI process only.

Parameters
psarray of marker states after simulation has finished
n_totnumber of markers in the array

Definition at line 736 of file ascot5_main.c.