Yet Another eXchange Tool 0.11.1
Loading...
Searching...
No Matches
Correct use of addresses

C Standard (section 6.5.6 Additive operators)

According to the C Standard, when computing the difference between two pointers, both have to point to elements of the same array object or to an element directly behind the last element of the array. If the pointers point to elements of different arrays, the result of the subtraction is undefined.

MPI Standard Version 3.1 (section 4.1.12)

The MPI Standard Version 3.1 states that difference between two valid addresses can only by computed if both addresses are in the same sequential storage.

Sequential storage is defined to be the memory associated with an array, a COMMON block (Fortran) or the memory of a single structure (C).

Why is this important for YAXT?

Multiple interfaces (C and Fortran) in YAXT accept one or more pointers as arguments (e.g. xt_redist_collection_static_new, xt_redist_collection_new, xt_redist_s_exchange, and xt_redist_a_exchange). Within YAXT, the differences of the corresponding addresses are computed. Therefore, to not violate the above standards, the addresses passed to the mentioned interfaces have to point to memory in sequential storage.

// non-standard conforming code
int * a = malloc(N * sizeof(*a));
int * b = malloc(M * sizeof(*b));
// working on a and b
// ...
void const * src_data[2] = {a, b};
void * dst_data[2] = {a, b};
xt_redist_s_exchange(redist_coll, 2, src_data, dst_data);
void xt_redist_s_exchange(Xt_redist redist, int num_arrays, const void **src_data, void **dst_data)
Definition xt_redist.c:78
// standard conform code
int * buffer = malloc((N + M) * sizeof(*a));
int * a = buffer;
int * b = buffer + N;
// working on a and b
// ...
void const * src_data[2] = {a, b};
void * dst_data[2] = {a, b};
xt_redist_s_exchange(redist_coll, 2, src_data, dst_data);

However...

On commonly used machines, e.g. all systems in the TOP500 of HPC systems at the time of this writing, this particular case of undefined behaviour does not lead to actual problems. Which means, that you can use multiple buffers in the same exchange and YAXT will deliver the expected results. However, we cannot guarantee that this will always be the case or that no future machines use features (e.g. segmented address space) that prohibit this.

In case this should become a significant issue, we will address this appropriately within YAXT.

TL;DR: Using YAXT with pointers to multiple objects breaks the relevant language standards in a way that is not conflicting with any known implementation and therefore not problematic in practice.