#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <assert.h>
#include <string.h>
#include <yaxt.h>
#include "tests.h"
#include "test_idxlist_utils.h"
static void
ref_get_positions_of_indices(
Xt_int const * indices,
int num_indices,
Xt_int const * selection,
int selection_size,
int * positions, int repeat_first_match) {
int used[num_indices > 0 ? num_indices : 1];
int found;
for (int i = 0; i < num_indices; i++)
used[i] = 0;
for (int i = 0; i < selection_size; i++) {
found = 0;
for (int j = 0; j < num_indices; j++) {
if (selection[i] == indices[j] && (repeat_first_match || !used[j])) {
positions[i] = j;
used[j] = 1;
found = 1;
break;
}
}
if (!found)
PUT_ERR("ref_get_positions_of_indices: internal test error\n");
}
}
static Xt_int get_min_index(
int num_indices,
const Xt_int *indices) {
Xt_int index = num_indices > 0 ? indices[0] : 0;
for (int i = 1; i < num_indices; ++i)
if (index > indices[i])
index = indices[i];
return index;
}
static Xt_int get_max_index(
int num_indices,
const Xt_int *indices) {
Xt_int index = num_indices > 0 ? indices[0] : 0;
for (int i = 1; i < num_indices; ++i)
if (index < indices[i])
index = indices[i];
return index;
}
int ref_num_indices) {
if (num_indices != ref_num_indices)
PUT_ERR("wrong number of indices in idxlist\n");
size_t ref_num_indices_ = (size_t)(ref_num_indices > 0 ? ref_num_indices : 1);
Xt_int indices[ref_num_indices_];
{
bool mismatch = false;
size_t ntrans_dn = 0, ntrans_up = 0;
for (size_t i = 1; i < ref_num_indices_; ++i) {
ntrans_dn += indices[i] < indices[i-1];
ntrans_up += indices[i] > indices[i-1];
mismatch |= (ref_indices[i] != indices_const[i])
| (ref_indices[i] != indices[i]);
}
if (ntrans_up && !ntrans_dn && sorting != 1)
PUT_ERR("incorrect ascending sorting returned!\n");
if (!ntrans_up && ntrans_dn && sorting != -1)
PUT_ERR("incorrect descending sorting returned!\n");
if (num_indices && !ntrans_up && !ntrans_dn && sorting != 3)
PUT_ERR("incorrect sorting returned!\n");
else if (!num_indices && sorting != 2)
PUT_ERR("incorrect sorting returned!\n");
if (mismatch)
PUT_ERR("check_idxlist: index reference mismatch\n");
}
{
bool is_sorted = true;
size_t indices_mem_size = ref_num_indices_ * sizeof (*sorted_ref_indices);
for (size_t i = 1; i < ref_num_indices_; ++i)
is_sorted &= (ref_indices[i-1] <= ref_indices[i]);
if (is_sorted)
sorted_ref_indices = (
Xt_int *)(
void *)ref_indices;
else {
sorted_ref_indices
memcpy(sorted_ref_indices, ref_indices, indices_mem_size);
}
Xt_int sorted_indices[ref_num_indices_];
bool mismatch = false;
for(int i=0; i<ref_num_indices; i++)
mismatch |= (sorted_ref_indices[i] != sorted_indices[i]);
if (mismatch)
PUT_ERR("check_idxlist: incorrect index sorting detected!\n");
if (sorted_ref_indices != ref_indices)
free(sorted_ref_indices);
}
{
int ref_positions[2][ref_num_indices_];
{
int position;
ref_get_positions_of_indices(indices, num_indices, ref_indices,
ref_num_indices, ref_positions[1], 1);
bool mismatch = false;
for (int i = 0; i < ref_num_indices; ++i)
mismatch |= (indices[i] != ref_indices[i]);
if (mismatch)
PUT_ERR("index list contains wrong indices\n");
for (int i = 0; i < ref_num_indices; ++i) {
|| index != ref_indices[i])
PUT_ERR("error in xt_idxlist_get_index_at_position\n");
|| position != ref_positions[1][i])
PUT_ERR("error in xt_idxlist_get_position_of_index\n");
}
ref_get_positions_of_indices(indices, num_indices, ref_indices,
ref_num_indices, ref_positions[0], 0);
position = -1;
for (int i = 0; i < ref_num_indices; ++i) {
&position, position+1))
PUT_ERR("error in xt_idxlist_get_position_of_index_off\n");
if (position != ref_positions[0][i])
PUT_ERR("get_positions_of_indices returned wrong position\n");
}
}
{
int positions[ref_num_indices_];
ref_num_indices, positions, 1))
PUT_ERR("get_positions_of_indices failed\n");
bool mismatch = false;
for (int i = 0; i < ref_num_indices; ++i)
mismatch |= (positions[i] != ref_positions[0][i]);
if (mismatch)
PUT_ERR("check_idxlist: get_positions_of_indices failed (case 1)\n");
}
{
int positions[ref_num_indices_];
ref_num_indices, positions, 0))
PUT_ERR("get_positions_of_indices failed\n");
bool mismatch = false;
for (int i = 0; i < ref_num_indices; ++i)
mismatch |= (positions[i] != ref_positions[1][i]);
if (mismatch)
PUT_ERR("check_idxlist: get_positions_of_indices failed (case 2)\n");
}
{
Xt_int reverse_ref_indices[ref_num_indices_];
for (int i = 0; i < ref_num_indices; ++i)
reverse_ref_indices[i] = ref_indices[ref_num_indices - i - 1];
{
int positions[ref_num_indices_];
ref_get_positions_of_indices(indices, num_indices, reverse_ref_indices,
ref_num_indices, ref_positions[0], 0);
ref_num_indices, positions, 1))
PUT_ERR("get_positions_of_indices failed\n");
bool mismatch = false;
for (int i = 0; i < ref_num_indices; ++i)
mismatch |= (positions[i] != ref_positions[0][i]);
if (mismatch)
PUT_ERR("check_idxlist: get_positions_of_indices failed (case 3)\n");
}
{
int positions[ref_num_indices_];
ref_num_indices, positions, 0))
PUT_ERR("get_positions_of_indices failed\n");
bool mismatch = false;
for (int i = 0; i < ref_num_indices; ++i)
mismatch |= (positions[i] != ref_positions[1][ref_num_indices-1-i]);
if (mismatch)
PUT_ERR("check_idxlist: get_positions_of_indices failed (case 4)\n");
}
}
}
if (ref_num_indices > 0) {
if (get_min_index(ref_num_indices, ref_indices) !=
PUT_ERR("check_idxlist: get_min_index failed\n");
if (get_max_index(ref_num_indices, ref_indices) !=
PUT_ERR("check_idxlist: get_max_index failed\n");
}
PUT_ERR("error in xt_idxlist_get_index_at_position\n");
PUT_ERR("error in xt_idxlist_get_index_at_position\n");
}
void
check_stripes(
struct Xt_stripe const * stripes,
int num_stripes,
struct Xt_stripe const * ref_stripes,
int ref_num_stripes) {
if (num_stripes != ref_num_stripes)
PUT_ERR("wrong number of stripes\n");
bool mismatch = false;
for (i = 0; i < ref_num_stripes; ++i)
mismatch |= (stripes[i].start != ref_stripes[i].start ||
stripes[i].nstrides != ref_stripes[i].nstrides ||
stripes[i].stride != ref_stripes[i].stride);
if (mismatch)
PUT_ERR("error in stripe (start, nstrides and/or stride)\n");
}
void
check_offsets(size_t num_offsets, const int offsets_a[num_offsets],
const int offsets_b[num_offsets])
{
bool mismatch = false;
for(size_t i=0; i<num_offsets; i++)
mismatch |= (offsets_a[i] != offsets_b[i]);
if (mismatch)
PUT_ERR("unexpected results for offsets or index positions\n");
}
{
size_t buffer_size
void *send_buffer =
xmalloc(buffer_size),
*recv_buffer =
xmalloc(buffer_size);
int position = 0;
assert(buffer_size <= INT_MAX);
assert((size_t)position <= buffer_size);
int rank;
MPI_Request request;
xt_mpi_call(MPI_Isend(send_buffer, (
int)buffer_size, MPI_PACKED, rank, 0,
xt_mpi_call(MPI_Recv(recv_buffer, (
int)buffer_size, MPI_PACKED, rank, 0,
free(send_buffer);
position = 0;
assert((size_t)position <= buffer_size);
free(recv_buffer);
return idxlist_copy;
}
static int
xt_int_compare(const void *a, const void *b)
{
}
void
size_t num_ref_indices,
const Xt_int *ref_indices,
size_t num_ref_stripes,
const struct Xt_stripe *ref_stripes)
{
check_idxlist(idxlist_copy, ref_indices, (int)num_ref_indices);
* sizeof (ref_indices[0]));
memcpy(sorted_ref_indices, ref_indices,
num_ref_indices * sizeof (ref_indices[0]));
qsort(sorted_ref_indices, num_ref_indices, sizeof (ref_indices[0]),
xt_int_compare);
check_idxlist(intersection, sorted_ref_indices, (int)num_ref_indices);
free(sorted_ref_indices);
int num_stripes;
check_stripes(stripes, num_stripes, ref_stripes, (int)num_ref_stripes);
free(stripes);
}
void xt_mergesort_xt_int(Xt_int a[], size_t n)
add versions of standard API functions not returning on error
Xt_idxlist xt_idxlist_sorted_copy(Xt_idxlist idxlist)
int xt_idxlist_get_positions_of_indices(Xt_idxlist idxlist, const Xt_int *indices, int num_indices, int *positions, int single_match_only)
Xt_idxlist xt_idxlist_unpack(void *buffer, int buffer_size, int *position, MPI_Comm comm)
Xt_int xt_idxlist_get_min_index(Xt_idxlist idxlist)
const Xt_int * xt_idxlist_get_indices_const(Xt_idxlist idxlist)
int xt_idxlist_get_index_at_position(Xt_idxlist idxlist, int position, Xt_int *index)
Xt_int xt_idxlist_get_max_index(Xt_idxlist idxlist)
void xt_idxlist_get_indices(Xt_idxlist idxlist, Xt_int *indices)
int xt_idxlist_get_position_of_index_off(Xt_idxlist idxlist, Xt_int index, int *position, int offset)
void xt_idxlist_pack(Xt_idxlist idxlist, void *buffer, int buffer_size, int *position, MPI_Comm comm)
size_t xt_idxlist_get_pack_size(Xt_idxlist idxlist, MPI_Comm comm)
void xt_idxlist_get_index_stripes(Xt_idxlist idxlist, struct Xt_stripe **stripes, int *num_stripes)
Xt_idxlist xt_idxlist_get_intersection(Xt_idxlist idxlist_src, Xt_idxlist idxlist_dst)
int xt_idxlist_get_sorting(Xt_idxlist idxlist)
int xt_idxlist_get_position_of_index(Xt_idxlist idxlist, Xt_int index, int *position)
void xt_idxlist_delete(Xt_idxlist idxlist)
#define xt_idxlist_get_num_indices(idxlist)
#define xt_mpi_call(call, comm)