X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/826897d361add5db3272a9810e70371a40ba1660..3037a0963f5d462b145ee127ffaed836dffd0085:/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c diff --git a/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c b/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c index ef6705083c..fa0f49bf39 100644 --- a/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c +++ b/teshsuite/smpi/mpich3-test/rma/linked_list_bench_lock_all.c @@ -28,12 +28,12 @@ #define MIN_NPROBE 1 #define ELEM_PER_ROW 16 -#define MIN(X,Y) ((X < Y) ? (X) : (Y)) -#define MAX(X,Y) ((X > Y) ? (X) : (Y)) +#define MYMIN(X,Y) ((X < Y) ? (X) : (Y)) +#define MYMAX(X,Y) ((X > Y) ? (X) : (Y)) /* Linked list pointer */ typedef struct { - int rank; + int rank; MPI_Aint disp; } llist_ptr_t; @@ -44,44 +44,46 @@ typedef struct { } llist_elem_t; static const llist_ptr_t nil = { -1, (MPI_Aint) MPI_BOTTOM }; + static const int verbose = 0; static const int print_perf = 0; -/* List of locally allocated list elements. */ -static llist_elem_t **my_elems = NULL; -static int my_elems_size = 0; -static int my_elems_count = 0; - /* Allocate a new shared linked list element */ -MPI_Aint alloc_elem(int value, MPI_Win win) { +static MPI_Aint alloc_elem(int value, MPI_Win win, llist_elem_t ***my_elems, int* my_elems_size, int* my_elems_count) +{ MPI_Aint disp; llist_elem_t *elem_ptr; /* Allocate the new element and register it with the window */ MPI_Alloc_mem(sizeof(llist_elem_t), MPI_INFO_NULL, &elem_ptr); elem_ptr->value = value; - elem_ptr->next = nil; + elem_ptr->next = nil; MPI_Win_attach(win, elem_ptr, sizeof(llist_elem_t)); /* Add the element to the list of local elements so we can free it later. */ - if (my_elems_size == my_elems_count) { - my_elems_size += 100; - my_elems = realloc(my_elems, my_elems_size*sizeof(void*)); + if (*my_elems_size == *my_elems_count) { + *my_elems_size += 100; + *my_elems = realloc(*my_elems, *my_elems_size * sizeof(void *)); } - my_elems[my_elems_count] = elem_ptr; - my_elems_count++; + (*my_elems)[*my_elems_count] = elem_ptr; + (*my_elems_count)++; MPI_Get_address(elem_ptr, &disp); return disp; } -int main(int argc, char **argv) { - int procid, nproc, i, j, my_nelem; - int pollint = 0; - double time; - MPI_Win llist_win; - llist_ptr_t head_ptr, tail_ptr; - +int main(int argc, char **argv) +{ + int procid, nproc, i, j, my_nelem; + int pollint = 0; + double time; + MPI_Win llist_win; + llist_ptr_t head_ptr, tail_ptr; + + /* List of locally allocated list elements. */ + llist_elem_t **my_elems = NULL; + int my_elems_size = 0; + int my_elems_count = 0; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &procid); @@ -91,7 +93,7 @@ int main(int argc, char **argv) { /* Process 0 creates the head node */ if (procid == 0) - head_ptr.disp = alloc_elem(procid, llist_win); + head_ptr.disp = alloc_elem(procid, llist_win, &my_elems, &my_elems_size, &my_elems_count); /* Broadcast the head pointer to everyone */ head_ptr.rank = 0; @@ -105,7 +107,7 @@ int main(int argc, char **argv) { else i = 0; - my_nelem = NUM_ELEMS/nproc; + my_nelem = NUM_ELEMS / nproc; if (procid < NUM_ELEMS % nproc) my_nelem++; @@ -115,31 +117,33 @@ int main(int argc, char **argv) { /* Lock the window for shared access to all targets */ MPI_Win_lock_all(0, llist_win); - for ( ; i < my_nelem; i++) { + for (; i < my_nelem; i++) { llist_ptr_t new_elem_ptr; int success = 0; + MTEST_VG_MEM_INIT(&new_elem_ptr, sizeof(llist_ptr_t)); + /* Create a new list element and register it with the window */ new_elem_ptr.rank = procid; - new_elem_ptr.disp = alloc_elem(procid, llist_win); + new_elem_ptr.disp = alloc_elem(procid, llist_win, &my_elems, &my_elems_size, &my_elems_count); /* Append the new node to the list. This might take multiple attempts if - others have already appended and our tail pointer is stale. */ + * others have already appended and our tail pointer is stale. */ do { int flag; /* The tail is at my left neighbor, append my element. */ - if (tail_ptr.rank == (procid + nproc-1) % nproc) - { + if (tail_ptr.rank == (procid + nproc - 1) % nproc) { if (verbose) - printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, (void*) tail_ptr.disp); + printf("%d: Appending to <%d, %p>\n", procid, tail_ptr.rank, + (void *) tail_ptr.disp); #if 1 MPI_Accumulate(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t), - MPI_BYTE, MPI_REPLACE, llist_win); + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), + sizeof(llist_ptr_t), MPI_BYTE, MPI_REPLACE, llist_win); #else MPI_Put(&new_elem_ptr, sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), sizeof(llist_ptr_t), + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), sizeof(llist_ptr_t), MPI_BYTE, llist_win); #endif MPI_Win_flush(tail_ptr.rank, llist_win); @@ -149,28 +153,29 @@ int main(int argc, char **argv) { } /* Otherwise, chase the tail. */ - else - { + else { llist_ptr_t next_tail_ptr; - MPI_Get_accumulate( NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr, - sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, - (MPI_Aint) &(((llist_elem_t*)tail_ptr.disp)->next), - sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win); + MPI_Get_accumulate(NULL, 0, MPI_DATATYPE_NULL, &next_tail_ptr, + sizeof(llist_ptr_t), MPI_BYTE, tail_ptr.rank, + (MPI_Aint) & (((llist_elem_t *) tail_ptr.disp)->next), + sizeof(llist_ptr_t), MPI_BYTE, MPI_NO_OP, llist_win); MPI_Win_flush(tail_ptr.rank, llist_win); if (next_tail_ptr.rank != nil.rank) { if (verbose) - printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, (void*) next_tail_ptr.disp); + printf("%d: Chasing to <%d, %p>\n", procid, next_tail_ptr.rank, + (void *) next_tail_ptr.disp); tail_ptr = next_tail_ptr; - pollint = MAX(MIN_NPROBE, pollint/2); + pollint = MYMAX(MIN_NPROBE, pollint / 2); } else { for (j = 0; j < pollint; j++) - MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, MPI_STATUS_IGNORE); + MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, MPI_COMM_WORLD, &flag, + MPI_STATUS_IGNORE); - pollint = MIN(MAX_NPROBE, pollint*2); + pollint = MYMIN(MAX_NPROBE, pollint * 2); } } } while (!success); @@ -181,12 +186,12 @@ int main(int argc, char **argv) { time = MPI_Wtime() - time; /* Traverse the list and verify that all processes inserted exactly the correct - number of elements. */ + * number of elements. */ if (procid == 0) { - int errors = 0; + int errors = 0; int *counts, count = 0; - counts = (int*) malloc(sizeof(int) * nproc); + counts = (int *) malloc(sizeof(int) * nproc); assert(counts != NULL); for (i = 0; i < nproc; i++) @@ -222,18 +227,19 @@ int main(int argc, char **argv) { MPI_Win_unlock_all(llist_win); if (verbose) - printf("\n\n"); + printf("\n\n"); /* Verify the counts we collected */ for (i = 0; i < nproc; i++) { int expected; - expected = NUM_ELEMS/nproc; + expected = NUM_ELEMS / nproc; if (i < NUM_ELEMS % nproc) expected++; if (counts[i] != expected) { - printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], expected); + printf("Error: Rank %d inserted %d elements, expected %d\n", i, counts[i], + expected); errors++; } } @@ -248,15 +254,16 @@ int main(int argc, char **argv) { MPI_Reduce(&time, &max_time, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); if (procid == 0) { - printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, NUM_ELEMS/max_time, max_time/NUM_ELEMS*1.0e6); + printf("Total time = %0.2f sec, elem/sec = %0.2f, sec/elem = %0.2f usec\n", max_time, + NUM_ELEMS / max_time, max_time / NUM_ELEMS * 1.0e6); } } MPI_Win_free(&llist_win); /* Free all the elements in the list */ - for ( ; my_elems_count > 0; my_elems_count--) - MPI_Free_mem(my_elems[my_elems_count-1]); + for (; my_elems_count > 0; my_elems_count--) + MPI_Free_mem(my_elems[my_elems_count - 1]); MPI_Finalize(); return 0;