I’m trying to send and receive an array that is only allocated on the device:
#include <mpi.h>
#include <omp.h>
int main (int argc, char *argv[]) {
const size_t N = 16;
MPI_Init(NULL, NULL);
int rank, nranks;
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
MPI_Comm_size (MPI_COMM_WORLD, &nranks);
int device_id = omp_get_default_device();
int *x = (int*)omp_target_alloc(N * sizeof(int), device_id);
#pragma omp target is_device_ptr(x)
{
if (rank == 0) {
for (int i = 0; i < N; i++)
{
x[i] = i;
}
MPI_Send (x, N, MPI_INT, 1, 0, MPI_COMM_WORLD);
} else {
MPI_Recv (x, N, MPI_INT, 0, 0, MPI_COMM_WORLD, NULL);
}
}
omp_target_free(x, device_id);}
I compile with the nvhpc-hpcx module from HPC SDK 25.7, using mpicc -mp=gpu. This results in
nvlink error : Undefined reference to ‘MPI_Recv’ in ‘/tmp/nvcVHThpnC_h-wdA.o’
nvlink error : Undefined reference to ‘MPI_Send’ in ‘/tmp/nvcVHThpnC_h-wdA.o’
pgacclnk: child process exit status 2: /home/cweiss/local/hpc_sdk/Linux_x86_64/25.1/compilers/bin/tools/nvdd
I have confirmed with the -v option that -lmpi is linked. Also, when I leave out the pragma, the test code compiles fine.