made a safer memory allocation for mpi