htrdr

Solving radiative transfer in heterogeneous media
git clone git://git.meso-star.fr/htrdr.git
Log | Files | Refs | README | LICENSE

htrdr_planets_main.c (3025B)


      1 /* Copyright (C) 2018-2019, 2022-2025 Centre National de la Recherche Scientifique
      2  * Copyright (C) 2020-2022 Institut Mines Télécom Albi-Carmaux
      3  * Copyright (C) 2022-2025 Institut Pierre-Simon Laplace
      4  * Copyright (C) 2022-2025 Institut de Physique du Globe de Paris
      5  * Copyright (C) 2018-2025 |Méso|Star> (contact@meso-star.com)
      6  * Copyright (C) 2022-2025 Observatoire de Paris
      7  * Copyright (C) 2022-2025 Université de Reims Champagne-Ardenne
      8  * Copyright (C) 2022-2025 Université de Versaille Saint-Quentin
      9  * Copyright (C) 2018-2019, 2022-2025 Université Paul Sabatier
     10  *
     11  * This program is free software: you can redistribute it and/or modify
     12  * it under the terms of the GNU General Public License as published by
     13  * the Free Software Foundation, either version 3 of the License, or
     14  * (at your option) any later version.
     15  *
     16  * This program is distributed in the hope that it will be useful,
     17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     19  * GNU General Public License for more details.
     20  *
     21  * You should have received a copy of the GNU General Public License
     22  * along with this program. If not, see <http://www.gnu.org/licenses/>. */
     23 
     24 #include "planets/htrdr_planets.h"
     25 #include "planets/htrdr_planets_args.h"
     26 
     27 #include "core/htrdr_log.h"
     28 
     29 #include <rsys/mem_allocator.h>
     30 
     31 int
     32 htrdr_planets_main(int argc, char** argv)
     33 {
     34   char cmd_name[] = "htrdr-planets";
     35   struct htrdr_args htrdr_args = HTRDR_ARGS_DEFAULT;
     36   struct htrdr_planets_args cmd_args = HTRDR_PLANETS_ARGS_DEFAULT;
     37   struct htrdr* htrdr = NULL;
     38   struct htrdr_planets* cmd = NULL;
     39   const size_t memsz_begin = mem_allocated_size();
     40   size_t memsz_end;
     41   int is_mpi_init = 0;
     42   res_T res = RES_OK;
     43   int err = 0;
     44 
     45   /* Overwrite command name */
     46   argv[0] = cmd_name;
     47 
     48   res = htrdr_mpi_init(argc, argv);
     49   if(res != RES_OK) goto error;
     50   is_mpi_init = 1;
     51 
     52   res = htrdr_planets_args_init(&cmd_args, argc, argv);
     53   if(res != RES_OK) goto error;
     54   if(cmd_args.quit) goto exit;
     55 
     56   htrdr_args.nthreads = cmd_args.nthreads;
     57   htrdr_args.verbose = cmd_args.verbose;
     58   res = htrdr_create(&mem_default_allocator, &htrdr_args, &htrdr);
     59   if(res != RES_OK) goto error;
     60 
     61   if(cmd_args.output_type == HTRDR_PLANETS_ARGS_OUTPUT_OCTREES
     62   && htrdr_get_mpi_rank(htrdr) != 0) {
     63     goto exit; /* Nothing to do except for the master process */
     64   }
     65 
     66   res = htrdr_planets_create(htrdr, &cmd_args, &cmd);
     67   if(res != RES_OK) goto error;
     68 
     69   res = htrdr_planets_run(cmd);
     70   if(res != RES_OK) goto error;
     71 
     72 exit:
     73   htrdr_planets_args_release(&cmd_args);
     74   if(is_mpi_init) htrdr_mpi_finalize();
     75   if(htrdr) htrdr_ref_put(htrdr);
     76   if(cmd) htrdr_planets_ref_put(cmd);
     77 
     78   /* Check memory leaks */
     79   memsz_end = mem_allocated_size();
     80   if(memsz_begin != memsz_end) {
     81     ASSERT(memsz_end >= memsz_begin);
     82     fprintf(stderr, HTRDR_LOG_WARNING_PREFIX"Memory leaks: %lu Bytes\n",
     83       (unsigned long)(memsz_end - memsz_begin));
     84     err = -1;
     85   }
     86   return err;
     87 error:
     88   err = -1;
     89   goto exit;
     90 }
     91