Question

See the piece of code below:

#include <memory>
void foo() {
  std::unique_ptr<int> sp(new int);
  MPI_Isend(sp, 1, MPI_INT,...);
}

My question is: can sp be deleted at the end of function foo?

If it is, how can I manage a heap memory in the case I don't know the exact time deleting it?

Can this work, does a.size() bind memory of a?

#include <memory>
void foo(const vector<int> & a) {
  MPI_Isend((int)a.size(), 1, MPI_INT,...);
}

No correct solution

OTHER TIPS

From the documentation: "The sender should not access any part of the send buffer after a nonblocking send operation is called, until the send completes." That would include disposing of it.

BTW the documentation is completely incorrect in describing this as 'non-blocking'. The correct term for what is happening here is 'asynchronous'. If it was merely non-blocking there would be no problem with the buffer going out of scope, as the MPI_Isend() method would have completely finished with it once it had returned.

unique pointer sp will stay till end of foo() method.

But since MPI_Isend(...)is non blocking function the chances that unique pointer sp may be already destroyed when it is being used in MPI_Isend(...) method as you are not waiting for it finish. Its always suggested to pass copy data to MPI_ISend(...) non blocking method instead of smart pointer.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top