Skip to content

Conversation

devreal
Copy link

@devreal devreal commented Sep 19, 2025

Test for changes introduced in open-mpi/ompi#13330. Since MPI 4.0, MPI_Win_shared_query allows querying shared memory in windows created using MPI_Win_create and MPI_Win_allocate. This test checks that the call to MPI_Win_shared_query does not fail. The test itself does not fail if shared memory was not provided since that is not required.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a test suite for the new MPI 4.0 feature that allows MPI_Win_shared_query to be used with windows created by MPI_Win_create and MPI_Win_allocate, in addition to the existing support for MPI_Win_allocate_shared.

  • Implements comprehensive test coverage for all three window creation methods
  • Validates that MPI_Win_shared_query returns appropriate results without failing
  • Includes proper error handling and memory verification

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
one-sided/test_mpi_win_shared_query.c Main test implementation covering all three MPI window creation methods
one-sided/run.sh Simple shell script to execute the test with 2 MPI processes
one-sided/Makefile Build configuration for compiling the test executable

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

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);
Copy link
Preview

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format specifier %zu is used for MPI_Aint queried_size, but MPI_Aint is not guaranteed to be the same type as size_t. Use %ld with a cast to long or check the MPI implementation's recommended format specifier for MPI_Aint.

Suggested change
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 uses AI. Check for mistakes.

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);
Copy link
Preview

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format specifier %zu is used for MPI_Aint queried_size, but MPI_Aint is not guaranteed to be the same type as size_t. Use %ld with a cast to long or check the MPI implementation's recommended format specifier for MPI_Aint.

Suggested change
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 uses AI. Check for mistakes.

} while (false);
}

int *ret_vals = (int *)malloc(size * sizeof(int));
Copy link
Preview

Copilot AI Sep 19, 2025

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.

Suggested change
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 uses AI. Check for mistakes.


// Test with MPI_Win_create
MPI_Win win_create;
int* local_mem = (int*)malloc(sizeof(int) * win_size);
Copy link
Preview

Copilot AI Sep 19, 2025

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.

Suggested change
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);
}

Copilot uses AI. Check for mistakes.

}

int *ret_vals = (int *)malloc(size * sizeof(int));
MPI_Gather(&ret, 1, MPI_INT, ret_vals, 1, MPI_INT, 0, comm);
Copy link
Preview

Copilot AI Sep 19, 2025

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 uses AI. Check for mistakes.

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 this pull request may close these issues.

1 participant