From 67340746514b2898052beefdaadc9bb5a1ac3c4f Mon Sep 17 00:00:00 2001 From: Mikael Djurfeldt <mikael@djurfeldt.com> Date: Tue, 19 Jul 2022 14:33:31 +0200 Subject: [PATCH] Add mpi_utils.cc and music/mpi_utils.hh and include the latter --- src/Makefile.am | 3 +- src/collector.cc | 1 + src/distributor.cc | 1 + src/error.cc | 1 + src/mpi_utils.cc | 63 +++++++++++++++++++++++++++++++++++++++ src/music/mpi_utils.hh | 35 ++++++++++++++++++++++ src/music/multibuffer.hh | 1 + src/music/subconnector.hh | 1 + src/sampler.cc | 1 + 9 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 src/mpi_utils.cc create mode 100644 src/music/mpi_utils.hh diff --git a/src/Makefile.am b/src/Makefile.am index 0a133e0..95f2ea8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,7 @@ ACLOCAL = $(top_srcdir)/aclocal.sh lib_LTLIBRARIES = libmusic.la libmusic-c.la libmusic_la_SOURCES = \ + mpi_utils.cc music/mpi_utils.hh \ runtime.cc music/runtime.hh \ setup.cc music/setup.hh \ error.cc music/error.hh music/debug.hh \ @@ -88,6 +89,6 @@ musicinclude_HEADERS = music/runtime.hh music/setup.hh \ music/message.hh music/music-config.hh \ music/predict_rank.hh music/predict_rank-c.h \ music/communication.hh music/version.hh \ - music/memory.hh + music/memory.hh music/mpi_utils.hh MKDEP = gcc -M $(DEFS) $(INCLUDES) $(CPPFLAGS) $(CFLAGS) diff --git a/src/collector.cc b/src/collector.cc index 65411ba..a95b2fa 100644 --- a/src/collector.cc +++ b/src/collector.cc @@ -30,6 +30,7 @@ #include <cstring> #include "music/event.hh" +#include "music/mpi_utils.hh" namespace MUSIC { diff --git a/src/distributor.cc b/src/distributor.cc index b9d5236..374be25 100644 --- a/src/distributor.cc +++ b/src/distributor.cc @@ -31,6 +31,7 @@ #include <cstring> #include "music/event.hh" +#include "music/mpi_utils.hh" namespace MUSIC { diff --git a/src/error.cc b/src/error.cc index 7dd7ceb..583ad00 100644 --- a/src/error.cc +++ b/src/error.cc @@ -22,6 +22,7 @@ #include <mpi.h> #endif +#include "music/mpi_utils.hh" #include "music/error.hh" #include <iostream> diff --git a/src/mpi_utils.cc b/src/mpi_utils.cc new file mode 100644 index 0000000..105292b --- /dev/null +++ b/src/mpi_utils.cc @@ -0,0 +1,63 @@ +/* + * This file is part of MUSIC. + * Copyright (C) 2022 Mikael Djurfeldt + * + * MUSIC is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * MUSIC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "music/mpi_utils.hh" + +namespace MUSIC { + + int + mpi_get_rank (MPI_Comm comm) + { + int rank; + MPI_Comm_rank (comm, &rank); + return rank; + } + + int + mpi_get_size (MPI_Comm comm) + { + int size; + MPI_Comm_size (comm, &size); + return size; + } + + int + mpi_get_size (MPI_Group group) + { + int size; + MPI_Group_size (group, &size); + return size; + } + + int + mpi_get_size (MPI_Datatype type) + { + int size; + MPI_Type_size (type, &size); + return size; + } + + MPI_Group + mpi_get_group (MPI_Comm comm) + { + MPI_Group group; + MPI_Comm_group (comm, &group); + return group; + } + +} diff --git a/src/music/mpi_utils.hh b/src/music/mpi_utils.hh new file mode 100644 index 0000000..8f34544 --- /dev/null +++ b/src/music/mpi_utils.hh @@ -0,0 +1,35 @@ +/* + * This file is part of MUSIC. + * Copyright (C) 2022 Mikael Djurfeldt + * + * MUSIC is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * MUSIC is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef MUSIC_MPI_UTILS_HH +#define MUSIC_MPI_UTILS_HH +#include "music/music-config.hh" +#if MUSIC_USE_MPI +#include <mpi.h> + +namespace MUSIC +{ + int mpi_get_rank (MPI_Comm comm); + int mpi_get_size (MPI_Comm comm); + int mpi_get_size (MPI_Group group); + int mpi_get_size (MPI_Datatype type); + MPI_Group mpi_get_group (MPI_Comm comm); +} + +#endif /* MUSIC_USE_MPI */ +#endif /* MUSIC_MPI_UTILS_HH */ diff --git a/src/music/multibuffer.hh b/src/music/multibuffer.hh index d9dee25..53cea72 100644 --- a/src/music/multibuffer.hh +++ b/src/music/multibuffer.hh @@ -22,6 +22,7 @@ #include "music/music-config.hh" +#include "music/mpi_utils.hh" #include "music/connector.hh" #include <vector> diff --git a/src/music/subconnector.hh b/src/music/subconnector.hh index 6015058..53bd70a 100644 --- a/src/music/subconnector.hh +++ b/src/music/subconnector.hh @@ -29,6 +29,7 @@ #include <music/BIFO.hh> #include <music/event.hh> #include <music/message.hh> +#include <music/mpi_utils.hh> namespace MUSIC { diff --git a/src/sampler.cc b/src/sampler.cc index 9563ce9..0fbf620 100644 --- a/src/sampler.cc +++ b/src/sampler.cc @@ -28,6 +28,7 @@ #include "music/array_data.hh" #include "music/index_map_factory.hh" #include "music/error.hh" +#include "music/mpi_utils.hh" #include <cstring> -- GitLab