test_sdis_device.c (3308B)
1 /* Copyright (C) 2016-2025 |Méso|Star> (contact@meso-star.com) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #include "sdis.h" 17 #include "test_sdis_utils.h" 18 19 #include <rsys/logger.h> 20 21 #ifdef SDIS_ENABLE_MPI 22 #include <mpi.h> 23 #endif 24 25 static INLINE void 26 log_stream(const char* msg, void* ctx) 27 { 28 ASSERT(msg); 29 (void) msg, (void) ctx; 30 printf("%s\n", msg); 31 } 32 33 int 34 main(int argc, char** argv) 35 { 36 struct sdis_device_create_args args = SDIS_DEVICE_CREATE_ARGS_DEFAULT; 37 struct logger logger; 38 struct mem_allocator allocator; 39 struct sdis_device* dev; 40 int is_mpi_used; 41 #ifdef SDIS_ENABLE_MPI 42 int provided; 43 #endif 44 (void)argc, (void)argv; 45 46 args.nthreads_hint = 0; 47 args.verbosity = 0; 48 49 BA(sdis_device_create(&args, NULL)); 50 BA(sdis_device_create(&args, &dev)); 51 args.nthreads_hint = 1; 52 OK(sdis_device_create(&args, &dev)); 53 BA(sdis_device_ref_get(NULL)); 54 OK(sdis_device_ref_get(dev)); 55 BA(sdis_device_ref_put(NULL)); 56 OK(sdis_device_ref_put(dev)); 57 OK(sdis_device_ref_put(dev)); 58 59 OK(mem_init_proxy_allocator(&allocator, &mem_default_allocator)); 60 61 CHK(MEM_ALLOCATED_SIZE(&allocator) == 0); 62 63 args.allocator = &allocator; 64 args.verbosity = 0; 65 BA(sdis_device_create(&args, NULL)); 66 OK(sdis_device_create(&args, &dev)); 67 OK(sdis_device_ref_put(dev)); 68 CHK(MEM_ALLOCATED_SIZE(&allocator) == 0); 69 70 OK(logger_init(&allocator, &logger)); 71 logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL); 72 logger_set_stream(&logger, LOG_ERROR, log_stream, NULL); 73 logger_set_stream(&logger, LOG_WARNING, log_stream, NULL); 74 75 args.logger = &logger; 76 args.allocator = NULL; 77 BA(sdis_device_create(&args, NULL)); 78 OK(sdis_device_create(&args, &dev)); 79 OK(sdis_device_ref_put(dev)); 80 81 args.allocator = &allocator; 82 BA(sdis_device_create(&args, NULL)); 83 OK(sdis_device_create(&args, &dev)); 84 OK(sdis_device_ref_put(dev)); 85 86 args.nthreads_hint = SDIS_NTHREADS_DEFAULT; 87 OK(sdis_device_create(&args, &dev)); 88 BA(sdis_device_is_mpi_used(NULL, &is_mpi_used)); 89 BA(sdis_device_is_mpi_used(dev, NULL)); 90 91 OK(sdis_device_ref_put(dev)); 92 93 args.use_mpi = 1; 94 args.verbosity = 1; 95 96 #ifndef SDIS_ENABLE_MPI 97 OK(sdis_device_create(&args, &dev)); 98 OK(sdis_device_is_mpi_used(dev, &is_mpi_used)); 99 CHK(!is_mpi_used); 100 OK(sdis_device_ref_put(dev)); 101 #else 102 CHK(MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided) == MPI_SUCCESS); 103 OK(sdis_device_create(&args, &dev)); 104 OK(sdis_device_is_mpi_used(dev, &is_mpi_used)); 105 CHK(is_mpi_used); 106 CHK(MPI_Finalize() == MPI_SUCCESS); 107 OK(sdis_device_ref_put(dev)); 108 #endif 109 110 logger_release(&logger); 111 check_memory_allocator(&allocator); 112 mem_shutdown_proxy_allocator(&allocator); 113 CHK(mem_allocated_size() == 0); 114 return 0; 115 } 116