htrdr_combustion_main.c (3123B)
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 "combustion/htrdr_combustion.h" 25 #include "combustion/htrdr_combustion_args.h" 26 27 #include "core/htrdr.h" 28 #include "core/htrdr_args.h" 29 #include "core/htrdr_log.h" 30 31 #include <rsys/mem_allocator.h> 32 33 int 34 htrdr_combustion_main(int argc, char** argv) 35 { 36 char cmd_name[] = "htrdr-combustion"; 37 struct htrdr_args htrdr_args = HTRDR_ARGS_DEFAULT; 38 struct htrdr_combustion_args cmd_args = HTRDR_COMBUSTION_ARGS_DEFAULT; 39 struct htrdr* htrdr = NULL; 40 struct htrdr_combustion* cmd = NULL; 41 const size_t memsz_begin = mem_allocated_size(); 42 size_t memsz_end; 43 int is_mpi_init = 0; 44 res_T res = RES_OK; 45 int err = 0; 46 47 /* Overwrite command name */ 48 argv[0] = cmd_name; 49 50 res = htrdr_mpi_init(argc, argv); 51 if(res != RES_OK) goto error; 52 is_mpi_init = 1; 53 54 res = htrdr_combustion_args_init(&cmd_args, argc, argv); 55 if(res != RES_OK) goto error; 56 if(cmd_args.quit) goto exit; 57 58 htrdr_args.nthreads = cmd_args.nthreads; 59 htrdr_args.verbose = cmd_args.verbose; 60 res = htrdr_create(&mem_default_allocator, &htrdr_args, &htrdr); 61 if(res != RES_OK) goto error; 62 63 if(cmd_args.output_type != HTRDR_COMBUSTION_ARGS_OUTPUT_IMAGE 64 && htrdr_get_mpi_rank(htrdr) != 0) { 65 goto exit; /* Nothing to do except for the master process */ 66 } 67 68 res = htrdr_combustion_create(htrdr, &cmd_args, &cmd); 69 if(res != RES_OK) goto error; 70 71 res = htrdr_combustion_run(cmd); 72 if(res != RES_OK) goto error; 73 74 exit: 75 htrdr_combustion_args_release(&cmd_args); 76 if(is_mpi_init) htrdr_mpi_finalize(); 77 if(htrdr) htrdr_ref_put(htrdr); 78 if(cmd) htrdr_combustion_ref_put(cmd); 79 80 /* Check memory leaks */ 81 memsz_end = mem_allocated_size(); 82 if(memsz_begin != memsz_end) { 83 ASSERT(memsz_end >= memsz_begin); 84 fprintf(stderr, HTRDR_LOG_WARNING_PREFIX"Memory leaks: %lu Bytes\n", 85 (unsigned long)(memsz_end - memsz_begin)); 86 err = -1; 87 } 88 return err; 89 error: 90 err = -1; 91 goto exit; 92 } 93