ASCOT5
|
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. | |
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.
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):
If the arguments could not be parsed, this function returns a non-zero exit value.
argc | argument count as given to main() |
argv | argument vector as given to main() |
sim | pointer to offload data struct |
Definition at line 572 of file ascot5_main.c.
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.
argc | argument count of the command line arguments |
argv | argument vector of the command line arguments |
Definition at line 100 of file ascot5_main.c.
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.
sim | simulation offload data struct |
n_tot | total number of markers |
pin | pointer to marker input array which is deallocated here |
pout | pointer to marker state array created here |
n_proc | pointer to variable for number of markers for this process |
B_offload_array | pointer to magnetic field data needed for marker init |
Definition at line 278 of file ascot5_main.c.
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.
sim | simulation offload data struct |
offload_data | empty offload package |
B_offload_array | magnetic field offload array |
E_offload_array | electric field offload array |
plasma_offload_array | plasma offload array |
neutral_offload_array | neutrals offload array |
wall_offload_array | wall offload array |
wall_int_offload_array | wall integer offload array |
boozer_offload_array | boozer offload array |
mhd_offload_array | MHD data offload array |
asigma_offload_array | atomic data offload array |
offload_array | pointer to common offload array created here |
int_offload_array | pointer to common offload integer array created here |
Definition at line 341 of file ascot5_main.c.
int write_rungroup | ( | sim_offload_data * | sim, |
particle_state * | ps, | ||
int | n_tot, | ||
char * | qid ) |
Create and store run group and marker inistate.
sim | simulation offload data struct |
ps | marker state array for this process |
n_tot | total number of markers in this simulation |
qid | unique identifier for this run group |
Definition at line 408 of file ascot5_main.c.
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.
sim | simulation offload data struct |
n_tot | total number of markers |
n_proc | number of markers in this process |
pin | marker state array for this process (deallocated here) |
offload_data | packed offload data struct |
offload_array | packed offload array containing the input data |
int_offload_array | packed offload integer array containg the input data |
n_gather | pointer for storing the number of markers in pout (either n_tot or n_proc) |
pout | pointer to array containing all endstates in the simulation |
diag_offload_array | array to store output data |
Definition at line 469 of file ascot5_main.c.
int write_output | ( | sim_offload_data * | sim, |
particle_state * | ps, | ||
int | n_tot, | ||
real * | diag_offload_array ) |
Store simulation output data.
sim | simulation offload data |
ps | marker endstate array to be written |
n_tot | number of markers |
diag_offload_array | diagnostics offload data array |
Definition at line 508 of file ascot5_main.c.
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.
ps | array of marker states after simulation has finished |
n_tot | number of markers in the array |
Definition at line 736 of file ascot5_main.c.