-
Notifications
You must be signed in to change notification settings - Fork 16
Add test for MPI 4.0 MPI_Win_shared_query #36
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
|
|
||
|
|
||
| CC=mpicc | ||
| CFLAGS=-Wall -g -O0 | ||
|
|
||
| PROGS=test_mpi_win_shared_query | ||
|
|
||
| all: $(PROGS) | ||
|
|
||
| test_mpi_win_shared_query: test_mpi_win_shared_query.c | ||
| $(CC) test_mpi_win_shared_query.c $(CFLAGS) -o test_mpi_win_shared_query | ||
|
|
||
|
|
||
| clean: | ||
| rm -f *.o $(PROGS) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/bin/bash -e | ||
|
|
||
| echo "=============================" | ||
| echo "Testing: MPI_Win_shared_query" | ||
| echo "=============================" | ||
| mpirun --np 2 ./test_mpi_win_shared_query | ||
|
|
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,112 @@ | ||||||||||||||||||||||||||||||||||
| #include <mpi.h> | ||||||||||||||||||||||||||||||||||
| #include <stdio.h> | ||||||||||||||||||||||||||||||||||
| #include <stdbool.h> | ||||||||||||||||||||||||||||||||||
| #include <stdlib.h> | ||||||||||||||||||||||||||||||||||
| #include <string.h> | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| void test_shared_memory(MPI_Win win, MPI_Comm comm, int *local_mem, int shared_size, const char *test_name) { | ||||||||||||||||||||||||||||||||||
| int ret = MPI_SUCCESS; | ||||||||||||||||||||||||||||||||||
| int rank, size; | ||||||||||||||||||||||||||||||||||
| MPI_Comm_rank(comm, &rank); | ||||||||||||||||||||||||||||||||||
| MPI_Comm_size(comm, &size); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Configure the window to return errors instead of aborting | ||||||||||||||||||||||||||||||||||
| MPI_Win_set_errhandler(win, MPI_ERRORS_RETURN); | ||||||||||||||||||||||||||||||||||
| if (rank != 0) { | ||||||||||||||||||||||||||||||||||
| do { | ||||||||||||||||||||||||||||||||||
| // Query the shared memory of rank 0 | ||||||||||||||||||||||||||||||||||
| int *baseptr; | ||||||||||||||||||||||||||||||||||
| MPI_Aint queried_size; | ||||||||||||||||||||||||||||||||||
| int disp_unit; | ||||||||||||||||||||||||||||||||||
| ret = MPI_Win_shared_query(win, 0, &queried_size, &disp_unit, &baseptr); | ||||||||||||||||||||||||||||||||||
| if (ret != MPI_SUCCESS) { | ||||||||||||||||||||||||||||||||||
| printf("%s: rank %d: MPI_Win_shared_query failed with error code %d\n", test_name, rank, ret); | ||||||||||||||||||||||||||||||||||
| ret = MPI_ERR_OTHER; | ||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (baseptr == NULL) { | ||||||||||||||||||||||||||||||||||
| printf("%s: rank %d: MPI_Win_shared_query returned NULL\n", test_name, rank); | ||||||||||||||||||||||||||||||||||
| if (queried_size != 0) { | ||||||||||||||||||||||||||||||||||
| printf("%s: rank %d: Expected zero size but got %zu\n", test_name, rank, queried_size); | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| ret = MPI_ERR_NO_MEM; | ||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (queried_size != shared_size) { | ||||||||||||||||||||||||||||||||||
| printf("%s: rank %d: Queried size mismatch: expected %d, got %zu\n", test_name, rank, shared_size, queried_size); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+31
to
+38
|
||||||||||||||||||||||||||||||||||
| printf("%s: rank %d: Expected zero size but got %zu\n", test_name, rank, queried_size); | |
| } | |
| ret = MPI_ERR_NO_MEM; | |
| break; | |
| } | |
| if (queried_size != shared_size) { | |
| printf("%s: rank %d: Queried size mismatch: expected %d, got %zu\n", test_name, rank, shared_size, queried_size); | |
| printf("%s: rank %d: Expected zero size but got %ld\n", test_name, rank, (long)queried_size); | |
| } | |
| ret = MPI_ERR_NO_MEM; | |
| break; | |
| } | |
| if (queried_size != shared_size) { | |
| printf("%s: rank %d: Queried size mismatch: expected %d, got %ld\n", test_name, rank, shared_size, (long)queried_size); |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null check after malloc. If malloc fails and returns NULL, the subsequent MPI_Gather call will cause undefined behavior.
| int *ret_vals = (int *)malloc(size * sizeof(int)); | |
| int *ret_vals = (int *)malloc(size * sizeof(int)); | |
| if (ret_vals == NULL) { | |
| printf("%s: rank %d: malloc for ret_vals failed\n", test_name, rank); | |
| ret = MPI_ERR_NO_MEM; | |
| // Use MPI_Gather with a NULL recvbuf only on non-root, or skip entirely | |
| // To avoid undefined behavior, we return early | |
| return; | |
| } |
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: ret_vals is allocated but never freed. Add free(ret_vals) after the MPI_Gather operation and result processing.
Copilot
AI
Sep 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing null check after malloc. If malloc fails and returns NULL, the subsequent MPI_Win_create call may cause undefined behavior.
| int* local_mem = (int*)malloc(sizeof(int) * win_size); | |
| int* local_mem = (int*)malloc(sizeof(int) * win_size); | |
| if (local_mem == NULL) { | |
| fprintf(stderr, "Error: malloc failed for local_mem in MPI_Win_create test\n"); | |
| MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The format specifier
%zuis used forMPI_Aint queried_size, butMPI_Aintis not guaranteed to be the same type assize_t. Use%ldwith a cast tolongor check the MPI implementation's recommended format specifier forMPI_Aint.