Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPI_Win_shared_query give nullpointer with 1 process #6994

Closed
hakostra opened this issue Apr 26, 2024 · 2 comments · Fixed by #6996
Closed

MPI_Win_shared_query give nullpointer with 1 process #6994

hakostra opened this issue Apr 26, 2024 · 2 comments · Fixed by #6996

Comments

@hakostra
Copy link

I'm using MPICH 4.2.1 on Linux and have the example program:

#include <stdio.h>
#include <mpi.h>

int main() {
    int myid, numprocs, ierr;
    int disp_unit;
    MPI_Aint winsize, nelems;
    MPI_Comm shmcomm;
    void *baseptr;
    MPI_Win win;

    // Initialize MPI
    ierr = MPI_Init(NULL, NULL);
    ierr = MPI_Comm_rank(MPI_COMM_WORLD, &myid);
    ierr = MPI_Comm_size(MPI_COMM_WORLD, &numprocs);
    ierr = MPI_Comm_split_type(MPI_COMM_WORLD, MPI_COMM_TYPE_SHARED, 0,
        MPI_INFO_NULL, &shmcomm);

    // Allocate shared memory
    winsize = 1024;

    ierr = MPI_Win_allocate_shared(winsize, 1, MPI_INFO_NULL, shmcomm,
        &baseptr, &win);
    printf("Allocated shared memory segment: %ld %d\n", winsize, ierr);
    printf("  Value of pointer: %p\n", baseptr);

    ierr = MPI_Allreduce(&winsize, &nelems, 1, MPI_AINT, MPI_SUM, shmcomm);
    printf("Allreduce: %ld %ld\n", winsize, nelems);

    ierr = MPI_Win_shared_query(win, MPI_PROC_NULL, &winsize, &disp_unit,
        &baseptr);
    printf("Got winsize: %ld %d\n", winsize, ierr);
    printf("  Value of pointer: %p\n", baseptr);

    // Clean up
    ierr = MPI_Win_free(&win);
    ierr = MPI_Comm_free(&shmcomm);
    ierr = MPI_Finalize();

    return 0;
}

When compiling mpicc shmem.c and running with two or more processes on a single node/workstation everything looks good:

$ mpirun -prepend-rank -n 2 ./a.out 
[0] Allocated shared memory segment: 1024 0
[0]   Value of pointer: 0x7e5818510000
[0] Allreduce: 1024 2048
[0] Got winsize: 1024 0
[0]   Value of pointer: 0x7e5818510000
[1] Allocated shared memory segment: 1024 0
[1]   Value of pointer: 0x7052b7629400
[1] Allreduce: 1024 2048
[1] Got winsize: 1024 0
[1]   Value of pointer: 0x7052b7629000

When running the program using a single process, the winsize and baseptr returned from MPI_Win_shared_query is null:

$ mpirun -prepend-rank -n 1 ./a.out 
[0] Allocated shared memory segment: 1024 0
[0]   Value of pointer: 0x561e2bf07560
[0] Allreduce: 1024 1024
[0] Got winsize: 0 0
[0]   Value of pointer: (nil)

I tried the example with Open MPI and Intel MPI and both works as expected (i.e. I get a non-null pointer and winsize), both with a single and multiple processes.

Could this be a bug in MPICH? Thanks for all comments and help.

@hakostra
Copy link
Author

Small follow up:

  1. Most recent code from github produce the same (nullpointer) result
  2. MPICH 4.1.3 gives the expected result also running a single process:
$ mpirun -prepend-rank -n 1 ./a.out 
[0] Allocated shared memory segment: 1024 0
[0]   Value of pointer: 0x5cc2898d6260
[0] Allreduce: 1024 1024
[0] Got winsize: 1024 0
[0]   Value of pointer: 0x5cc2898d6260

@hzhou
Copy link
Contributor

hzhou commented Apr 26, 2024

Thanks for reporting. Fix coming...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants