I'm writing a MPI_Win wrapper in C++11 which looks as follows.
#include <utility>
#include <mpi.h>
class WinWrapper {
MPI_Win win;
public:
template<typename Scalar>
WinWrapper(Scalar *data, std::size_t dataSize, MPI_Comm comm) {
MPI_Win_create(data, dataSize * sizeof(Scalar), sizeof(Scalar),
MPI_INFO_NULL, comm, &win);
}
WinWrapper(WinWrapper const &wrapper) {
win = wrapper.win;
}
WinWrapper(WinWrapper &&wrapper) : win(wrapper.win) {
wrapper.win = MPI_WIN_NULL;
}
WinWrapper &operator=(WinWrapper const &wrapper) {
win = wrapper.win;
return *this;
}
WinWrapper &operator=(WinWrapper &&wrapper) {
if (&wrapper != this) {
win = wrapper.win;
wrapper.win = MPI_WIN_NULL;
}
return *this;
}
~WinWrapper() {
if (win != MPI_WIN_NULL) {
MPI_Win_free(&win);
}
}
}; // end class WinWrapper
int main(int argc, char **argv) {
MPI_Init(&argc, &argv);
{
std::size_t dataSize{100};
int* data;
MPI_Alloc_mem(sizeof(int) * dataSize, MPI_INFO_NULL, &data);
WinWrapper w1{data, dataSize, MPI_COMM_WORLD};
// WinWrapper w2 = w1;
WinWrapper w3 = std::move(w1);
WinWrapper w4{std::move(w3)};
//WinWrapper w5{w4};
}
MPI_Finalize();
}
I pass a Scalar * which can be int *, double *, etc ... pointers allocated using MPI_Alloc_mem. When I uncomment the copy constructor or the copy assignment operator in main, I get a segmentation fault
[latitude:21878] *** Process received signal ***
[latitude:21878] Signal: Segmentation fault (11)
[latitude:21878] Signal code: Address not mapped (1)
[latitude:21878] Failing at address: 0x18
[latitude:21878] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390) [0x7fbc12c1c390]
[latitude:21878] [ 1] /home/teodor/soft/lib /libmpi.so.20(ompi_win_free+0xe)[0x7fbc12e70f7e]
[latitude:21878] [ 2] /home/teodor/soft/lib/libmpi.so.20(MPI_Win_free+0x9b)[0x7fbc12ea3ecb]
[latitude:21878] [ 3] ./example/winwrapper(main+0xbd)[0x400c0d]
[latitude:21878] [ 4] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7fbc11fb7830]
[latitude:21878] [ 5] ./example/winwrapper(_start+0x29)[0x400a79]
[latitude:21878] *** End of error message ***
[2] 21878 segmentation fault (core dumped) ./example/winwrapper
Is there a similar routine to MPI_Comm_dup for MPI_Win? If not, how do I make the copy operations work?
The MPI Reference mentions something about future proposals to duplicate windows, but I don't think it makes sense anyway. I think what you should do is to `=delete` the copy assignment and the copy constructor. Windows are inherently no-copyable objects.
RépondreSupprimer