diff --git a/src/Makefile.am b/src/Makefile.am index 0a133e024d0f76c49f6461818ddfc9086f677722..95f2ea87811beecb19288514b63b57066b826355 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 65411bac3352a62e8b38ef2f7641d940ebdc2ea0..a95b2fae3bf39ea1709b5185d1d13be3c7d3a148 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 b9d52360a824e367dce0279a1b3099168e30279f..374be25788d1d01e08c145db4fc6ff05c569ba15 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 7dd7ceb5c85d9919553859e95ead788c1a29013e..583ad003bb1b928aee22b101d550133a9e4946ad 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 0000000000000000000000000000000000000000..105292b8c871107328de44e83b868752ba91395c --- /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 0000000000000000000000000000000000000000..8f34544f8cbb9482c4cb959f1c08abfa006ae294 --- /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 d9dee25f9740583d70b7d33f92499dad8fc84606..53cea7212c1d7ef1ec8002faa1bb66dc05a5101e 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 60150580d2761fed8f41644f60e32e0a750720c4..53bd70aa78de84146f10808a6d5f0b7970e2da23 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 9563ce91b87ea1062a29945adaf75abd0342f764..0fbf62091bb603bea5edaced5e60a3d1a9af8273 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>