htrdr_proc_work.h (2924B)
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 #ifndef HTRDR_PROC_WORK_H 25 #define HTRDR_PROC_WORK_H 26 27 #include <rsys/dynamic_array_u64.h> 28 29 #include <mpi.h> 30 31 #define CHUNK_ID_NULL UINT64_MAX 32 33 /* Forward declarations */ 34 struct mutex; 35 struct ssp_rng; 36 37 /* List of chunks to compute onto the MPI process */ 38 struct proc_work { 39 struct mutex* mutex; 40 struct darray_u64 chunks; /* #chunks to solve */ 41 uint64_t index; /* Next chunk to solve in the above list of chunks */ 42 }; 43 44 extern LOCAL_SYM void 45 proc_work_init 46 (struct mem_allocator* allocator, 47 struct proc_work* work); 48 49 extern LOCAL_SYM void 50 proc_work_release 51 (struct proc_work* work); 52 53 extern LOCAL_SYM void 54 proc_work_reset 55 (struct proc_work* work); 56 57 extern LOCAL_SYM void 58 proc_work_add_chunk 59 (struct proc_work* work, 60 const uint64_t ichunk); 61 62 /* Return the index of the next chunk to be processed */ 63 extern LOCAL_SYM uint64_t 64 proc_work_get_chunk 65 (struct proc_work* work); 66 67 extern LOCAL_SYM uint64_t 68 proc_work_get_nchunks 69 (struct proc_work* work); 70 71 /* Wait for the completion of an MPI request */ 72 extern LOCAL_SYM void 73 mpi_wait_for_request 74 (struct htrdr* htrdr, 75 MPI_Request* req); 76 77 /* Active polling of the "steal" request submitted by other processes to 78 * relieve the current process of the chunks assigned to it. 79 * The function runs until probe_thieves is set to 0 by the caller. */ 80 extern LOCAL_SYM void 81 mpi_probe_thieves 82 (struct htrdr* htrdr, 83 struct proc_work* work, 84 ATOMIC* probe_thieves); 85 86 /* Unload a working process by taking chunks from it, 87 * i.e. submit a steal request and wait for it to be honored */ 88 extern LOCAL_SYM size_t 89 mpi_steal_work 90 (struct htrdr* htrdr, 91 struct ssp_rng* rng, 92 struct proc_work* work); 93 94 #endif /* HTRDR_PROC_WORK_H */