commit 2c4a5b8b76f79995692698f70eea9cf9aa6a224e
parent 8d56275e10b40905279e7713a2c0843a3779d790
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Mon, 11 Dec 2023 16:40:38 +0100
2 new accessors added and tested
The sdis_device_is_mpi_used function returns whether or not MPI support
is enabled on the queried device, while the sdis_scene_get_device
function returns the device used to create the scene.
Diffstat:
5 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/src/sdis.h b/src/sdis.h
@@ -730,6 +730,11 @@ sdis_device_ref_put
(struct sdis_device* dev);
SDIS_API res_T
+sdis_device_is_mpi_used
+ (struct sdis_device* dev,
+ int* is_mpi_used);
+
+SDIS_API res_T
sdis_device_get_mpi_rank
(struct sdis_device* dev,
int* rank);
@@ -1107,6 +1112,11 @@ sdis_scene_get_medium_spread
const struct sdis_medium* mdm,
double* spread);
+SDIS_API res_T
+sdis_scene_get_device
+ (struct sdis_scene* scn,
+ struct sdis_device** device);
+
/*******************************************************************************
* An estimator stores the state of a simulation
******************************************************************************/
diff --git a/src/sdis_device.c b/src/sdis_device.c
@@ -373,6 +373,18 @@ sdis_device_ref_put(struct sdis_device* dev)
}
res_T
+sdis_device_is_mpi_used(struct sdis_device* dev, int* is_mpi_used)
+{
+ if(!dev || !is_mpi_used) return RES_BAD_ARG;
+#ifndef SDIS_ENABLE_MPI
+ *is_mpi_used = 0;
+#else
+ *is_mpi_used = dev->use_mpi;
+#endif
+ return RES_OK;
+}
+
+res_T
sdis_device_get_mpi_rank(struct sdis_device* dev, int* rank)
{
#ifndef SDIS_ENABLE_MPI
diff --git a/src/sdis_scene.c b/src/sdis_scene.c
@@ -410,6 +410,14 @@ error:
goto exit;
}
+res_T
+sdis_scene_get_device(struct sdis_scene* scn, struct sdis_device** device)
+{
+ if(!scn || !device) return RES_BAD_ARG;
+ *device = scn->dev;
+ return RES_OK;
+}
+
/*******************************************************************************
* Local miscellaneous function
******************************************************************************/
@@ -556,4 +564,3 @@ exit:
error:
goto exit;
}
-
diff --git a/src/test_sdis_device.c b/src/test_sdis_device.c
@@ -37,6 +37,7 @@ main(int argc, char** argv)
struct logger logger;
struct mem_allocator allocator;
struct sdis_device* dev;
+ int is_mpi_used;
#ifdef SDIS_ENABLE_MPI
int provided;
#endif
@@ -84,6 +85,9 @@ main(int argc, char** argv)
args.nthreads_hint = SDIS_NTHREADS_DEFAULT;
OK(sdis_device_create(&args, &dev));
+ BA(sdis_device_is_mpi_used(NULL, &is_mpi_used));
+ BA(sdis_device_is_mpi_used(dev, NULL));
+
OK(sdis_device_ref_put(dev));
args.use_mpi = 1;
@@ -91,10 +95,14 @@ main(int argc, char** argv)
#ifndef SDIS_ENABLE_MPI
OK(sdis_device_create(&args, &dev));
+ OK(sdis_device_is_mpi_used(dev, &is_mpi_used));
+ CHK(!is_mpi_used);
OK(sdis_device_ref_put(dev));
#else
CHK(MPI_Init_thread(&argc, &argv, MPI_THREAD_SERIALIZED, &provided) == MPI_SUCCESS);
OK(sdis_device_create(&args, &dev));
+ OK(sdis_device_is_mpi_used(dev, &is_mpi_used));
+ CHK(is_mpi_used);
CHK(MPI_Finalize() == MPI_SUCCESS);
OK(sdis_device_ref_put(dev));
#endif
diff --git a/src/test_sdis_scene.c b/src/test_sdis_scene.c
@@ -99,6 +99,7 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf)
struct senc3d_scene* scn3d;
struct sdis_scene_create_args scn_args = SDIS_SCENE_CREATE_ARGS_DEFAULT;
struct sdis_scene* scn = NULL;
+ struct sdis_device* dev2 = NULL;
size_t ntris, npos;
size_t iprim;
size_t i;
@@ -163,6 +164,11 @@ test_scene_3d(struct sdis_device* dev, struct sdis_interface* interf)
OK(sdis_scene_get_dimension(scn, &dim));
CHK(dim == SDIS_SCENE_3D);
+ BA(sdis_scene_get_device(NULL, &dev2));
+ BA(sdis_scene_get_device(scn, NULL));
+ OK(sdis_scene_get_device(scn, &dev2));
+ CHK(dev == dev2);
+
BA(sdis_scene_get_aabb(NULL, lower, upper));
BA(sdis_scene_get_aabb(scn, NULL, upper));
BA(sdis_scene_get_aabb(scn, lower, NULL));