From 669c0dc7df9018e51add9a6ee0883549737ed635 Mon Sep 17 00:00:00 2001 From: Nathan Hjelm <hjelmn@google.com> Date: Tue, 20 Apr 2021 09:59:08 -0600 Subject: [PATCH] examples/test: format using clang-format This commit runs clang-format on the test and examples directories. Signed-off-by: Nathan Hjelm <hjelmn@google.com> --- examples/connectivity_c.c | 40 +- examples/dtrace/mpicommleak.c | 33 +- examples/hello_c.c | 7 +- examples/hello_oshmem_c.c | 9 +- examples/oshmem_circular_shift.c | 5 +- examples/oshmem_max_reduction.c | 5 +- examples/oshmem_shmalloc.c | 1 - examples/oshmem_strided_puts.c | 9 +- examples/oshmem_symmetric_data.c | 10 +- examples/ring_c.c | 12 +- examples/ring_oshmem_c.c | 13 +- examples/spc_example.c | 39 +- test/asm/atomic_barrier.c | 4 +- test/asm/atomic_cmpset.c | 65 +- test/asm/atomic_math.c | 164 +++-- test/asm/atomic_spinlock.c | 46 +- test/carto/carto_test.c | 90 +-- test/class/ompi_rb_tree.c | 238 +++---- test/class/opal_bitmap.c | 116 ++- test/class/opal_fifo.c | 240 ++++--- test/class/opal_hash_table.c | 212 +++--- test/class/opal_lifo.c | 149 ++-- test/class/opal_list.c | 199 +++--- test/class/opal_pointer_array.c | 88 +-- test/class/opal_proc_table.c | 118 ++-- test/class/opal_value_array.c | 27 +- test/datatype/checksum.c | 69 +- test/datatype/ddt_lib.c | 384 +++++----- test/datatype/ddt_lib.h | 50 +- test/datatype/ddt_pack.c | 274 +++++--- test/datatype/ddt_raw.c | 296 ++++---- test/datatype/ddt_raw2.c | 355 ++++------ test/datatype/ddt_test.c | 556 ++++++++------- test/datatype/external32.c | 195 +++--- test/datatype/large_data.c | 86 +-- test/datatype/opal_datatype_test.c | 847 ++++++++++++---------- test/datatype/opal_ddt_lib.c | 523 +++++++------- test/datatype/opal_ddt_lib.h | 43 +- test/datatype/partial.c | 113 +-- test/datatype/position.c | 193 +++-- test/datatype/position_noncontig.c | 168 +++-- test/datatype/reduce_local.c | 857 +++++++++++------------ test/datatype/to_self.c | 459 ++++++------ test/datatype/unpack_hetero.c | 51 +- test/datatype/unpack_ooo.c | 233 +++--- test/event/event-test.c | 194 +++-- test/event/signal-test.c | 69 +- test/event/time-test.c | 70 +- test/memchecker/irecv_init_check.c | 34 +- test/memchecker/irecv_uninit_check.c | 36 +- test/memchecker/non_blocking_recv_test.c | 33 +- test/memchecker/non_blocking_send_test.c | 34 +- test/monitoring/check_monitoring.c | 465 ++++++------ test/monitoring/example_reduce_count.c | 83 +-- test/monitoring/monitoring_test.c | 229 +++--- test/monitoring/test_overhead.c | 131 ++-- test/monitoring/test_pvar_access.c | 94 +-- test/mpi/environment/chello.c | 11 +- test/mpool/mpool_memkind.c | 69 +- test/runtime/opal_init_finalize.c | 5 +- test/runtime/orte_init_finalize.c | 9 +- test/runtime/sigchld.c | 7 +- test/runtime/start_shut.c | 19 +- test/simple/abort.c | 4 +- test/simple/accept.c | 4 +- test/simple/add_host.c | 26 +- test/simple/attach.c | 6 +- test/simple/bad_arg.c | 42 +- test/simple/bad_exit.c | 29 +- test/simple/badcoll.c | 6 +- test/simple/bcast_loop.c | 3 +- test/simple/binding.c | 22 +- test/simple/client.c | 59 +- test/simple/comm_abort.c | 132 ++-- test/simple/concurrent_spawn.c | 17 +- test/simple/connect.c | 4 +- test/simple/crisscross.c | 490 +++++++------ test/simple/debugger.c | 9 +- test/simple/delayed_abort.c | 6 +- test/simple/early_abort.c | 6 +- test/simple/hello.c | 5 +- test/simple/hello_barrier.c | 4 +- test/simple/hello_nodename.c | 11 +- test/simple/hello_output.c | 5 +- test/simple/hello_show_help.c | 42 +- test/simple/info_spawn.c | 17 +- test/simple/init-exit77.c | 17 +- test/simple/initial_errh.c | 168 +++-- test/simple/intercomm1.c | 22 +- test/simple/intercomm_create.c | 101 ++- test/simple/interlib.c | 70 +- test/simple/iof.c | 10 +- test/simple/loop_child.c | 15 +- test/simple/loop_spawn.c | 21 +- test/simple/mpi_barrier.c | 4 +- test/simple/mpi_info.c | 31 +- test/simple/mpi_no_op.c | 4 +- test/simple/mpi_spin.c | 27 +- test/simple/multi_abort.c | 7 +- test/simple/no-disconnect.c | 97 +-- test/simple/nonzero.c | 6 +- test/simple/parallel_r64.c | 312 ++++----- test/simple/parallel_r8.c | 312 ++++----- test/simple/parallel_w64.c | 321 +++++---- test/simple/parallel_w8.c | 159 ++--- test/simple/pinterlib.c | 112 ++- test/simple/pmix.c | 57 +- test/simple/pubsub.c | 8 +- test/simple/reduce-hang.c | 4 +- test/simple/ring.c | 17 +- test/simple/segv.c | 6 +- test/simple/sendrecv_blaster.c | 127 ++-- test/simple/server.c | 83 ++- test/simple/simple_spawn.c | 17 +- test/simple/singleton_client_server.c | 274 ++++---- test/simple/sio.c | 6 +- test/simple/slave.c | 6 +- test/simple/spawn-problem/ch_rec.c | 84 ++- test/simple/spawn-problem/start.c | 39 +- test/simple/spawn_multiple.c | 20 +- test/simple/spawn_tree.c | 34 +- test/simple/thread_init.c | 16 +- test/simple/xlib.c | 57 +- test/simple/ziaprobe.c | 36 +- test/simple/ziatest.c | 14 +- test/spc/spc_test.c | 69 +- test/support/support.c | 28 +- test/support/support.h | 32 +- test/threads/opal_atomic_thread_bench.c | 205 +++--- test/threads/opal_condition.c | 27 +- test/threads/opal_thread.c | 14 +- test/util/bipartite_graph.c | 331 ++++----- test/util/ompi_numtostr.c | 23 +- test/util/opal_argv.c | 628 ++++++++--------- test/util/opal_basename.c | 40 +- test/util/opal_bit_ops.c | 107 +-- test/util/opal_error.c | 33 +- test/util/opal_if.c | 21 +- test/util/opal_os_create_dirpath.c | 59 +- test/util/opal_os_path.c | 74 +- test/util/opal_path_nfs.c | 124 ++-- test/util/opal_timer.c | 8 +- test/util/orte_session_dir.c | 174 +++-- test/util/orte_universe_setup_file_io.c | 40 +- 144 files changed, 7386 insertions(+), 7604 deletions(-) diff --git a/examples/connectivity_c.c b/examples/connectivity_c.c index 14f3f546d5..a4fac9e7c2 100644 --- a/examples/connectivity_c.c +++ b/examples/connectivity_c.c @@ -7,25 +7,24 @@ */ #include <errno.h> +#include <mpi.h> +#include <netdb.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <netdb.h> #include <unistd.h> -#include <mpi.h> -int -main(int argc, char **argv) +int main(int argc, char **argv) { - MPI_Status status; - int verbose = 0; - int rank; - int np; /* number of processes in job */ - int peer; - int i; - int j; - int length; - char name[MPI_MAX_PROCESSOR_NAME+1]; + MPI_Status status; + int verbose = 0; + int rank; + int np; /* number of processes in job */ + int peer; + int i; + int j; + int length; + char name[MPI_MAX_PROCESSOR_NAME + 1]; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -38,20 +37,19 @@ main(int argc, char **argv) strcpy(name, "unknown"); } - if (argc>1 && strcmp(argv[1], "-v")==0) + if (argc > 1 && strcmp(argv[1], "-v") == 0) verbose = 1; - for (i=0; i<np; i++) { - if (rank==i) { + for (i = 0; i < np; i++) { + if (rank == i) { /* rank i sends to and receives from each higher rank */ - for(j=i+1; j<np; j++) { + for (j = i + 1; j < np; j++) { if (verbose) - printf("checking connection between rank %d on %s and rank %-4d\n", - i, name, j); + printf("checking connection between rank %d on %s and rank %-4d\n", i, name, j); MPI_Send(&rank, 1, MPI_INT, j, rank, MPI_COMM_WORLD); MPI_Recv(&peer, 1, MPI_INT, j, j, MPI_COMM_WORLD, &status); } - } else if (rank>i) { + } else if (rank > i) { /* receive from and reply to rank i */ MPI_Recv(&peer, 1, MPI_INT, i, i, MPI_COMM_WORLD, &status); MPI_Send(&rank, 1, MPI_INT, i, rank, MPI_COMM_WORLD); @@ -59,7 +57,7 @@ main(int argc, char **argv) } MPI_Barrier(MPI_COMM_WORLD); - if (rank==0) + if (rank == 0) printf("Connectivity test on %d processes PASSED.\n", np); MPI_Finalize(); diff --git a/examples/dtrace/mpicommleak.c b/examples/dtrace/mpicommleak.c index b2fcb8a25c..2a5c737ab0 100644 --- a/examples/dtrace/mpicommleak.c +++ b/examples/dtrace/mpicommleak.c @@ -9,10 +9,10 @@ */ #include <errno.h> +#include <netdb.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <netdb.h> #include <unistd.h> #include <mpi.h> @@ -23,39 +23,40 @@ static void allocate_comms(void); static void deallocate_comms(void); static MPI_Comm communicator_a, communicator_b, communicator_c; -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - int rank; /* COMM_WORLD rank of process */ - int np; /* number of processes in job */ - int i; - int unslept; + int rank; /* COMM_WORLD rank of process */ + int np; /* number of processes in job */ + int i; + int unslept; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &np); - for (i=0; i < ITERATIONS; i++) { - /* allocate our communicators */ - allocate_comms(); + for (i = 0; i < ITERATIONS; i++) { + /* allocate our communicators */ + allocate_comms(); - /* simulate doing work */ - unslept = sleep(5); + /* simulate doing work */ + unslept = sleep(5); - /* deallocate communicators forgetting one of the communicators */ - deallocate_comms(); + /* deallocate communicators forgetting one of the communicators */ + deallocate_comms(); } MPI_Finalize(); return 0; } -void allocate_comms(void) { +void allocate_comms(void) +{ MPI_Comm_dup(MPI_COMM_WORLD, &communicator_a); MPI_Comm_dup(MPI_COMM_WORLD, &communicator_b); MPI_Comm_dup(MPI_COMM_WORLD, &communicator_c); } -void deallocate_comms(void) { +void deallocate_comms(void) +{ MPI_Comm_free(&communicator_a); MPI_Comm_free(&communicator_c); } diff --git a/examples/hello_c.c b/examples/hello_c.c index e44f684370..ba30e16706 100644 --- a/examples/hello_c.c +++ b/examples/hello_c.c @@ -7,10 +7,10 @@ * Sample MPI "hello world" application in C */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size, len; char version[MPI_MAX_LIBRARY_VERSION_STRING]; @@ -19,8 +19,7 @@ int main(int argc, char* argv[]) MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); MPI_Get_library_version(version, &len); - printf("Hello, world, I am %d of %d, (%s, %d)\n", - rank, size, version, len); + printf("Hello, world, I am %d of %d, (%s, %d)\n", rank, size, version, len); MPI_Finalize(); return 0; diff --git a/examples/hello_oshmem_c.c b/examples/hello_oshmem_c.c index 6bb0d08c06..a485e2e99d 100644 --- a/examples/hello_oshmem_c.c +++ b/examples/hello_oshmem_c.c @@ -9,14 +9,14 @@ * $HEADER$ */ -#include <stdio.h> #include "shmem.h" +#include <stdio.h> #if !defined(OSHMEM_SPEC_VERSION) || OSHMEM_SPEC_VERSION < 10200 -#error This application uses API 1.2 and up +# error This application uses API 1.2 and up #endif -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int proc, nproc; char name[SHMEM_MAX_NAME_LEN]; @@ -28,8 +28,7 @@ int main(int argc, char* argv[]) shmem_info_get_name(name); shmem_info_get_version(&major, &minor); - printf("Hello, world, I am %d of %d: %s (version: %d.%d)\n", - proc, nproc, name, major, minor); + printf("Hello, world, I am %d of %d: %s (version: %d.%d)\n", proc, nproc, name, major, minor); shmem_finalize(); return 0; diff --git a/examples/oshmem_circular_shift.c b/examples/oshmem_circular_shift.c index 3ff2d6d0c8..1cc26466da 100644 --- a/examples/oshmem_circular_shift.c +++ b/examples/oshmem_circular_shift.c @@ -8,10 +8,10 @@ * $HEADER$ */ -#include <stdio.h> #include <shmem.h> +#include <stdio.h> -int main (void) +int main(void) { static int aaa, bbb; int num_pes, my_pe, peer; @@ -32,4 +32,3 @@ int main (void) return 0; } - diff --git a/examples/oshmem_max_reduction.c b/examples/oshmem_max_reduction.c index d0dec673af..c9bef246d1 100644 --- a/examples/oshmem_max_reduction.c +++ b/examples/oshmem_max_reduction.c @@ -23,7 +23,7 @@ long src[N]; long dst[N]; long pWrk[_SHMEM_REDUCE_SYNC_SIZE]; -int main(void) +int main(void) { int i; int my_pe, num_pes; @@ -47,7 +47,7 @@ int main(void) printf("%d/%d dst =", my_pe, num_pes); - for (i = 0; i < N; i+= 1) { + for (i = 0; i < N; i += 1) { printf(" %ld", dst[i]); } @@ -56,4 +56,3 @@ int main(void) return 0; } - diff --git a/examples/oshmem_shmalloc.c b/examples/oshmem_shmalloc.c index e5f9ab9090..aac04d9ac9 100644 --- a/examples/oshmem_shmalloc.c +++ b/examples/oshmem_shmalloc.c @@ -27,4 +27,3 @@ int main(void) shmem_finalize(); } - diff --git a/examples/oshmem_strided_puts.c b/examples/oshmem_strided_puts.c index e9f31ddb74..ea547c6a66 100644 --- a/examples/oshmem_strided_puts.c +++ b/examples/oshmem_strided_puts.c @@ -24,12 +24,12 @@ * */ -#include <stdio.h> #include <shmem.h> +#include <stdio.h> int main(void) { - short source[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + short source[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; static short target[10]; int me; @@ -44,9 +44,8 @@ int main(void) shmem_barrier_all(); /* sync sender and receiver */ if (me == 1) { - printf("target on PE %d is %hd %hd %hd %hd %hd\n", me, - target[0], target[1], target[2], - target[3], target[4] ); + printf("target on PE %d is %hd %hd %hd %hd %hd\n", me, target[0], target[1], target[2], + target[3], target[4]); } shmem_barrier_all(); /* sync before exiting */ shmem_finalize(); diff --git a/examples/oshmem_symmetric_data.c b/examples/oshmem_symmetric_data.c index 7c5a1db6b5..42155aa06b 100644 --- a/examples/oshmem_symmetric_data.c +++ b/examples/oshmem_symmetric_data.c @@ -8,12 +8,12 @@ * $HEADER$ */ -#include <stdio.h> #include <shmem.h> +#include <stdio.h> #define SIZE 16 -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { short source[SIZE]; static short target[SIZE]; @@ -27,13 +27,13 @@ int main(int argc, char* argv[]) if (my_pe == 0) { /* initialize array */ - for(i = 0; i < SIZE; i++) { + for (i = 0; i < SIZE; i++) { source[i] = i; } /* local, not symmetric */ /* static makes it symmetric */ /* put "size" words into target on each PE */ - for(i = 1; i < num_pe; i++) { + for (i = 1; i < num_pe; i++) { shmem_short_put(target, source, SIZE, i); } } @@ -43,7 +43,7 @@ int main(int argc, char* argv[]) if (my_pe != 0) { printf("Target on PE %d is \t", my_pe); - for(i = 0; i < SIZE; i++) { + for (i = 0; i < SIZE; i++) { printf("%hd \t", target[i]); } printf("\n"); diff --git a/examples/ring_c.c b/examples/ring_c.c index 86c205b3d2..8551e4f701 100644 --- a/examples/ring_c.c +++ b/examples/ring_c.c @@ -7,8 +7,8 @@ * Simple ring test program in C. */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> int main(int argc, char *argv[]) { @@ -34,8 +34,8 @@ int main(int argc, char *argv[]) if (0 == rank) { message = 10; - printf("Process 0 sending %d to %d, tag %d (%d processes in ring)\n", - message, next, tag, size); + printf("Process 0 sending %d to %d, tag %d (%d processes in ring)\n", message, next, tag, + size); MPI_Send(&message, 1, MPI_INT, next, tag, MPI_COMM_WORLD); printf("Process 0 sent to %d\n", next); } @@ -49,8 +49,7 @@ int main(int argc, char *argv[]) and can quit normally. */ while (1) { - MPI_Recv(&message, 1, MPI_INT, prev, tag, MPI_COMM_WORLD, - MPI_STATUS_IGNORE); + MPI_Recv(&message, 1, MPI_INT, prev, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); if (0 == rank) { --message; @@ -68,8 +67,7 @@ int main(int argc, char *argv[]) to be received before the program can exit */ if (0 == rank) { - MPI_Recv(&message, 1, MPI_INT, prev, tag, MPI_COMM_WORLD, - MPI_STATUS_IGNORE); + MPI_Recv(&message, 1, MPI_INT, prev, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } /* All done */ diff --git a/examples/ring_oshmem_c.c b/examples/ring_oshmem_c.c index 5fe1c7f65d..17ba57d326 100644 --- a/examples/ring_oshmem_c.c +++ b/examples/ring_oshmem_c.c @@ -12,10 +12,10 @@ #include <stdio.h> #if !defined(OSHMEM_SPEC_VERSION) || OSHMEM_SPEC_VERSION < 10200 -#error This application uses API 1.2 and up +# error This application uses API 1.2 and up #endif -int main (int argc, char * argv[]) +int main(int argc, char *argv[]) { static int rbuf = -1; int proc, nproc, next; @@ -30,8 +30,7 @@ int main (int argc, char * argv[]) next = (proc + 1) % nproc; - if(proc == 0) - { + if (proc == 0) { printf("Process 0 puts message %d to %d (%d processes in ring)\n", message, next, nproc); shmem_int_put(&rbuf, &message, 1, next); } @@ -44,14 +43,14 @@ int main (int argc, char * argv[]) message first, every process gets the 0 message and can quit normally. */ - while(message > 0) { + while (message > 0) { shmem_int_wait_until(&rbuf, SHMEM_CMP_EQ, message); - if(proc == 0) { + if (proc == 0) { --message; printf("Process 0 decremented value: %d\n", message); } shmem_int_put(&rbuf, &message, 1, next); - if(proc != 0) { + if (proc != 0) { --message; } } diff --git a/examples/spc_example.c b/examples/spc_example.c index ba0bb38996..927773ccc0 100644 --- a/examples/spc_example.c +++ b/examples/spc_example.c @@ -19,16 +19,16 @@ void message_exchange(int num_messages, int message_size) { int i, rank; /* Use calloc to initialize data to 0's */ - char *data = (char*)calloc(message_size, sizeof(char)); + char *data = (char *) calloc(message_size, sizeof(char)); MPI_Status status; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if(rank == 0) { - for(i = 0; i < num_messages; i++) + if (rank == 0) { + for (i = 0; i < num_messages; i++) MPI_Send(data, message_size, MPI_BYTE, 1, 123, MPI_COMM_WORLD); - } else if(rank == 1) { - for(i = 0; i < num_messages; i++) + } else if (rank == 1) { + for (i = 0; i < num_messages; i++) MPI_Recv(data, message_size, MPI_BYTE, 0, 123, MPI_COMM_WORLD, &status); } @@ -39,15 +39,17 @@ int main(int argc, char **argv) { int num_messages, message_size, rc; - if(argc < 3) { - printf("Usage: mpirun -np 2 --mca mpi_spc_attach all --mca mpi_spc_dump_enabled true ./spc_example [num_messages] [message_size]\n"); + if (argc < 3) { + printf("Usage: mpirun -np 2 --mca mpi_spc_attach all --mca mpi_spc_dump_enabled true " + "./spc_example [num_messages] [message_size]\n"); return -1; } else { num_messages = atoi(argv[1]); message_size = atoi(argv[2]); } - int i, rank, size, provided, num, name_len, desc_len, verbosity, bind, var_class, readonly, continuous, atomic, count, index; + int i, rank, size, provided, num, name_len, desc_len, verbosity, bind, var_class, readonly, + continuous, atomic, count, index; MPI_Datatype datatype; MPI_T_enum enumtype; MPI_Comm comm; @@ -56,14 +58,14 @@ int main(int argc, char **argv) /* Counter names to be read by ranks 0 and 1 */ /* (See also: ompi_spc_counters_t for list) */ char *counter_names[] = {"runtime_spc_OMPI_SPC_BYTES_SENT_USER", - "runtime_spc_OMPI_SPC_BYTES_RECEIVED_USER" }; + "runtime_spc_OMPI_SPC_BYTES_RECEIVED_USER"}; MPI_Init(NULL, NULL); MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - if(size != 2) { + if (size != 2) { fprintf(stderr, "ERROR: This test should be run with two MPI processes.\n"); MPI_Abort(MPI_COMM_WORLD, -1); } @@ -71,21 +73,20 @@ int main(int argc, char **argv) /* Determine the MPI_T pvar indices for the OMPI_BYTES_SENT/RECIEVED_USER SPCs */ index = -1; MPI_T_pvar_get_num(&num); - for(i = 0; i < num; i++) { + for (i = 0; i < num; i++) { name_len = desc_len = 256; - rc = PMPI_T_pvar_get_info(i, name, &name_len, &verbosity, - &var_class, &datatype, &enumtype, description, &desc_len, &bind, - &readonly, &continuous, &atomic); - if( MPI_SUCCESS != rc ) + rc = PMPI_T_pvar_get_info(i, name, &name_len, &verbosity, &var_class, &datatype, &enumtype, + description, &desc_len, &bind, &readonly, &continuous, &atomic); + if (MPI_SUCCESS != rc) continue; - if(strcmp(name, counter_names[rank]) == 0) { + if (strcmp(name, counter_names[rank]) == 0) { index = i; printf("[%d] %s -> %s\n", rank, name, description); } } /* Make sure we found the counters */ - if(index == -1) { + if (index == -1) { fprintf(stderr, "ERROR: Couldn't find the appropriate SPC counter in the MPI_T pvars.\n"); MPI_Abort(MPI_COMM_WORLD, -1); } @@ -104,8 +105,8 @@ int main(int argc, char **argv) ret = MPI_T_pvar_read(session, handle, &value); /* Print the counter values in order by rank */ - for(i = 0; i < 2; i++) { - if(i == rank) { + for (i = 0; i < 2; i++) { + if (i == rank) { printf("[%d] Value Read: %lld\n", rank, value); fflush(stdout); } diff --git a/test/asm/atomic_barrier.c b/test/asm/atomic_barrier.c index 3542ba74cf..065e116a28 100644 --- a/test/asm/atomic_barrier.c +++ b/test/asm/atomic_barrier.c @@ -22,8 +22,7 @@ #include "opal/sys/atomic.h" -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { #if OPAL_HAVE_ATOMIC_MEM_BARRIER @@ -40,4 +39,3 @@ main(int argc, char *argv[]) return 77; #endif } - diff --git a/test/asm/atomic_cmpset.c b/test/asm/atomic_cmpset.c index 59f53403ea..8a948608bf 100644 --- a/test/asm/atomic_cmpset.c +++ b/test/asm/atomic_cmpset.c @@ -30,7 +30,7 @@ #include <assert.h> #ifdef HAVE_PTHREAD_H -#include <pthread.h> +# include <pthread.h> #endif #include <stdarg.h> #include <stdio.h> @@ -39,7 +39,6 @@ #include "opal/sys/atomic.h" - /* default options */ int nreps = 100; int nthreads = 2; @@ -71,7 +70,6 @@ opal_atomic_intptr_t volptr = 0; intptr_t oldptr = 0; intptr_t newptr = 0; - static void *thread_main(void *arg) { int rank = (int) (unsigned long) arg; @@ -82,7 +80,7 @@ static void *thread_main(void *arg) for (i = 0; i < nreps; i++) { opal_atomic_add_fetch_32(&val32, 5); opal_atomic_add_fetch_64(&val64, 5); - opal_atomic_add (&valint, 5); + opal_atomic_add(&valint, 5); } return (void *) (unsigned long) (rank + 1000); @@ -99,41 +97,40 @@ int main(int argc, char *argv[]) } nthreads = atoi(argv[1]); - /* first test single-threaded functionality */ /* -- cmpset 32-bit tests -- */ vol32 = 42, old32 = 42, new32 = 50; - assert(opal_atomic_compare_exchange_strong_32 (&vol32, &old32, new32) == true); + assert(opal_atomic_compare_exchange_strong_32(&vol32, &old32, new32) == true); opal_atomic_rmb(); assert(vol32 == new32); assert(old32 == 42); vol32 = 42, old32 = 420, new32 = 50; - assert(opal_atomic_compare_exchange_strong_32 (&vol32, &old32, new32) == false); + assert(opal_atomic_compare_exchange_strong_32(&vol32, &old32, new32) == false); opal_atomic_rmb(); assert(vol32 == 42); assert(old32 == 42); vol32 = 42, old32 = 42, new32 = 50; - assert(opal_atomic_compare_exchange_strong_32 (&vol32, &old32, new32) == true); + assert(opal_atomic_compare_exchange_strong_32(&vol32, &old32, new32) == true); assert(vol32 == new32); assert(old32 == 42); vol32 = 42, old32 = 420, new32 = 50; - assert(opal_atomic_compare_exchange_strong_acq_32 (&vol32, &old32, new32) == false); + assert(opal_atomic_compare_exchange_strong_acq_32(&vol32, &old32, new32) == false); assert(vol32 == 42); assert(old32 == 42); vol32 = 42, old32 = 42, new32 = 50; - assert(opal_atomic_compare_exchange_strong_rel_32 (&vol32, &old32, new32) == true); + assert(opal_atomic_compare_exchange_strong_rel_32(&vol32, &old32, new32) == true); opal_atomic_rmb(); assert(vol32 == new32); assert(old32 == 42); vol32 = 42, old32 = 420, new32 = 50; - assert(opal_atomic_compare_exchange_strong_rel_32 (&vol32, &old32, new32) == false); + assert(opal_atomic_compare_exchange_strong_rel_32(&vol32, &old32, new32) == false); opal_atomic_rmb(); assert(vol32 == 42); assert(old32 == 42); @@ -141,35 +138,35 @@ int main(int argc, char *argv[]) /* -- cmpset 64-bit tests -- */ vol64 = 42, old64 = 42, new64 = 50; - assert(opal_atomic_compare_exchange_strong_64 (&vol64, &old64, new64) == true); + assert(opal_atomic_compare_exchange_strong_64(&vol64, &old64, new64) == true); opal_atomic_rmb(); assert(new64 == vol64); assert(old64 == 42); vol64 = 42, old64 = 420, new64 = 50; - assert(opal_atomic_compare_exchange_strong_64 (&vol64, &old64, new64) == false); + assert(opal_atomic_compare_exchange_strong_64(&vol64, &old64, new64) == false); opal_atomic_rmb(); assert(vol64 == 42); assert(old64 == 42); vol64 = 42, old64 = 42, new64 = 50; - assert(opal_atomic_compare_exchange_strong_acq_64 (&vol64, &old64, new64) == true); + assert(opal_atomic_compare_exchange_strong_acq_64(&vol64, &old64, new64) == true); assert(vol64 == new64); assert(old64 == 42); vol64 = 42, old64 = 420, new64 = 50; - assert(opal_atomic_compare_exchange_strong_acq_64 (&vol64, &old64, new64) == false); + assert(opal_atomic_compare_exchange_strong_acq_64(&vol64, &old64, new64) == false); assert(vol64 == 42); assert(old64 == 42); vol64 = 42, old64 = 42, new64 = 50; - assert(opal_atomic_compare_exchange_strong_rel_64 (&vol64, &old64, new64) == true); + assert(opal_atomic_compare_exchange_strong_rel_64(&vol64, &old64, new64) == true); opal_atomic_rmb(); assert(vol64 == new64); assert(old64 == 42); vol64 = 42, old64 = 420, new64 = 50; - assert(opal_atomic_compare_exchange_strong_rel_64 (&vol64, &old64, new64) == false); + assert(opal_atomic_compare_exchange_strong_rel_64(&vol64, &old64, new64) == false); opal_atomic_rmb(); assert(vol64 == 42); assert(old64 == 42); @@ -178,13 +175,13 @@ int main(int argc, char *argv[]) #if OPAL_HAVE_ATOMIC_COMPARE_EXCHANGE_128 vol128 = 42, old128 = 42, new128 = 50; - assert(opal_atomic_compare_exchange_strong_128 (&vol128, &old128, new128) == true); + assert(opal_atomic_compare_exchange_strong_128(&vol128, &old128, new128) == true); opal_atomic_rmb(); assert(new128 == vol128); assert(old128 == 42); vol128 = 42, old128 = 420, new128 = 50; - assert(opal_atomic_compare_exchange_strong_128 (&vol128, &old128, new128) == false); + assert(opal_atomic_compare_exchange_strong_128(&vol128, &old128, new128) == false); opal_atomic_rmb(); assert(vol128 == 42); assert(old128 == 42); @@ -193,72 +190,71 @@ int main(int argc, char *argv[]) /* -- cmpset int tests -- */ volint = 42, oldint = 42, newint = 50; - assert(opal_atomic_compare_exchange_strong (&volint, &oldint, newint) == true); + assert(opal_atomic_compare_exchange_strong(&volint, &oldint, newint) == true); opal_atomic_rmb(); assert(volint == newint); assert(oldint == 42); volint = 42, oldint = 420, newint = 50; - assert(opal_atomic_compare_exchange_strong (&volint, &oldint, newint) == false); + assert(opal_atomic_compare_exchange_strong(&volint, &oldint, newint) == false); opal_atomic_rmb(); assert(volint == 42); assert(oldint == 42); volint = 42, oldint = 42, newint = 50; - assert(opal_atomic_compare_exchange_strong_acq (&volint, &oldint, newint) == true); + assert(opal_atomic_compare_exchange_strong_acq(&volint, &oldint, newint) == true); assert(volint == newint); assert(oldint == 42); volint = 42, oldint = 420, newint = 50; - assert(opal_atomic_compare_exchange_strong_acq (&volint, &oldint, newint) == false); + assert(opal_atomic_compare_exchange_strong_acq(&volint, &oldint, newint) == false); assert(volint == 42); assert(oldint == 42); volint = 42, oldint = 42, newint = 50; - assert(opal_atomic_compare_exchange_strong_rel (&volint, &oldint, newint) == true); + assert(opal_atomic_compare_exchange_strong_rel(&volint, &oldint, newint) == true); opal_atomic_rmb(); assert(volint == newint); assert(oldint == 42); volint = 42, oldint = 420, newint = 50; - assert(opal_atomic_compare_exchange_strong_rel (&volint, &oldint, newint) == false); + assert(opal_atomic_compare_exchange_strong_rel(&volint, &oldint, newint) == false); opal_atomic_rmb(); assert(volint == 42); assert(oldint == 42); - /* -- cmpset ptr tests -- */ volptr = 42, oldptr = 42, newptr = 50; - assert(opal_atomic_compare_exchange_strong_ptr (&volptr, &oldptr, newptr) == true); + assert(opal_atomic_compare_exchange_strong_ptr(&volptr, &oldptr, newptr) == true); opal_atomic_rmb(); assert(volptr == newptr); assert(oldptr == 42); volptr = 42, oldptr = 420, newptr = 50; - assert(opal_atomic_compare_exchange_strong_ptr (&volptr, &oldptr, newptr) == false); + assert(opal_atomic_compare_exchange_strong_ptr(&volptr, &oldptr, newptr) == false); opal_atomic_rmb(); assert(volptr == 42); assert(oldptr == 42); volptr = 42, oldptr = 42, newptr = 50; - assert(opal_atomic_compare_exchange_strong_acq_ptr (&volptr, &oldptr, newptr) == true); + assert(opal_atomic_compare_exchange_strong_acq_ptr(&volptr, &oldptr, newptr) == true); assert(volptr == newptr); assert(oldptr == 42); volptr = 42, oldptr = 420, newptr = 50; - assert(opal_atomic_compare_exchange_strong_acq_ptr (&volptr, &oldptr, newptr) == false); + assert(opal_atomic_compare_exchange_strong_acq_ptr(&volptr, &oldptr, newptr) == false); assert(volptr == 42); assert(oldptr == 42); volptr = 42, oldptr = 42, newptr = 50; - assert(opal_atomic_compare_exchange_strong_rel_ptr (&volptr, &oldptr, newptr) == true); + assert(opal_atomic_compare_exchange_strong_rel_ptr(&volptr, &oldptr, newptr) == true); opal_atomic_rmb(); assert(volptr == newptr); assert(oldptr == 42); volptr = 42, oldptr = 420, newptr = 50; - assert(opal_atomic_compare_exchange_strong_rel_ptr (&volptr, &oldptr, newptr) == false); + assert(opal_atomic_compare_exchange_strong_rel_ptr(&volptr, &oldptr, newptr) == false); opal_atomic_rmb(); assert(volptr == 42); assert(oldptr == 42); @@ -278,11 +274,10 @@ int main(int argc, char *argv[]) /* -- add_int tests -- */ valint = 42; - opal_atomic_add (&valint, 5); + opal_atomic_add(&valint, 5); opal_atomic_rmb(); assert((42 + 5) == valint); - /* threaded tests */ val32 = 0; @@ -317,7 +312,7 @@ int main(int argc, char *argv[]) opal_atomic_rmb(); assert((5 * nthreads * nreps) == val32); opal_atomic_rmb(); - assert((5 * nthreads * nreps) == val64); + assert((5 * nthreads * nreps) == val64); opal_atomic_rmb(); assert((5 * nthreads * nreps) == valint); diff --git a/test/asm/atomic_math.c b/test/asm/atomic_math.c index 4992c3a43a..864d7a2a4d 100644 --- a/test/asm/atomic_math.c +++ b/test/asm/atomic_math.c @@ -23,10 +23,10 @@ #include "opal_config.h" #ifdef HAVE_PTHREAD_H -#include <pthread.h> +# include <pthread.h> #endif -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include "opal/sys/atomic.h" @@ -36,23 +36,21 @@ opal_atomic_int32_t val32 = 0; opal_atomic_int64_t val64 = 0; opal_atomic_int_t valint = 0; -static void* atomic_math_test(void* arg) +static void *atomic_math_test(void *arg) { - int count = *((int*) arg); + int count = *((int *) arg); int i; - for (i = 0 ; i < count ; ++i) { - (void)opal_atomic_add_fetch_32(&val32, 5); - (void)opal_atomic_add_fetch_64(&val64, 6); - opal_atomic_add (&valint, 4); + for (i = 0; i < count; ++i) { + (void) opal_atomic_add_fetch_32(&val32, 5); + (void) opal_atomic_add_fetch_64(&val64, 6); + opal_atomic_add(&valint, 4); } return NULL; } - -static int -atomic_math_test_th(int count, int thr_count) +static int atomic_math_test_th(int count, int thr_count) { int value; pthread_t *th; @@ -71,8 +69,7 @@ atomic_math_test_th(int count, int thr_count) disappearing before the threads start. */ value = count; for (tid = 0; tid < thr_count; tid++) { - if (pthread_create(&th[tid], NULL, atomic_math_test, - (void*) &value) != 0) { + if (pthread_create(&th[tid], NULL, atomic_math_test, (void *) &value) != 0) { perror("pthread_create"); exit(EXIT_FAILURE); } @@ -92,9 +89,7 @@ atomic_math_test_th(int count, int thr_count) return 0; } - -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int32_t test32; int64_t test64; @@ -107,142 +102,169 @@ main(int argc, char *argv[]) } num_threads = atoi(argv[1]); - test32 = opal_atomic_add_fetch_32 (&val32, 17); + test32 = opal_atomic_add_fetch_32(&val32, 17); if (test32 != 17 || val32 != 17) { - fprintf (stderr, "error in opal_atomic_add_fetch_32. expected (17, 17), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_add_fetch_32. expected (17, 17), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - test32 = opal_atomic_fetch_add_32 (&val32, 13); + test32 = opal_atomic_fetch_add_32(&val32, 13); if (test32 != 17 || val32 != 30) { - fprintf (stderr, "error in opal_atomic_fetch_add_32. expected (17, 30), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_fetch_add_32. expected (17, 30), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - - - test32 = opal_atomic_and_fetch_32 (&val32, 0x18); + test32 = opal_atomic_and_fetch_32(&val32, 0x18); if (test32 != 24 || val32 != 24) { - fprintf (stderr, "error in opal_atomic_and_fetch_32. expected (24, 24), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_and_fetch_32. expected (24, 24), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - test32 = opal_atomic_fetch_and_32 (&val32, 0x10); + test32 = opal_atomic_fetch_and_32(&val32, 0x10); if (test32 != 24 || val32 != 16) { - fprintf (stderr, "error in opal_atomic_fetch_and_32. expected (24, 16), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_fetch_and_32. expected (24, 16), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - - - test32 = opal_atomic_or_fetch_32 (&val32, 0x03); + test32 = opal_atomic_or_fetch_32(&val32, 0x03); if (test32 != 19 || val32 != 19) { - fprintf (stderr, "error in opal_atomic_or_fetch_32. expected (19, 19), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_or_fetch_32. expected (19, 19), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - test32 = opal_atomic_fetch_or_32 (&val32, 0x04); + test32 = opal_atomic_fetch_or_32(&val32, 0x04); if (test32 != 19 || val32 != 23) { - fprintf (stderr, "error in opal_atomic_fetch_or_32. expected (19, 23), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_fetch_or_32. expected (19, 23), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - - test32 = opal_atomic_xor_fetch_32 (&val32, 0x03); + test32 = opal_atomic_xor_fetch_32(&val32, 0x03); if (test32 != 20 || val32 != 20) { - fprintf (stderr, "error in opal_atomic_xor_fetch_32. expected (20, 20), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_xor_fetch_32. expected (20, 20), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - test32 = opal_atomic_fetch_xor_32 (&val32, 0x05); + test32 = opal_atomic_fetch_xor_32(&val32, 0x05); if (test32 != 20 || val32 != 17) { - fprintf (stderr, "error in opal_atomic_fetch_xor_32. expected (20, 17), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_fetch_xor_32. expected (20, 17), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - - - test32 = opal_atomic_sub_fetch_32 (&val32, 14); + test32 = opal_atomic_sub_fetch_32(&val32, 14); if (test32 != 3 || val32 != 3) { - fprintf (stderr, "error in opal_atomic_sub_fetch_32. expected (3, 3), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_sub_fetch_32. expected (3, 3), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - test32 = opal_atomic_fetch_xor_32 (&val32, 3); + test32 = opal_atomic_fetch_xor_32(&val32, 3); if (test32 != 3 || val32 != 0) { - fprintf (stderr, "error in opal_atomic_fetch_sub_32. expected (3, 0), got (%d, %d)\n", test32, val32); + fprintf(stderr, "error in opal_atomic_fetch_sub_32. expected (3, 0), got (%d, %d)\n", + test32, val32); exit(EXIT_FAILURE); } - test64 = opal_atomic_add_fetch_64 (&val64, 17); + test64 = opal_atomic_add_fetch_64(&val64, 17); if (test64 != 17 || val64 != 17) { - fprintf (stderr, "error in opal_atomic_add_fetch_64. expected (17, 17), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_add_fetch_64. expected (17, 17), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - test64 = opal_atomic_fetch_add_64 (&val64, 13); + test64 = opal_atomic_fetch_add_64(&val64, 13); if (test64 != 17 || val64 != 30) { - fprintf (stderr, "error in opal_atomic_fetch_add_64. expected (17, 30), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_fetch_add_64. expected (17, 30), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - - - test64 = opal_atomic_and_fetch_64 (&val64, 0x18); + test64 = opal_atomic_and_fetch_64(&val64, 0x18); if (test64 != 24 || val64 != 24) { - fprintf (stderr, "error in opal_atomic_and_fetch_64. expected (24, 24), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_and_fetch_64. expected (24, 24), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - test64 = opal_atomic_fetch_and_64 (&val64, 0x10); + test64 = opal_atomic_fetch_and_64(&val64, 0x10); if (test64 != 24 || val64 != 16) { - fprintf (stderr, "error in opal_atomic_fetch_and_64. expected (24, 16), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_fetch_and_64. expected (24, 16), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - - - test64 = opal_atomic_or_fetch_64 (&val64, 0x03); + test64 = opal_atomic_or_fetch_64(&val64, 0x03); if (test64 != 19 || val64 != 19) { - fprintf (stderr, "error in opal_atomic_or_fetch_64. expected (19, 19), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_or_fetch_64. expected (19, 19), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - test64 = opal_atomic_fetch_or_64 (&val64, 0x04); + test64 = opal_atomic_fetch_or_64(&val64, 0x04); if (test64 != 19 || val64 != 23) { - fprintf (stderr, "error in opal_atomic_fetch_or_64. expected (19, 23), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_fetch_or_64. expected (19, 23), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - - test64 = opal_atomic_xor_fetch_64 (&val64, 0x03); + test64 = opal_atomic_xor_fetch_64(&val64, 0x03); if (test64 != 20 || val64 != 20) { - fprintf (stderr, "error in opal_atomic_xor_fetch_64. expected (20, 20), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_xor_fetch_64. expected (20, 20), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - test64 = opal_atomic_fetch_xor_64 (&val64, 0x05); + test64 = opal_atomic_fetch_xor_64(&val64, 0x05); if (test64 != 20 || val64 != 17) { - fprintf (stderr, "error in opal_atomic_fetch_xor_64. expected (20, 17), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_fetch_xor_64. expected (20, 17), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - - - test64 = opal_atomic_sub_fetch_64 (&val64, 14); + test64 = opal_atomic_sub_fetch_64(&val64, 14); if (test64 != 3 || val64 != 3) { - fprintf (stderr, "error in opal_atomic_sub_fetch_64. expected (3, 3), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_sub_fetch_64. expected (3, 3), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } - test64 = opal_atomic_fetch_xor_64 (&val64, 3); + test64 = opal_atomic_fetch_xor_64(&val64, 3); if (test64 != 3 || val64 != 0) { - fprintf (stderr, "error in opal_atomic_fetch_sub_64. expected (3, 0), got (%" PRId64 ", %" PRId64 ")\n", test64, val64); + fprintf(stderr, + "error in opal_atomic_fetch_sub_64. expected (3, 0), got (%" PRId64 ", %" PRId64 + ")\n", + test64, val64); exit(EXIT_FAILURE); } ret = atomic_math_test_th(TEST_REPS, num_threads); - if (ret == 77) return ret; + if (ret == 77) + return ret; opal_atomic_mb(); if (val32 != TEST_REPS * num_threads * 5) { printf("opal_atomic_add_fetch32 failed. Expected %d, got %d.\n", diff --git a/test/asm/atomic_spinlock.c b/test/asm/atomic_spinlock.c index a6c68b134d..f918f3637b 100644 --- a/test/asm/atomic_spinlock.c +++ b/test/asm/atomic_spinlock.c @@ -23,10 +23,10 @@ #include "opal_config.h" #ifdef HAVE_PTHREAD_H -#include <pthread.h> +# include <pthread.h> #endif -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include "opal/sys/atomic.h" @@ -42,25 +42,29 @@ struct start_info { static int atomic_spinlock_test(opal_atomic_lock_t *lock, int count, int id); -static void* atomic_spinlock_start(void* arg) +static void *atomic_spinlock_start(void *arg) { - struct start_info *data = (struct start_info*) arg; + struct start_info *data = (struct start_info *) arg; - return (void*) (unsigned long) atomic_spinlock_test(data->lock, data->count, - data->tid); + return (void *) (unsigned long) atomic_spinlock_test(data->lock, data->count, data->tid); } -static int -atomic_spinlock_test_th(opal_atomic_lock_t *lock, int count, int id, int thr_count) +static int atomic_spinlock_test_th(opal_atomic_lock_t *lock, int count, int id, int thr_count) { pthread_t *th; int tid, ret = 0; struct start_info *data; th = (pthread_t *) malloc(thr_count * sizeof(pthread_t)); - if (!th) { perror("malloc"); exit(EXIT_FAILURE); } + if (!th) { + perror("malloc"); + exit(EXIT_FAILURE); + } data = (struct start_info *) malloc(thr_count * sizeof(struct start_info)); - if (!th) { perror("malloc"); exit(EXIT_FAILURE); } + if (!th) { + perror("malloc"); + exit(EXIT_FAILURE); + } for (tid = 0; tid < thr_count; tid++) { data[tid].tid = tid; @@ -90,28 +94,30 @@ atomic_spinlock_test_th(opal_atomic_lock_t *lock, int count, int id, int thr_cou return ret; } - -static int -atomic_spinlock_test(opal_atomic_lock_t *lock, int count, int id) +static int atomic_spinlock_test(opal_atomic_lock_t *lock, int count, int id) { int i; - for (i = 0 ; i < count ; ++i) { + for (i = 0; i < count; ++i) { opal_atomic_lock(lock); - if (atomic_verbose) { printf("id %03d has the lock (lock)\n", id); } + if (atomic_verbose) { + printf("id %03d has the lock (lock)\n", id); + } opal_atomic_unlock(lock); - while (opal_atomic_trylock(lock)) { ; } - if (atomic_verbose) { printf("id %03d has the lock (trylock)\n", id); } + while (opal_atomic_trylock(lock)) { + ; + } + if (atomic_verbose) { + printf("id %03d has the lock (trylock)\n", id); + } opal_atomic_unlock(lock); } return 0; } - -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int ret = 77; opal_atomic_lock_t lock; diff --git a/test/carto/carto_test.c b/test/carto/carto_test.c index 2ff81d6d86..2c81e978c3 100644 --- a/test/carto/carto_test.c +++ b/test/carto/carto_test.c @@ -23,16 +23,14 @@ #define false 0 #define true 1 - -#include <mpi.h> -#include <stdio.h> -#include "../../opal/mca/carto/carto.h" +#include "../../opal/class/opal_graph.h" #include "../../opal/mca/carto/base/base.h" +#include "../../opal/mca/carto/carto.h" #include "../../opal/util/output.h" -#include "../../opal/class/opal_graph.h" +#include <mpi.h> +#include <stdio.h> -int -main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size, distance, distance_array_size, i; opal_carto_graph_t *graph; @@ -44,37 +42,38 @@ main(int argc, char* argv[]) MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - printf("Hello, world, I am %d of %d\n", rank, size); if (0 == rank) { /** * */ - opal_output(0," \n\nget_host_graph Full\n"); - opal_carto_base_get_host_graph(&graph,NULL); + opal_output(0, " \n\nget_host_graph Full\n"); + opal_carto_base_get_host_graph(&graph, NULL); opal_graph_print(graph); slot0 = opal_carto_base_find_node(graph, "slot0"); if (NULL == slot0) { - opal_output(0,"couldn't find slot0 in the graph exiting\n"); + opal_output(0, "couldn't find slot0 in the graph exiting\n"); opal_carto_base_free_graph(graph); return -1; } end_node = opal_carto_base_find_node(graph, "slot3"); if (NULL == end_node) { - opal_output(0,"couldn't find mthca1 in the graph exiting\n"); + opal_output(0, "couldn't find mthca1 in the graph exiting\n"); opal_carto_base_free_graph(graph); return -1; } distance = opal_carto_base_spf(graph, slot0, end_node); - opal_output(0,"\nThe distance between slot0 and slot3 is %d\n",distance); + opal_output(0, "\nThe distance between slot0 and slot3 is %d\n", distance); distance_array = OBJ_NEW(opal_value_array_t); opal_value_array_init(distance_array, sizeof(opal_carto_node_distance_t)); opal_value_array_reserve(distance_array, 50); - distance_array_size = opal_carto_base_get_nodes_distance(graph, slot0, NULL, distance_array); - for (i=0; i < distance_array_size; i++) { + distance_array_size = opal_carto_base_get_nodes_distance(graph, slot0, NULL, + distance_array); + for (i = 0; i < distance_array_size; i++) { node_distance = opal_value_array_get_item(distance_array, i); - opal_output(0,"Node %s distance from slot0 is %d\n",node_distance->node->node_name, node_distance->node_distance); + opal_output(0, "Node %s distance from slot0 is %d\n", node_distance->node->node_name, + node_distance->node_distance); } OBJ_RELEASE(distance_array); opal_carto_base_free_graph(graph); @@ -82,30 +81,32 @@ main(int argc, char* argv[]) * */ - opal_output(0," \n\nget_host_graph Infiniband\n"); - opal_carto_base_get_host_graph(&graph,"Infiniband"); + opal_output(0, " \n\nget_host_graph Infiniband\n"); + opal_carto_base_get_host_graph(&graph, "Infiniband"); opal_graph_print(graph); slot0 = opal_carto_base_find_node(graph, "slot0"); if (NULL == slot0) { - opal_output(0,"couldn't find slot0 in the graph exiting\n"); + opal_output(0, "couldn't find slot0 in the graph exiting\n"); opal_carto_base_free_graph(graph); return -1; } end_node = opal_carto_base_find_node(graph, "mthca1"); if (NULL == end_node) { - opal_output(0,"couldn't find mthca1 in the graph exiting\n"); + opal_output(0, "couldn't find mthca1 in the graph exiting\n"); opal_carto_base_free_graph(graph); return -1; } distance = opal_carto_base_spf(graph, slot0, end_node); - opal_output(0,"\nThe distance between slot0 and mthca1 is %d\n",distance); + opal_output(0, "\nThe distance between slot0 and mthca1 is %d\n", distance); distance_array = OBJ_NEW(opal_value_array_t); opal_value_array_init(distance_array, sizeof(opal_carto_node_distance_t)); opal_value_array_reserve(distance_array, 50); - distance_array_size = opal_carto_base_get_nodes_distance(graph, slot0, "Infiniband", distance_array); - for (i=0; i < distance_array_size; i++) { + distance_array_size = opal_carto_base_get_nodes_distance(graph, slot0, "Infiniband", + distance_array); + for (i = 0; i < distance_array_size; i++) { node_distance = opal_value_array_get_item(distance_array, i); - opal_output(0,"Node %s distance from slot0 is %d\n",node_distance->node->node_name, node_distance->node_distance); + opal_output(0, "Node %s distance from slot0 is %d\n", node_distance->node->node_name, + node_distance->node_distance); } OBJ_RELEASE(distance_array); opal_carto_base_free_graph(graph); @@ -113,30 +114,32 @@ main(int argc, char* argv[]) * */ - opal_output(0," \n\nget_host_graph Ethernet\n"); - opal_carto_base_get_host_graph(&graph,"Ethernet"); + opal_output(0, " \n\nget_host_graph Ethernet\n"); + opal_carto_base_get_host_graph(&graph, "Ethernet"); opal_graph_print(graph); slot0 = opal_carto_base_find_node(graph, "slot0"); if (NULL == slot0) { - opal_output(0,"couldn't find slot0 in the graph exiting\n"); + opal_output(0, "couldn't find slot0 in the graph exiting\n"); opal_carto_base_free_graph(graph); return -1; } end_node = opal_carto_base_find_node(graph, "eth1"); if (NULL == end_node) { - opal_output(0,"couldn't find mthca1 in the graph exiting\n"); + opal_output(0, "couldn't find mthca1 in the graph exiting\n"); opal_carto_base_free_graph(graph); return -1; } distance = opal_carto_base_spf(graph, slot0, end_node); - opal_output(0,"\nThe distance between slot0 and eth1 is %d\n",distance); + opal_output(0, "\nThe distance between slot0 and eth1 is %d\n", distance); distance_array = OBJ_NEW(opal_value_array_t); opal_value_array_init(distance_array, sizeof(opal_carto_node_distance_t)); opal_value_array_reserve(distance_array, 50); - distance_array_size = opal_carto_base_get_nodes_distance(graph, slot0, "Ethernet", distance_array); - for (i=0; i < distance_array_size; i++) { + distance_array_size = opal_carto_base_get_nodes_distance(graph, slot0, "Ethernet", + distance_array); + for (i = 0; i < distance_array_size; i++) { node_distance = opal_value_array_get_item(distance_array, i); - opal_output(0,"Node %s distance from slot0 is %d\n",node_distance->node->node_name, node_distance->node_distance); + opal_output(0, "Node %s distance from slot0 is %d\n", node_distance->node->node_name, + node_distance->node_distance); } OBJ_RELEASE(distance_array); opal_carto_base_free_graph(graph); @@ -144,39 +147,38 @@ main(int argc, char* argv[]) * */ - opal_output(0," \n\nget_host_graph Memory\n"); - opal_carto_base_get_host_graph(&graph,"Memory"); + opal_output(0, " \n\nget_host_graph Memory\n"); + opal_carto_base_get_host_graph(&graph, "Memory"); opal_graph_print(graph); slot0 = opal_carto_base_find_node(graph, "slot0"); if (NULL == slot0) { - opal_output(0,"couldn't find slot0 in the graph exiting\n"); + opal_output(0, "couldn't find slot0 in the graph exiting\n"); opal_carto_base_free_graph(graph); return -1; } end_node = opal_carto_base_find_node(graph, "mem3"); if (NULL == end_node) { - opal_output(0,"couldn't find mthca1 in the graph exiting\n"); + opal_output(0, "couldn't find mthca1 in the graph exiting\n"); opal_carto_base_free_graph(graph); return -1; } distance = opal_carto_base_spf(graph, slot0, end_node); - opal_output(0,"\nThe distance between slot0 and mem3 is %d\n",distance); + opal_output(0, "\nThe distance between slot0 and mem3 is %d\n", distance); distance_array = OBJ_NEW(opal_value_array_t); opal_value_array_init(distance_array, sizeof(opal_carto_node_distance_t)); opal_value_array_reserve(distance_array, 50); - distance_array_size = opal_carto_base_get_nodes_distance(graph, slot0, "Memory", distance_array); - for (i=0; i < distance_array_size; i++) { + distance_array_size = opal_carto_base_get_nodes_distance(graph, slot0, "Memory", + distance_array); + for (i = 0; i < distance_array_size; i++) { node_distance = opal_value_array_get_item(distance_array, i); - opal_output(0,"Node %s distance from slot0 is %d\n",node_distance->node->node_name, node_distance->node_distance); + opal_output(0, "Node %s distance from slot0 is %d\n", node_distance->node->node_name, + node_distance->node_distance); } OBJ_RELEASE(distance_array); - opal_carto_base_free_graph(graph); - + opal_carto_base_free_graph(graph); } MPI_Barrier(MPI_COMM_WORLD); MPI_Finalize(); return 0; - } - diff --git a/test/class/ompi_rb_tree.c b/test/class/ompi_rb_tree.c index a13c0e055e..0ce02f83e2 100644 --- a/test/class/ompi_rb_tree.c +++ b/test/class/ompi_rb_tree.c @@ -23,67 +23,60 @@ #include "opal_config.h" #include <stdint.h> #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #else -#include <sys/_time.h> +# include <sys/_time.h> #endif -#include <string.h> -#include "support.h" #include "opal/class/opal_rb_tree.h" #include "opal/mca/mpool/base/base.h" +#include "support.h" +#include <string.h> #define NUM_KEYS 10000 -#define SEED 1 -int keys[] = { - 0, 1, 2, 3, 4, 5, 6, 7 -}; +#define SEED 1 +int keys[] = {0, 1, 2, 3, 4, 5, 6, 7}; -int values[] = { - 10, 11, 12, 13, 14, 15, 16, 17 -}; +int values[] = {10, 11, 12, 13, 14, 15, 16, 17}; -int comp_fn(void * ele1, void * ele2); +int comp_fn(void *ele1, void *ele2); void test1(void); -int comp_key(void* key1, void* key2); +int comp_key(void *key1, void *key2); void test_keys(void); -int comp_fn(void * ele1, void * ele2) +int comp_fn(void *ele1, void *ele2) { - if(*((int *) ele1) > *((int *) ele2)) { - return(1); + if (*((int *) ele1) > *((int *) ele2)) { + return (1); } - if(*((int *) ele1) < *((int *) ele2)) { - return(-1); + if (*((int *) ele1) < *((int *) ele2)) { + return (-1); } - return(0); + return (0); } -struct my_key_t{ +struct my_key_t { void *base; void *bound; -}; typedef struct my_key_t my_key_t; +}; +typedef struct my_key_t my_key_t; -struct my_val_t{ - my_key_t* key; +struct my_val_t { + my_key_t *key; int val; -}; typedef struct my_val_t my_val_t; - +}; +typedef struct my_val_t my_val_t; -int comp_key(void* key1, void* key2) { - if( ((my_key_t*) key1)->base < - ((my_key_t*) key2)->base) { +int comp_key(void *key1, void *key2) +{ + if (((my_key_t *) key1)->base < ((my_key_t *) key2)->base) { return -1; - } - else if ( ((my_key_t*) key1)->base > - ((my_key_t*) key2)->bound) { + } else if (((my_key_t *) key1)->base > ((my_key_t *) key2)->bound) { return 1; - } - else { + } else { return 0; } } - void test_keys(void) { opal_rb_tree_t tree; @@ -98,40 +91,37 @@ void test_keys(void) OBJ_CONSTRUCT(&tree, opal_rb_tree_t); rc = opal_rb_tree_init(&tree, comp_key); srand(SEED); - for(i = 0; i < NUM_KEYS; i++) { + for (i = 0; i < NUM_KEYS; i++) { cur_key = &(keys[i]); cur_val = &(vals[i]); cur_val->key = cur_key; cur_val->val = i; tmp = (long) rand(); - cur_key->base = (void*) tmp; + cur_key->base = (void *) tmp; tmp += (long) rand(); - cur_key->bound = (void*) tmp; + cur_key->bound = (void *) tmp; rc = opal_rb_tree_insert(&tree, cur_key, cur_val); - if(OPAL_SUCCESS != rc) { + if (OPAL_SUCCESS != rc) { test_failure("error inserting element in the tree"); } } - for(i = 0; i < NUM_KEYS; i+=2) { + for (i = 0; i < NUM_KEYS; i += 2) { cur_key = &(keys[i]); rc = opal_rb_tree_delete(&tree, cur_key); - if(OPAL_SUCCESS != rc) { + if (OPAL_SUCCESS != rc) { test_failure("error deleting element in the tree"); } } - for(i = 1; i < NUM_KEYS; i+=2) { + for (i = 1; i < NUM_KEYS; i += 2) { cur_key = &(keys[i]); - cur_val = (my_val_t*) opal_rb_tree_find(&tree, cur_key); - if(cur_val == NULL) { + cur_val = (my_val_t *) opal_rb_tree_find(&tree, cur_key); + if (cur_val == NULL) { test_failure("lookup returned NULL item"); - } - else if(cur_val->val != i && (cur_val->key->base > cur_key->base || - cur_val->key->bound < cur_key->base)) { - sprintf(buf, "lookup returned invalid item, returned %d, extected %d", - cur_val->val, i); + } else if (cur_val->val != i + && (cur_val->key->base > cur_key->base || cur_val->key->bound < cur_key->base)) { + sprintf(buf, "lookup returned invalid item, returned %d, extected %d", cur_val->val, i); test_failure(buf); } - } } @@ -139,121 +129,121 @@ void test1(void) { opal_rb_tree_t tree; int rc; - void * result; + void *result; OBJ_CONSTRUCT(&tree, opal_rb_tree_t); rc = opal_rb_tree_init(&tree, comp_fn); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly initialize the tree"); } rc = opal_rb_tree_insert(&tree, &keys[0], &values[0]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly insert a new node"); } result = opal_rb_tree_find(&tree, &keys[0]); - if(NULL == result) { + if (NULL == result) { test_failure("lookup returned null!"); } - if(!test_verify_int(values[0], *((int *) result))) { + if (!test_verify_int(values[0], *((int *) result))) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_insert(&tree, &keys[1], &values[1]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly insert a new node"); } result = opal_rb_tree_find(&tree, &keys[1]); - if(NULL == result) { + if (NULL == result) { test_failure("lookup returned null!"); } - if(!test_verify_int(values[1], *((int *) result))) { + if (!test_verify_int(values[1], *((int *) result))) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_insert(&tree, &keys[2], &values[2]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly insert a new node"); } result = opal_rb_tree_find(&tree, &keys[2]); - if(NULL == result) { + if (NULL == result) { test_failure("lookup returned null!"); } - if(!test_verify_int(values[2], *((int *) result))) { + if (!test_verify_int(values[2], *((int *) result))) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_insert(&tree, &keys[3], &values[3]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly insert a new node"); } result = opal_rb_tree_find(&tree, &keys[3]); - if(NULL == result) { + if (NULL == result) { test_failure("lookup returned null!"); } - if(!test_verify_int(values[3], *((int *) result))) { + if (!test_verify_int(values[3], *((int *) result))) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_insert(&tree, &keys[4], &values[4]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly insert a new node"); } result = opal_rb_tree_find(&tree, &keys[4]); - if(NULL == result) { + if (NULL == result) { test_failure("lookup returned null!"); } - if(!test_verify_int(values[4], *((int *) result))) { + if (!test_verify_int(values[4], *((int *) result))) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_insert(&tree, &keys[5], &values[5]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly insert a new node"); } result = opal_rb_tree_find(&tree, &keys[5]); - if(NULL == result) { + if (NULL == result) { test_failure("lookup returned null!"); } - if(!test_verify_int(values[5], *((int *) result))) { + if (!test_verify_int(values[5], *((int *) result))) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_insert(&tree, &keys[6], &values[6]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly insert a new node"); } result = opal_rb_tree_find(&tree, &keys[6]); - if(NULL == result) { + if (NULL == result) { test_failure("lookup returned null!"); } - if(!test_verify_int(values[6], *((int *) result))) { + if (!test_verify_int(values[6], *((int *) result))) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_insert(&tree, &keys[7], &values[7]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly insert a new node"); } result = opal_rb_tree_find(&tree, &keys[7]); - if(NULL == result) { + if (NULL == result) { test_failure("lookup returned null!"); } - if(!test_verify_int(values[7], *((int *) result))) { + if (!test_verify_int(values[7], *((int *) result))) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_size(&tree); - if(!test_verify_int(8, rc)) { + if (!test_verify_int(8, rc)) { test_failure("failed to properly insert a new node"); } rc = opal_rb_tree_delete(&tree, &keys[0]); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly delete a node"); } result = opal_rb_tree_find(&tree, &keys[0]); - if(NULL != result) { + if (NULL != result) { test_failure("lookup returned a value instead of null!"); } else { test_success(); @@ -263,7 +253,7 @@ void test1(void) } /* the following test is based on memory lookups in the mpool */ -int mem_node_compare(void * key1, void * key2); +int mem_node_compare(void *key1, void *key2); void test2(void); /* the maximum number of memory pools a piece of memory can be registered with */ @@ -272,34 +262,27 @@ void test2(void); /* the number of memory segments to allocate */ #define NUM_ALLOCATIONS 500 -struct opal_test_rb_key_t -{ - void * bottom; /* the bottom of the memory range */ - void * top; /* the top of the memory range */ +struct opal_test_rb_key_t { + void *bottom; /* the bottom of the memory range */ + void *top; /* the top of the memory range */ }; typedef struct opal_test_rb_key_t opal_test_rb_key_t; -struct opal_test_rb_value_t -{ +struct opal_test_rb_value_t { opal_free_list_item_t super; /* the parent class */ - opal_test_rb_key_t key; /* the key which holds the memory pointers */ - mca_mpool_base_module_t* registered_mpools[MAX_REGISTRATIONS]; - /* the mpools the memory is registered with */ + opal_test_rb_key_t key; /* the key which holds the memory pointers */ + mca_mpool_base_module_t *registered_mpools[MAX_REGISTRATIONS]; + /* the mpools the memory is registered with */ }; typedef struct opal_test_rb_value_t opal_test_rb_value_t; OBJ_CLASS_INSTANCE(opal_test_rb_value_t, opal_free_list_item_t, NULL, NULL); -int mem_node_compare(void * key1, void * key2) +int mem_node_compare(void *key1, void *key2) { - if(((opal_test_rb_key_t *) key1)->bottom < - ((opal_test_rb_key_t *) key2)->bottom) - { + if (((opal_test_rb_key_t *) key1)->bottom < ((opal_test_rb_key_t *) key2)->bottom) { return -1; - } - else if(((opal_test_rb_key_t *) key1)->bottom > - ((opal_test_rb_key_t *) key2)->top) - { + } else if (((opal_test_rb_key_t *) key1)->bottom > ((opal_test_rb_key_t *) key2)->top) { return 1; } return 0; @@ -308,73 +291,60 @@ int mem_node_compare(void * key1, void * key2) void test2(void) { opal_free_list_t key_list; - opal_free_list_item_t * new_value; + opal_free_list_item_t *new_value; opal_rb_tree_t tree; int rc, i, size; - void * result, * lookup; - void * mem[NUM_ALLOCATIONS]; - opal_free_list_item_t * key_array[NUM_ALLOCATIONS]; + void *result, *lookup; + void *mem[NUM_ALLOCATIONS]; + opal_free_list_item_t *key_array[NUM_ALLOCATIONS]; struct timeval start, end; OBJ_CONSTRUCT(&key_list, opal_free_list_t); - opal_free_list_init (&key_list, sizeof(opal_test_rb_value_t), - opal_cache_line_size, - OBJ_CLASS(opal_test_rb_value_t), - 0,opal_cache_line_size, - 0, -1 , 128, NULL, 0, NULL, NULL, NULL); + opal_free_list_init(&key_list, sizeof(opal_test_rb_value_t), opal_cache_line_size, + OBJ_CLASS(opal_test_rb_value_t), 0, opal_cache_line_size, 0, -1, 128, NULL, + 0, NULL, NULL, NULL); OBJ_CONSTRUCT(&tree, opal_rb_tree_t); rc = opal_rb_tree_init(&tree, mem_node_compare); - if(!test_verify_int(OPAL_SUCCESS, rc)) { + if (!test_verify_int(OPAL_SUCCESS, rc)) { test_failure("failed to properly initialize the tree"); } size = 1; - for(i = 0; i < NUM_ALLOCATIONS; i++) - { + for (i = 0; i < NUM_ALLOCATIONS; i++) { mem[i] = malloc(size); - if(NULL == mem[i]) - { + if (NULL == mem[i]) { test_failure("system out of memory"); return; } - new_value = opal_free_list_get (&key_list); - if(NULL == new_value) - { + new_value = opal_free_list_get(&key_list); + if (NULL == new_value) { test_failure("failed to get memory from free list"); } key_array[i] = new_value; ((opal_test_rb_value_t *) new_value)->key.bottom = mem[i]; - ((opal_test_rb_value_t *) new_value)->key.top = - (void *) ((size_t) mem[i] + size - 1); - ((opal_test_rb_value_t *) new_value)->registered_mpools[0] = (void *)(intptr_t) i; - rc = opal_rb_tree_insert(&tree, &((opal_test_rb_value_t *)new_value)->key, - new_value); - if(OPAL_SUCCESS != rc) - { + ((opal_test_rb_value_t *) new_value)->key.top = (void *) ((size_t) mem[i] + size - 1); + ((opal_test_rb_value_t *) new_value)->registered_mpools[0] = (void *) (intptr_t) i; + rc = opal_rb_tree_insert(&tree, &((opal_test_rb_value_t *) new_value)->key, new_value); + if (OPAL_SUCCESS != rc) { test_failure("failed to properly insert a new node"); } size += 1; } gettimeofday(&start, NULL); - for(i = 0; i < NUM_ALLOCATIONS; i++) - { + for (i = 0; i < NUM_ALLOCATIONS; i++) { lookup = (void *) ((size_t) mem[i] + i); result = opal_rb_tree_find(&tree, &lookup); - if(NULL == result) - { + if (NULL == result) { test_failure("lookup returned null!"); - } else if(i != ((int)(intptr_t) ((opal_test_rb_value_t *) result)->registered_mpools[0])) - { + } else if (i != ((int) (intptr_t)((opal_test_rb_value_t *) result)->registered_mpools[0])) { test_failure("lookup returned wrong node!"); } result = opal_rb_tree_find(&tree, &lookup); - if(NULL == result) - { + if (NULL == result) { test_failure("lookup returned null!"); - } else if(i != ((int)(intptr_t) ((opal_test_rb_value_t *) result)->registered_mpools[0])) - { + } else if (i != ((int) (intptr_t)((opal_test_rb_value_t *) result)->registered_mpools[0])) { test_failure("lookup returned wrong node!"); } } @@ -388,13 +358,11 @@ void test2(void) (float) i / (float) (NUM_ALLOCATIONS * 2)); #endif - for(i = 0; i < NUM_ALLOCATIONS; i++) - { - if(NULL != mem[i]) - { + for (i = 0; i < NUM_ALLOCATIONS; i++) { + if (NULL != mem[i]) { free(mem[i]); } - opal_free_list_return (&(key_list), key_array[i]); + opal_free_list_return(&(key_list), key_array[i]); } OBJ_DESTRUCT(&tree); diff --git a/test/class/opal_bitmap.c b/test/class/opal_bitmap.c index 5877841064..8bbaf221ea 100644 --- a/test/class/opal_bitmap.c +++ b/test/class/opal_bitmap.c @@ -4,17 +4,17 @@ #include "opal_config.h" -#include <stdio.h> #include "support.h" +#include <stdio.h> #include "opal/class/opal_bitmap.h" #include "opal/constants.h" -#define BSIZE 26 +#define BSIZE 26 #define OPAL_INVALID_BIT -1 -#define ERR_CODE -2 +#define ERR_CODE -2 -#define PRINT_VALID_ERR \ +#define PRINT_VALID_ERR \ fprintf(error_out, "================================ \n"); \ fprintf(error_out, "This is suppossed to throw error \n"); \ fprintf(error_out, "================================ \n") @@ -26,7 +26,6 @@ static void test_bitmap_clear_all(opal_bitmap_t *bm); static void test_bitmap_set_all(opal_bitmap_t *bm); static void test_bitmap_find_and_set(opal_bitmap_t *bm); - static int set_bit(opal_bitmap_t *bm, int bit); static int clear_bit(opal_bitmap_t *bm, int bit); static int is_set_bit(opal_bitmap_t *bm, int bit); @@ -39,7 +38,7 @@ static int find_and_set(opal_bitmap_t *bm, int bit); static void print_bitmap(opal_bitmap_t *bm); #endif -static FILE *error_out=NULL; +static FILE *error_out = NULL; int main(int argc, char *argv[]) { @@ -53,8 +52,9 @@ int main(int argc, char *argv[]) #ifdef STANDALONE error_out = stderr; #else - error_out = fopen( "./opal_bitmap_test_out.txt", "w" ); - if( error_out == NULL ) error_out = stderr; + error_out = fopen("./opal_bitmap_test_out.txt", "w"); + if (error_out == NULL) + error_out = stderr; #endif /* Initialize bitmap */ @@ -62,17 +62,17 @@ int main(int argc, char *argv[]) PRINT_VALID_ERR; err = opal_bitmap_init(NULL, 2); if (err == OPAL_ERR_BAD_PARAM) - fprintf(error_out, "ERROR: Initialization of bitmap failed\n\n"); + fprintf(error_out, "ERROR: Initialization of bitmap failed\n\n"); PRINT_VALID_ERR; err = opal_bitmap_init(&bm, -1); if (err == OPAL_ERR_BAD_PARAM) - fprintf(error_out, "ERROR: Initialization of bitmap failed \n\n"); + fprintf(error_out, "ERROR: Initialization of bitmap failed \n\n"); err = opal_bitmap_init(&bm, BSIZE); if (0 > err) { - fprintf(error_out, "Error in bitmap create -- aborting \n"); - exit(-1); + fprintf(error_out, "Error in bitmap create -- aborting \n"); + exit(-1); } fprintf(error_out, "\nTesting bitmap set... \n"); @@ -103,10 +103,9 @@ int main(int argc, char *argv[]) return 0; } - - -void test_bitmap_set(opal_bitmap_t *bm) { - int result=0; +void test_bitmap_set(opal_bitmap_t *bm) +{ + int result = 0; /* start of bitmap and boundaries */ set_bit(bm, 0); @@ -127,12 +126,12 @@ void test_bitmap_set(opal_bitmap_t *bm) { /* invalid bit */ PRINT_VALID_ERR; result = set_bit(bm, -1); - TEST_AND_REPORT(result, ERR_CODE,"opal_bitmap_set_bit"); + TEST_AND_REPORT(result, ERR_CODE, "opal_bitmap_set_bit"); } - -void test_bitmap_clear(opal_bitmap_t *bm) { - int result=0; +void test_bitmap_clear(opal_bitmap_t *bm) +{ + int result = 0; /* Valid set bits */ clear_bit(bm, 29); @@ -144,16 +143,15 @@ void test_bitmap_clear(opal_bitmap_t *bm) { /* invalid bit */ PRINT_VALID_ERR; result = clear_bit(bm, -1); - TEST_AND_REPORT(result, ERR_CODE,"opal_bitmap_clear_bit"); + TEST_AND_REPORT(result, ERR_CODE, "opal_bitmap_clear_bit"); PRINT_VALID_ERR; result = clear_bit(bm, 142); - TEST_AND_REPORT(result, ERR_CODE,"opal_bitmap_clear_bit"); + TEST_AND_REPORT(result, ERR_CODE, "opal_bitmap_clear_bit"); } - void test_bitmap_is_set(opal_bitmap_t *bm) { - int result=0; + int result = 0; /* First set some bits */ test_bitmap_set(bm); @@ -163,18 +161,17 @@ void test_bitmap_is_set(opal_bitmap_t *bm) is_set_bit(bm, 32); result = is_set_bit(bm, 1122); - TEST_AND_REPORT(result,0,"opal_bitmap_is_set_bit"); + TEST_AND_REPORT(result, 0, "opal_bitmap_is_set_bit"); is_set_bit(bm, -33); - TEST_AND_REPORT(result,0,"opal_bitmap_is_set_bit"); + TEST_AND_REPORT(result, 0, "opal_bitmap_is_set_bit"); is_set_bit(bm, -1); - TEST_AND_REPORT(result,0,"opal_bitmap_is_set_bit"); + TEST_AND_REPORT(result, 0, "opal_bitmap_is_set_bit"); } - void test_bitmap_find_and_set(opal_bitmap_t *bm) { int bsize; - int result=0; + int result = 0; opal_bitmap_clear_all_bits(bm); result = find_and_set(bm, 0); @@ -213,7 +210,6 @@ void test_bitmap_clear_all(opal_bitmap_t *bm) TEST_AND_REPORT(result, 0, " error in opal_bitmap_clear_all_bits"); } - void test_bitmap_set_all(opal_bitmap_t *bm) { int result = set_all(bm); @@ -224,32 +220,30 @@ int set_bit(opal_bitmap_t *bm, int bit) { int err = opal_bitmap_set_bit(bm, bit); if (err != 0 || !opal_bitmap_is_set_bit(bm, bit)) { - fprintf(error_out, "ERROR: set_bit for bit = %d\n\n", bit); - return ERR_CODE; - } + fprintf(error_out, "ERROR: set_bit for bit = %d\n\n", bit); + return ERR_CODE; + } return 0; } - int clear_bit(opal_bitmap_t *bm, int bit) { int err = opal_bitmap_clear_bit(bm, bit); if ((err != 0) || opal_bitmap_is_set_bit(bm, bit)) { - fprintf(error_out, "ERROR: clear_bit for bit = %d \n\n", bit); - return ERR_CODE; + fprintf(error_out, "ERROR: clear_bit for bit = %d \n\n", bit); + return ERR_CODE; } return 0; } - int is_set_bit(opal_bitmap_t *bm, int bit) { bool result = opal_bitmap_is_set_bit(bm, bit); if (result) { if (bit < 0) { - fprintf(error_out, "ERROR: is_set_bit for bit = %d \n\n",bit); + fprintf(error_out, "ERROR: is_set_bit for bit = %d \n\n", bit); return ERR_CODE; } return 0; @@ -257,7 +251,7 @@ int is_set_bit(opal_bitmap_t *bm, int bit) if (!result) { if (0 <= bit && bit <= bm->array_size && !opal_bitmap_is_set_bit(bm, bit)) { - fprintf(error_out, "ERROR: is_set_bit for bit = %d \n\n",bit); + fprintf(error_out, "ERROR: is_set_bit for bit = %d \n\n", bit); return ERR_CODE; } return 0; @@ -266,7 +260,6 @@ int is_set_bit(opal_bitmap_t *bm, int bit) return 0; } - int find_and_set(opal_bitmap_t *bm, int bit) { int ret, pos; @@ -274,18 +267,17 @@ int find_and_set(opal_bitmap_t *bm, int bit) level stub, this function will be called in sequence to test */ ret = opal_bitmap_find_and_set_first_unset_bit(bm, &pos); - if (ret != OPAL_SUCCESS) return ret; + if (ret != OPAL_SUCCESS) + return ret; if (pos != bit) { - fprintf(error_out, "ERROR: find_and_set: expected to find_and_set %d\n\n", - bit); - return ERR_CODE; + fprintf(error_out, "ERROR: find_and_set: expected to find_and_set %d\n\n", bit); + return ERR_CODE; } return 0; } - int clear_all(opal_bitmap_t *bm) { int i; @@ -293,30 +285,27 @@ int clear_all(opal_bitmap_t *bm) return ERR_CODE; } for (i = 0; i < bm->array_size; ++i) - if (bm->bitmap[i] != 0) { - fprintf(error_out, "ERROR: clear_all for bitmap array entry %d\n\n", - i); - return ERR_CODE; - } + if (bm->bitmap[i] != 0) { + fprintf(error_out, "ERROR: clear_all for bitmap array entry %d\n\n", i); + return ERR_CODE; + } return 0; } - int set_all(opal_bitmap_t *bm) { - int i; - if (OPAL_SUCCESS != opal_bitmap_set_all_bits(bm)) { - return ERR_CODE; - } - for (i = 0; i < bm->array_size; ++i) - if (bm->bitmap[i] != 0xffffffffffffffffUL) { - fprintf(error_out, "ERROR: set_all for bitmap arry entry %d\n\n", i); - return ERR_CODE; - } - return 0; + int i; + if (OPAL_SUCCESS != opal_bitmap_set_all_bits(bm)) { + return ERR_CODE; + } + for (i = 0; i < bm->array_size; ++i) + if (bm->bitmap[i] != 0xffffffffffffffffUL) { + fprintf(error_out, "ERROR: set_all for bitmap arry entry %d\n\n", i); + return ERR_CODE; + } + return 0; } - #if WANT_PRINT_BITMAP void print_bitmap(opal_bitmap_t *bm) { @@ -325,8 +314,7 @@ void print_bitmap(opal_bitmap_t *bm) int i; for (i = 0; i < bm->array_size; ++i) { - fprintf(error_out, "---\n bitmap[%d] = %x \n---\n\n", i, - (bm->bitmap[i] & 0xff)); + fprintf(error_out, "---\n bitmap[%d] = %x \n---\n\n", i, (bm->bitmap[i] & 0xff)); } fprintf(error_out, "========================= \n"); return; diff --git a/test/class/opal_fifo.c b/test/class/opal_fifo.c index 9a2ea79786..67a497c658 100644 --- a/test/class/opal_fifo.c +++ b/test/class/opal_fifo.c @@ -13,110 +13,116 @@ #include "opal_config.h" #include <assert.h> -#include "support.h" #include "opal/class/opal_fifo.h" -#include "opal/runtime/opal.h" #include "opal/constants.h" #include "opal/mca/threads/threads.h" +#include "opal/runtime/opal.h" +#include "support.h" -#include <stdlib.h> -#include <stdio.h> #include <stddef.h> +#include <stdio.h> +#include <stdlib.h> #include <sys/time.h> #define OPAL_FIFO_TEST_THREAD_COUNT 8 -#define ITERATIONS 1000000 -#define ITEM_COUNT 100 -#define ITEMS_PER_LOOP 30 +#define ITERATIONS 1000000 +#define ITEM_COUNT 100 +#define ITEMS_PER_LOOP 30 #if !defined(timersub) -#define timersub(a, b, r) \ - do { \ - (r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - if ((a)->tv_usec < (b)->tv_usec) { \ - (r)->tv_sec--; \ - (a)->tv_usec += 1000000; \ - } \ - (r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - } while (0) +# define timersub(a, b, r) \ + do { \ + (r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + if ((a)->tv_usec < (b)->tv_usec) { \ + (r)->tv_sec--; \ + (a)->tv_usec += 1000000; \ + } \ + (r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + } while (0) #endif -static void *thread_test (opal_object_t *arg) { +static void *thread_test(opal_object_t *arg) +{ opal_thread_t *t = (opal_thread_t *) arg; opal_fifo_t *fifo = (opal_fifo_t *) t->t_arg; opal_list_item_t *item; struct timeval start, stop, total; double timing; - gettimeofday (&start, NULL); - for (int i = 0 ; i < ITERATIONS ; ++i) { - item = opal_fifo_pop_atomic (fifo); + gettimeofday(&start, NULL); + for (int i = 0; i < ITERATIONS; ++i) { + item = opal_fifo_pop_atomic(fifo); if (NULL != item) { - (void) opal_fifo_push_atomic (fifo, item); + (void) opal_fifo_push_atomic(fifo, item); } } - gettimeofday (&stop, NULL); + gettimeofday(&stop, NULL); timersub(&stop, &start, &total); timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) ITERATIONS; - printf ("Atomics thread finished. Time: %d s %d us %d nsec/poppush\n", (int) total.tv_sec, - (int)total.tv_usec, (int)(timing / 1e-9)); + printf("Atomics thread finished. Time: %d s %d us %d nsec/poppush\n", (int) total.tv_sec, + (int) total.tv_usec, (int) (timing / 1e-9)); return NULL; } -static void *thread_test_exhaust (opal_object_t *arg) { - opal_thread_t *t = (opal_thread_t *) arg; - opal_fifo_t *fifo = (opal_fifo_t *) t->t_arg; - opal_list_item_t *items[ITEMS_PER_LOOP]; - struct timeval start, stop, total; - int item_count = 0; - double timing; - - gettimeofday (&start, NULL); - - for (int i = 0 ; i < ITERATIONS ; i += ITEMS_PER_LOOP) { - for (int j = 0 ; j < ITEMS_PER_LOOP ; ++j) { - items[j] = opal_fifo_pop_atomic (fifo); - if (items[j]) { - ++item_count; - } - } +static void *thread_test_exhaust(opal_object_t *arg) +{ + opal_thread_t *t = (opal_thread_t *) arg; + opal_fifo_t *fifo = (opal_fifo_t *) t->t_arg; + opal_list_item_t *items[ITEMS_PER_LOOP]; + struct timeval start, stop, total; + int item_count = 0; + double timing; + + gettimeofday(&start, NULL); + + for (int i = 0; i < ITERATIONS; i += ITEMS_PER_LOOP) { + for (int j = 0; j < ITEMS_PER_LOOP; ++j) { + items[j] = opal_fifo_pop_atomic(fifo); + if (items[j]) { + ++item_count; + } + } - for (int j = 0 ; j < ITEMS_PER_LOOP ; ++j) { - if (items[j]) { - (void) opal_fifo_push_atomic (fifo, items[j]); - } + for (int j = 0; j < ITEMS_PER_LOOP; ++j) { + if (items[j]) { + (void) opal_fifo_push_atomic(fifo, items[j]); + } + } } - } - gettimeofday (&stop, NULL); + gettimeofday(&stop, NULL); - timersub(&stop, &start, &total); + timersub(&stop, &start, &total); - timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) item_count; + timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) item_count; - fprintf (stderr, "Exhaustive atomics thread finished. Popped %d items. Time: %d s %d us %d nsec/poppush\n", item_count, - (int) total.tv_sec, (int)total.tv_usec, (int)(timing / 1e-9)); + fprintf( + stderr, + "Exhaustive atomics thread finished. Popped %d items. Time: %d s %d us %d nsec/poppush\n", + item_count, (int) total.tv_sec, (int) total.tv_usec, (int) (timing / 1e-9)); - return NULL; + return NULL; } -static bool check_fifo_consistency (opal_fifo_t *fifo, int expected_count) +static bool check_fifo_consistency(opal_fifo_t *fifo, int expected_count) { - opal_list_item_t * item; + opal_list_item_t *item; int count; - for (count = 0, item = (opal_list_item_t *) fifo->opal_fifo_head.data.item ; item != &fifo->opal_fifo_ghost ; - item = opal_list_get_next(item), count++); + for (count = 0, item = (opal_list_item_t *) fifo->opal_fifo_head.data.item; + item != &fifo->opal_fifo_ghost; item = opal_list_get_next(item), count++) + ; return count == expected_count; } -int main (int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ opal_thread_t threads[OPAL_FIFO_TEST_THREAD_COUNT]; opal_list_item_t *item, *prev, *item2; struct timeval start, stop, total; @@ -125,11 +131,11 @@ int main (int argc, char *argv[]) { double timing; int rc; - rc = opal_init_util (&argc, &argv); + rc = opal_init_util(&argc, &argv); test_verify_int(OPAL_SUCCESS, rc); if (OPAL_SUCCESS != rc) { test_finalize(); - exit (1); + exit(1); } test_init("opal_fifo_t"); @@ -137,123 +143,127 @@ int main (int argc, char *argv[]) { OBJ_CONSTRUCT(&fifo, opal_fifo_t); item = OBJ_NEW(opal_list_item_t); - prev = opal_fifo_push_st (&fifo, item); + prev = opal_fifo_push_st(&fifo, item); if (&fifo.opal_fifo_ghost == prev) { - test_success (); + test_success(); } else { - test_failure (" opal_fifo_push_st on empty fifo"); + test_failure(" opal_fifo_push_st on empty fifo"); } - item2 = opal_fifo_pop_st (&fifo); + item2 = opal_fifo_pop_st(&fifo); if (item == item2) { - test_success (); + test_success(); } else { - test_failure (" opal_fifo_pop_st"); + test_failure(" opal_fifo_pop_st"); } OBJ_RELEASE(item); - for (int i = 0 ; i < ITEM_COUNT ; ++i) { + for (int i = 0; i < ITEM_COUNT; ++i) { item = OBJ_NEW(opal_list_item_t); item->item_free = 0; - opal_fifo_push_st (&fifo, item); + opal_fifo_push_st(&fifo, item); } - if (check_fifo_consistency (&fifo, ITEM_COUNT)) { - test_success (); + if (check_fifo_consistency(&fifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" opal_fifo_push_st(multiple items)"); + test_failure(" opal_fifo_push_st(multiple items)"); } - gettimeofday (&start, NULL); - for (int i = 0 ; i < ITERATIONS ; ++i) { - item = opal_fifo_pop_st (&fifo); - (void) opal_fifo_push_st (&fifo, item); + gettimeofday(&start, NULL); + for (int i = 0; i < ITERATIONS; ++i) { + item = opal_fifo_pop_st(&fifo); + (void) opal_fifo_push_st(&fifo, item); } - gettimeofday (&stop, NULL); + gettimeofday(&stop, NULL); timersub(&stop, &start, &total); timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) ITERATIONS; - if (check_fifo_consistency (&fifo, ITEM_COUNT)) { - test_success (); + if (check_fifo_consistency(&fifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" fifo push/pop"); + test_failure(" fifo push/pop"); } - printf ("Single thread test. Time: %d s %d us %d nsec/poppush\n", (int) total.tv_sec, - (int)total.tv_usec, (int)(timing / 1e-9)); + printf("Single thread test. Time: %d s %d us %d nsec/poppush\n", (int) total.tv_sec, + (int) total.tv_usec, (int) (timing / 1e-9)); threads[0].t_arg = &fifo; - thread_test ((opal_object_t *) &threads[0]); + thread_test((opal_object_t *) &threads[0]); - if (check_fifo_consistency (&fifo, ITEM_COUNT)) { - test_success (); + if (check_fifo_consistency(&fifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" fifo push/pop single-threaded with atomics"); + test_failure(" fifo push/pop single-threaded with atomics"); } - gettimeofday (&start, NULL); - for (int i = 0 ; i < OPAL_FIFO_TEST_THREAD_COUNT ; ++i) { + gettimeofday(&start, NULL); + for (int i = 0; i < OPAL_FIFO_TEST_THREAD_COUNT; ++i) { OBJ_CONSTRUCT(&threads[i], opal_thread_t); threads[i].t_run = thread_test; threads[i].t_arg = &fifo; - opal_thread_start (threads + i); + opal_thread_start(threads + i); } - for (int i = 0 ; i < OPAL_FIFO_TEST_THREAD_COUNT ; ++i) { + for (int i = 0; i < OPAL_FIFO_TEST_THREAD_COUNT; ++i) { void *ret; - opal_thread_join (threads + i, &ret); + opal_thread_join(threads + i, &ret); } - gettimeofday (&stop, NULL); + gettimeofday(&stop, NULL); timersub(&stop, &start, &total); - timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) (ITERATIONS * OPAL_FIFO_TEST_THREAD_COUNT); + timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) + / (double) (ITERATIONS * OPAL_FIFO_TEST_THREAD_COUNT); - if (check_fifo_consistency (&fifo, ITEM_COUNT)) { - test_success (); + if (check_fifo_consistency(&fifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" fifo push/pop multi-threaded with atomics"); + test_failure(" fifo push/pop multi-threaded with atomics"); } - printf ("All threads finished. Thread count: %d Time: %d s %d us %d nsec/poppush\n", - OPAL_FIFO_TEST_THREAD_COUNT, (int) total.tv_sec, (int)total.tv_usec, (int)(timing / 1e-9)); - + printf("All threads finished. Thread count: %d Time: %d s %d us %d nsec/poppush\n", + OPAL_FIFO_TEST_THREAD_COUNT, (int) total.tv_sec, (int) total.tv_usec, + (int) (timing / 1e-9)); - gettimeofday (&start, NULL); - for (int i = 0 ; i < OPAL_FIFO_TEST_THREAD_COUNT ; ++i) { + gettimeofday(&start, NULL); + for (int i = 0; i < OPAL_FIFO_TEST_THREAD_COUNT; ++i) { OBJ_CONSTRUCT(&threads[i], opal_thread_t); threads[i].t_run = thread_test_exhaust; threads[i].t_arg = &fifo; - opal_thread_start (threads + i); + opal_thread_start(threads + i); } - for (int i = 0 ; i < OPAL_FIFO_TEST_THREAD_COUNT ; ++i) { + for (int i = 0; i < OPAL_FIFO_TEST_THREAD_COUNT; ++i) { void *ret; - opal_thread_join (threads + i, &ret); + opal_thread_join(threads + i, &ret); } - gettimeofday (&stop, NULL); + gettimeofday(&stop, NULL); timersub(&stop, &start, &total); - timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) (ITERATIONS * OPAL_FIFO_TEST_THREAD_COUNT); + timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) + / (double) (ITERATIONS * OPAL_FIFO_TEST_THREAD_COUNT); - if (check_fifo_consistency (&fifo, ITEM_COUNT)) { - test_success (); + if (check_fifo_consistency(&fifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" fifo push/pop multi-threaded with atomics when there are insufficient items"); + test_failure( + " fifo push/pop multi-threaded with atomics when there are insufficient items"); } - printf ("All threads finished. Thread count: %d Time: %d s %d us %d nsec/poppush\n", - OPAL_FIFO_TEST_THREAD_COUNT, (int) total.tv_sec, (int)total.tv_usec, (int)(timing / 1e-9)); + printf("All threads finished. Thread count: %d Time: %d s %d us %d nsec/poppush\n", + OPAL_FIFO_TEST_THREAD_COUNT, (int) total.tv_sec, (int) total.tv_usec, + (int) (timing / 1e-9)); success = true; - for (int i = 0 ; i < ITEM_COUNT ; ++i) { - item = opal_fifo_pop_st (&fifo); + for (int i = 0; i < ITEM_COUNT; ++i) { + item = opal_fifo_pop_st(&fifo); if (NULL == item) { success = false; break; @@ -262,14 +272,14 @@ int main (int argc, char *argv[]) { } if (success) { - test_success (); + test_success(); } else { - test_failure (" fifo pop all items"); + test_failure(" fifo pop all items"); } OBJ_DESTRUCT(&fifo); - opal_finalize_util (); + opal_finalize_util(); - return test_finalize (); + return test_finalize(); } diff --git a/test/class/opal_hash_table.c b/test/class/opal_hash_table.c index e4f0e215f7..4ae405accc 100644 --- a/test/class/opal_hash_table.c +++ b/test/class/opal_hash_table.c @@ -22,47 +22,31 @@ */ #include "opal_config.h" -#include <stdint.h> -#include <string.h> -#include "support.h" -#include "opal/class/opal_object.h" #include "opal/class/opal_hash_table.h" -#include "opal/runtime/opal.h" +#include "opal/class/opal_object.h" #include "opal/constants.h" +#include "opal/runtime/opal.h" +#include "support.h" +#include <stdint.h> +#include <string.h> -static FILE *error_out=NULL; - -char *num_keys[] = { - "1234", "1234", - "5678", "5678", - "12450", "12450", - "45623", "45623", - NULL -}; - +static FILE *error_out = NULL; -char *str_keys[] = { - "foo", "bar", - "2", "this cow jumped over the moon", - "this is another key", "this is another value", - "key key", "value value", - NULL -}; +char *num_keys[] = {"1234", "1234", "5678", "5678", "12450", "12450", "45623", "45623", NULL}; +char *str_keys[] = {"foo", + "bar", + "2", + "this cow jumped over the moon", + "this is another key", + "this is another value", + "key key", + "value value", + NULL}; -char *perm_keys[] = { - "abcdef", "abcdef", - "bcdefa", "bcdefa", - "cdefab", "cdefab", - "defabc", "defabc", - "efabcd", "efabcd", - "fabcde", "fabcde", - "badcfe", "badcfe", - "badcef", "badcef", - "abdcfe", "abdcfe", - "bcdaef", "bcdaef", - NULL -}; +char *perm_keys[] = {"abcdef", "abcdef", "bcdefa", "bcdefa", "cdefab", "cdefab", "defabc", + "defabc", "efabcd", "efabcd", "fabcde", "fabcde", "badcfe", "badcfe", + "badcef", "badcef", "abdcfe", "abdcfe", "bcdaef", "bcdaef", NULL}; /* * This data specifically knows about the April'2014 version of hash tables. @@ -72,13 +56,15 @@ char *perm_keys[] = { * Then... it removes a key and checks again (via traversal) * and removes another key and re-checks. */ -static char* remove_keys[] = { - "1", "A", "2", "B", "4", "D", "6", "F", "10", "J", NULL, /* insert as-is: ...AB.D.F...J... */ - "2", "b", "4", "d", "5", "e", "3", "c", NULL, /* insert with capacity-offset: ...ABbDdFec.J... */ - "ABbDdFecJ", /* traversal expectation */ - "4", "ABbdeFcJ", /* remove D (...ABbdeFc..J...) then expected traversal */ - "2", "AbcdeFJ", /* remove B (...AbcdeF...J...) then expected traversal */ - NULL /* end removals and expectations */ +static char *remove_keys[] = { + "1", "A", "2", "B", "4", "D", "6", "F", "10", "J", + NULL, /* insert as-is: ...AB.D.F...J... */ + "2", "b", "4", "d", "5", "e", "3", "c", NULL, /* insert with capacity-offset: + ...ABbDdFec.J... */ + "ABbDdFecJ", /* traversal expectation */ + "4", "ABbdeFcJ", /* remove D (...ABbdeFc..J...) then expected traversal */ + "2", "AbcdeFJ", /* remove B (...AbcdeF...J...) then expected traversal */ + NULL /* end removals and expectations */ }; typedef union { @@ -88,87 +74,83 @@ typedef union { static void validate_table(opal_hash_table_t *table, char *keys[], int is_numeric_keys) { - int j, ret; + int j, ret; value_t value; - for ( j = 0; keys[j]; j += 2) { - if ( 1 == is_numeric_keys ) { - ret = opal_hash_table_get_value_uint32(table, atoi(keys[j]), - (void**) &value.uvalue); + for (j = 0; keys[j]; j += 2) { + if (1 == is_numeric_keys) { + ret = opal_hash_table_get_value_uint32(table, atoi(keys[j]), (void **) &value.uvalue); if (OPAL_SUCCESS != ret) { test_failure("opal_hash_table_get_value_uint32 failed"); } } else { - ret = opal_hash_table_get_value_ptr(table, keys[j], - strlen(keys[j]), - &value.vvalue); + ret = opal_hash_table_get_value_ptr(table, keys[j], strlen(keys[j]), &value.vvalue); if (OPAL_SUCCESS != ret) { test_failure("opal_hash_table_get_value_ptr failed"); } } - test_verify_str(keys[j+1], value.vvalue); + test_verify_str(keys[j + 1], value.vvalue); } - test_verify_int(j/2, opal_hash_table_get_size(table)); + test_verify_int(j / 2, opal_hash_table_get_size(table)); } -static void -validate_remove_traversal(opal_hash_table_t * table, const char * expected_chars) +static void validate_remove_traversal(opal_hash_table_t *table, const char *expected_chars) { /* all values are single-character strings */ /* expected_chars are those single characters as a string */ - const int debug = 0; /* turn this on if you want to see the details */ + const int debug = 0; /* turn this on if you want to see the details */ int rc, problems = 0; - const char * expected_scanner = expected_chars; + const char *expected_scanner = expected_chars; uint32_t key; - void * raw_value; - void * node; + void *raw_value; + void *node; if (debug) { - fprintf(stderr, "debug: expecting '%s' capacity is %d\n", - expected_chars, (int) table->ht_capacity); + fprintf(stderr, "debug: expecting '%s' capacity is %d\n", expected_chars, + (int) table->ht_capacity); } for (rc = opal_hash_table_get_first_key_uint32(table, &key, &raw_value, &node); - OPAL_SUCCESS == rc; - rc = opal_hash_table_get_next_key_uint32(table, &key, &raw_value, node, &node)) { - const char * value = (const char *) raw_value; - char expected, actual; - if (debug) { - fprintf(stderr, "key %d (probe at %d) value '%s' excpected_scanner '%s'\n", - key, (int) (key%table->ht_capacity), value, expected_scanner); - } - if (1 != strlen(value)) { - fprintf(stderr, "key %d's value '%s' is not a one-character string\n", key, value); - problems += 1; - continue; /* might as well be completely noisy */ - } - if ('\0' == *expected_scanner) { - fprintf(stderr, "Found key %d value '%s' but not expected!\n", key, value); - problems += 1; - continue; - } - expected = *expected_scanner++; - actual = *value; - if (actual != expected) { - fprintf(stderr, "Expected '%c' but got '%c'\n", expected, actual); - problems += 1; - continue; - } + OPAL_SUCCESS == rc; + rc = opal_hash_table_get_next_key_uint32(table, &key, &raw_value, node, &node)) { + const char *value = (const char *) raw_value; + char expected, actual; + if (debug) { + fprintf(stderr, "key %d (probe at %d) value '%s' excpected_scanner '%s'\n", key, + (int) (key % table->ht_capacity), value, expected_scanner); + } + if (1 != strlen(value)) { + fprintf(stderr, "key %d's value '%s' is not a one-character string\n", key, value); + problems += 1; + continue; /* might as well be completely noisy */ + } + if ('\0' == *expected_scanner) { + fprintf(stderr, "Found key %d value '%s' but not expected!\n", key, value); + problems += 1; + continue; + } + expected = *expected_scanner++; + actual = *value; + if (actual != expected) { + fprintf(stderr, "Expected '%c' but got '%c'\n", expected, actual); + problems += 1; + continue; + } } /* final checks */ if (OPAL_ERROR != rc) { - fprintf(stderr, "table traversal did not end in OPAL_ERROR?!?\n"); - problems += 1; + fprintf(stderr, "table traversal did not end in OPAL_ERROR?!?\n"); + problems += 1; } if ('\0' != *expected_scanner) { - fprintf(stderr, "Still expecting more key/values: '%s'\n", expected_scanner); - problems += 1; + fprintf(stderr, "Still expecting more key/values: '%s'\n", expected_scanner); + problems += 1; } /* resolution */ if (problems > 0) { - fflush(stderr); - test_failure("validate_remove_traversal"); + fflush(stderr); + test_failure("validate_remove_traversal"); } else { - test_success(); + test_success(); } } @@ -176,9 +158,8 @@ static void test_htable(opal_hash_table_t *table) { int j; fprintf(error_out, "\nTesting integer keys...\n"); - for ( j = 0; num_keys[j]; j += 2) - { - opal_hash_table_set_value_uint32(table, atoi(num_keys[j]), num_keys[j+1]); + for (j = 0; num_keys[j]; j += 2) { + opal_hash_table_set_value_uint32(table, atoi(num_keys[j]), num_keys[j + 1]); } validate_table(table, num_keys, 1); @@ -187,9 +168,8 @@ static void test_htable(opal_hash_table_t *table) test_verify_int(0, opal_hash_table_get_size(table)); fprintf(error_out, "\nTesting string keys...\n"); - for ( j = 0; str_keys[j]; j += 2) - { - opal_hash_table_set_value_ptr(table, str_keys[j], strlen(str_keys[j]), str_keys[j+1]); + for (j = 0; str_keys[j]; j += 2) { + opal_hash_table_set_value_ptr(table, str_keys[j], strlen(str_keys[j]), str_keys[j + 1]); } validate_table(table, str_keys, 0); @@ -200,9 +180,8 @@ static void test_htable(opal_hash_table_t *table) fprintf(error_out, "\nTesting collision resolution...\n"); /* All of the string keys in keys array should have the same hash value. */ - for ( j = 0; perm_keys[j]; j += 2) - { - opal_hash_table_set_value_ptr(table, perm_keys[j], strlen(perm_keys[j]), perm_keys[j+1]); + for (j = 0; perm_keys[j]; j += 2) { + opal_hash_table_set_value_ptr(table, perm_keys[j], strlen(perm_keys[j]), perm_keys[j + 1]); } validate_table(table, perm_keys, 0); @@ -213,18 +192,18 @@ static void test_htable(opal_hash_table_t *table) fprintf(error_out, "\nTesting removal and traversal...\n"); j = 0; - char * str; + char *str; while (NULL != (str = remove_keys[j++])) { - opal_hash_table_set_value_uint32(table, atoi(str), remove_keys[j++]); + opal_hash_table_set_value_uint32(table, atoi(str), remove_keys[j++]); } while (NULL != (str = remove_keys[j++])) { - /* generate collisions */ - opal_hash_table_set_value_uint32(table, atoi(str) + table->ht_capacity, remove_keys[j++]); + /* generate collisions */ + opal_hash_table_set_value_uint32(table, atoi(str) + table->ht_capacity, remove_keys[j++]); } validate_remove_traversal(table, remove_keys[j++]); while (NULL != (str = remove_keys[j++])) { - opal_hash_table_remove_value_uint32(table, atoi(str)); - validate_remove_traversal(table, remove_keys[j++]); + opal_hash_table_remove_value_uint32(table, atoi(str)); + validate_remove_traversal(table, remove_keys[j++]); } /* remove all values for next test */ @@ -234,14 +213,12 @@ static void test_htable(opal_hash_table_t *table) fprintf(error_out, "\n\n"); } - static void test_dynamic(void) { - opal_hash_table_t *table; + opal_hash_table_t *table; table = OBJ_NEW(opal_hash_table_t); - if ( NULL == table ) - { + if (NULL == table) { fprintf(error_out, "Error: Unable to create hash table.\n"); exit(-1); } @@ -252,10 +229,9 @@ static void test_dynamic(void) OBJ_RELEASE(table); } - static void test_static(void) { - opal_hash_table_t table; + opal_hash_table_t table; OBJ_CONSTRUCT(&table, opal_hash_table_t); opal_hash_table_init(&table, 128); @@ -266,7 +242,6 @@ static void test_static(void) OBJ_DESTRUCT(&table); } - int main(int argc, char **argv) { int rc; @@ -283,17 +258,18 @@ int main(int argc, char **argv) #ifdef STANDALONE error_out = stderr; #else - error_out = fopen( "./opal_hash_table_test_out.txt", "w" ); - if( error_out == NULL ) error_out = stderr; + error_out = fopen("./opal_hash_table_test_out.txt", "w"); + if (error_out == NULL) + error_out = stderr; #endif test_dynamic(); test_static(); #ifndef STANDALONE - fclose( error_out ); + fclose(error_out); #endif - opal_finalize_util (); + opal_finalize_util(); return test_finalize(); } diff --git a/test/class/opal_lifo.c b/test/class/opal_lifo.c index 3f4d9b7d92..ab67d6e4ae 100644 --- a/test/class/opal_lifo.c +++ b/test/class/opal_lifo.c @@ -12,71 +12,74 @@ #include "opal_config.h" #include <assert.h> -#include "support.h" #include "opal/class/opal_lifo.h" -#include "opal/runtime/opal.h" #include "opal/constants.h" #include "opal/mca/threads/threads.h" +#include "opal/runtime/opal.h" +#include "support.h" -#include <stdlib.h> -#include <stdio.h> #include <stddef.h> +#include <stdio.h> +#include <stdlib.h> #include <sys/time.h> #define OPAL_LIFO_TEST_THREAD_COUNT 8 -#define ITERATIONS 1000000 -#define ITEM_COUNT 100 +#define ITERATIONS 1000000 +#define ITEM_COUNT 100 #if !defined(timersub) -#define timersub(a, b, r) \ - do { \ - (r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - if ((a)->tv_usec < (b)->tv_usec) { \ - (r)->tv_sec--; \ - (a)->tv_usec += 1000000; \ - } \ - (r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - } while (0) +# define timersub(a, b, r) \ + do { \ + (r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + if ((a)->tv_usec < (b)->tv_usec) { \ + (r)->tv_sec--; \ + (a)->tv_usec += 1000000; \ + } \ + (r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + } while (0) #endif -static void *thread_test (opal_object_t *arg) { +static void *thread_test(opal_object_t *arg) +{ opal_thread_t *t = (opal_thread_t *) arg; opal_lifo_t *lifo = (opal_lifo_t *) t->t_arg; opal_list_item_t *item; struct timeval start, stop, total; double timing; - gettimeofday (&start, NULL); - for (int i = 0 ; i < ITERATIONS ; ++i) { - item = opal_lifo_pop_atomic (lifo); + gettimeofday(&start, NULL); + for (int i = 0; i < ITERATIONS; ++i) { + item = opal_lifo_pop_atomic(lifo); if (NULL != item) { - (void) opal_lifo_push_atomic (lifo, item); + (void) opal_lifo_push_atomic(lifo, item); } } - gettimeofday (&stop, NULL); + gettimeofday(&stop, NULL); timersub(&stop, &start, &total); timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) ITERATIONS; - printf ("Atomics thread finished. Time: %d s %d us %d nsec/poppush\n", (int) total.tv_sec, - (int)total.tv_usec, (int)(timing / 1e-9)); + printf("Atomics thread finished. Time: %d s %d us %d nsec/poppush\n", (int) total.tv_sec, + (int) total.tv_usec, (int) (timing / 1e-9)); return NULL; } -static bool check_lifo_consistency (opal_lifo_t *lifo, int expected_count) +static bool check_lifo_consistency(opal_lifo_t *lifo, int expected_count) { opal_list_item_t *item; int count; - for (count = 0, item = (opal_list_item_t *) lifo->opal_lifo_head.data.item ; item != &lifo->opal_lifo_ghost ; - item = opal_list_get_next(item), count++); + for (count = 0, item = (opal_list_item_t *) lifo->opal_lifo_head.data.item; + item != &lifo->opal_lifo_ghost; item = opal_list_get_next(item), count++) + ; return count == expected_count; } -int main (int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ opal_thread_t threads[OPAL_LIFO_TEST_THREAD_COUNT]; opal_list_item_t *item, *prev, *item2; struct timeval start, stop, total; @@ -85,11 +88,11 @@ int main (int argc, char *argv[]) { double timing; int rc; - rc = opal_init_util (&argc, &argv); + rc = opal_init_util(&argc, &argv); test_verify_int(OPAL_SUCCESS, rc); if (OPAL_SUCCESS != rc) { test_finalize(); - exit (1); + exit(1); } test_init("opal_lifo_t"); @@ -97,94 +100,96 @@ int main (int argc, char *argv[]) { OBJ_CONSTRUCT(&lifo, opal_lifo_t); item = OBJ_NEW(opal_list_item_t); - prev = opal_lifo_push_st (&lifo, item); + prev = opal_lifo_push_st(&lifo, item); if (&lifo.opal_lifo_ghost == prev) { - test_success (); + test_success(); } else { - test_failure (" opal_lifo_push_st on empty lifo"); + test_failure(" opal_lifo_push_st on empty lifo"); } - item2 = opal_lifo_pop_st (&lifo); + item2 = opal_lifo_pop_st(&lifo); if (item == item2) { - test_success (); + test_success(); } else { - test_failure (" opal_lifo_pop_st"); + test_failure(" opal_lifo_pop_st"); } OBJ_RELEASE(item); - for (int i = 0 ; i < ITEM_COUNT ; ++i) { + for (int i = 0; i < ITEM_COUNT; ++i) { item = OBJ_NEW(opal_list_item_t); item->item_free = 0; - opal_lifo_push_st (&lifo, item); + opal_lifo_push_st(&lifo, item); } - if (check_lifo_consistency (&lifo, ITEM_COUNT)) { - test_success (); + if (check_lifo_consistency(&lifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" opal_lifo_push_st(multiple items)"); + test_failure(" opal_lifo_push_st(multiple items)"); } - gettimeofday (&start, NULL); - for (int i = 0 ; i < ITERATIONS ; ++i) { - item = opal_lifo_pop_st (&lifo); - (void) opal_lifo_push_st (&lifo, item); + gettimeofday(&start, NULL); + for (int i = 0; i < ITERATIONS; ++i) { + item = opal_lifo_pop_st(&lifo); + (void) opal_lifo_push_st(&lifo, item); } - gettimeofday (&stop, NULL); + gettimeofday(&stop, NULL); timersub(&stop, &start, &total); timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) ITERATIONS; - if (check_lifo_consistency (&lifo, ITEM_COUNT)) { - test_success (); + if (check_lifo_consistency(&lifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" lifo push/pop"); + test_failure(" lifo push/pop"); } - printf ("Single thread test. Time: %d s %d us %d nsec/poppush\n", (int) total.tv_sec, - (int)total.tv_usec, (int)(timing / 1e-9)); + printf("Single thread test. Time: %d s %d us %d nsec/poppush\n", (int) total.tv_sec, + (int) total.tv_usec, (int) (timing / 1e-9)); threads[0].t_arg = &lifo; - thread_test ((opal_object_t *) &threads[0]); + thread_test((opal_object_t *) &threads[0]); - if (check_lifo_consistency (&lifo, ITEM_COUNT)) { - test_success (); + if (check_lifo_consistency(&lifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" lifo push/pop single-threaded with atomics"); + test_failure(" lifo push/pop single-threaded with atomics"); } - gettimeofday (&start, NULL); - for (int i = 0 ; i < OPAL_LIFO_TEST_THREAD_COUNT ; ++i) { + gettimeofday(&start, NULL); + for (int i = 0; i < OPAL_LIFO_TEST_THREAD_COUNT; ++i) { OBJ_CONSTRUCT(&threads[i], opal_thread_t); threads[i].t_run = thread_test; threads[i].t_arg = &lifo; - opal_thread_start (threads + i); + opal_thread_start(threads + i); } - for (int i = 0 ; i < OPAL_LIFO_TEST_THREAD_COUNT ; ++i) { + for (int i = 0; i < OPAL_LIFO_TEST_THREAD_COUNT; ++i) { void *ret; - opal_thread_join (threads + i, &ret); + opal_thread_join(threads + i, &ret); } - gettimeofday (&stop, NULL); + gettimeofday(&stop, NULL); timersub(&stop, &start, &total); - timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) (ITERATIONS * OPAL_LIFO_TEST_THREAD_COUNT); + timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) + / (double) (ITERATIONS * OPAL_LIFO_TEST_THREAD_COUNT); - if (check_lifo_consistency (&lifo, ITEM_COUNT)) { - test_success (); + if (check_lifo_consistency(&lifo, ITEM_COUNT)) { + test_success(); } else { - test_failure (" lifo push/pop multi-threaded with atomics"); + test_failure(" lifo push/pop multi-threaded with atomics"); } - printf ("All threads finished. Thread count: %d Time: %d s %d us %d nsec/poppush\n", - OPAL_LIFO_TEST_THREAD_COUNT, (int) total.tv_sec, (int)total.tv_usec, (int)(timing / 1e-9)); + printf("All threads finished. Thread count: %d Time: %d s %d us %d nsec/poppush\n", + OPAL_LIFO_TEST_THREAD_COUNT, (int) total.tv_sec, (int) total.tv_usec, + (int) (timing / 1e-9)); success = true; - for (int i = 0 ; i < ITEM_COUNT ; ++i) { - item = opal_lifo_pop_st (&lifo); + for (int i = 0; i < ITEM_COUNT; ++i) { + item = opal_lifo_pop_st(&lifo); if (NULL == item) { success = false; break; @@ -193,14 +198,14 @@ int main (int argc, char *argv[]) { } if (success) { - test_success (); + test_success(); } else { - test_failure (" list pop all items"); + test_failure(" list pop all items"); } OBJ_DESTRUCT(&lifo); - opal_finalize_util (); + opal_finalize_util(); - return test_finalize (); + return test_finalize(); } diff --git a/test/class/opal_list.c b/test/class/opal_list.c index e8e171c079..2c5799e768 100644 --- a/test/class/opal_list.c +++ b/test/class/opal_list.c @@ -20,10 +20,10 @@ #include "opal_config.h" #include <assert.h> -#include "support.h" #include "opal/class/opal_list.h" -#include "opal/runtime/opal.h" #include "opal/constants.h" +#include "opal/runtime/opal.h" +#include "support.h" /* * Data type used for testing @@ -35,15 +35,13 @@ typedef struct test_data { size_t data; } test_data_t; -OBJ_CLASS_INSTANCE(test_data_t, - opal_list_item_t, - NULL, NULL); +OBJ_CLASS_INSTANCE(test_data_t, opal_list_item_t, NULL, NULL); int main(int argc, char **argv) { /* local variables */ opal_list_t list, x; - size_t indx,i,list_size, tmp_size_1, tmp_size_2,size_elements; + size_t indx, i, list_size, tmp_size_1, tmp_size_2, size_elements; int error_cnt, rc; test_data_t *elements, *ele; opal_list_item_t *item; @@ -62,8 +60,8 @@ int main(int argc, char **argv) OBJ_CONSTRUCT(&x, opal_list_t); /* check length of list */ - list_size=opal_list_get_size(&list); - if( 0 == list_size ) { + list_size = opal_list_get_size(&list); + if (0 == list_size) { test_success(); } else { test_failure(" opal_list_get_size"); @@ -77,20 +75,20 @@ int main(int argc, char **argv) } /* create test elements */ - size_elements=4; - elements=(test_data_t *)malloc(sizeof(test_data_t)*size_elements); + size_elements = 4; + elements = (test_data_t *) malloc(sizeof(test_data_t) * size_elements); assert(elements); - for(i=0 ; i < size_elements ; i++) { + for (i = 0; i < size_elements; i++) { OBJ_CONSTRUCT(elements + i, test_data_t); - (elements+i)->data=i; + (elements + i)->data = i; } /* populate list */ - for(i=0 ; i < size_elements ; i++) { - opal_list_append(&list,(opal_list_item_t *)(elements+i)); + for (i = 0; i < size_elements; i++) { + opal_list_append(&list, (opal_list_item_t *) (elements + i)); } - list_size=opal_list_get_size(&list); - if( list_size == size_elements ) { + list_size = opal_list_get_size(&list); + if (list_size == size_elements) { test_success(); } else { test_failure(" populating list"); @@ -104,210 +102,209 @@ int main(int argc, char **argv) } /* check that list is ordered as expected */ - i=0; - error_cnt=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { - if( ele->data != i ) + i = 0; + error_cnt = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { + if (ele->data != i) error_cnt++; i++; } - if( 0 == error_cnt ) { + if (0 == error_cnt) { test_success(); } else { test_failure(" error in list order "); } /* check opal_list_get_first */ - ele = (test_data_t *)NULL; + ele = (test_data_t *) NULL; ele = (test_data_t *) opal_list_get_first(&list); assert(ele); - if( 0 == ele->data ) { + if (0 == ele->data) { test_success(); } else { test_failure(" error in opal_list_get_first"); } - i=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { + i = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { i++; } - if( size_elements == i ) { + if (size_elements == i) { test_success(); } else { test_failure(" error in opal_list_get_first - list size changed "); } /* check opal_list_get_last */ - ele = (test_data_t *)NULL; + ele = (test_data_t *) NULL; ele = (test_data_t *) opal_list_get_last(&list); assert(ele); - if( (size_elements-1) == ele->data ) { + if ((size_elements - 1) == ele->data) { test_success(); } else { test_failure(" error in opal_list_get_last"); } - i=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { + i = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { i++; } - if( size_elements == i ) { + if (size_elements == i) { test_success(); } else { test_failure(" error in opal_list_get_first - list size changed "); } /* check opal_list_remove_first */ - ele = (test_data_t *)NULL; + ele = (test_data_t *) NULL; ele = (test_data_t *) opal_list_remove_first(&list); assert(ele); - if( 0 == ele->data ) { + if (0 == ele->data) { test_success(); } else { test_failure(" error in opal_list_remove_first"); } - i=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { + i = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { i++; } - if( (size_elements-1) == i ) { + if ((size_elements - 1) == i) { test_success(); } else { test_failure(" error in opal_list_remove_first - list size changed "); } /* test opal_list_prepend */ - opal_list_prepend(&list,(opal_list_item_t *)elements); - ele = (test_data_t *)NULL; + opal_list_prepend(&list, (opal_list_item_t *) elements); + ele = (test_data_t *) NULL; ele = (test_data_t *) opal_list_get_first(&list); assert(ele); - if( 0 == ele->data ) { + if (0 == ele->data) { test_success(); } else { test_failure(" error in opal_list_prepend"); } - i=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { + i = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { i++; } - if( size_elements == i ) { + if (size_elements == i) { test_success(); } else { test_failure(" error in opal_list_prepend - list size changed "); } /* check opal_list_remove_last */ - ele = (test_data_t *)NULL; + ele = (test_data_t *) NULL; ele = (test_data_t *) opal_list_remove_last(&list); assert(ele); - if( (size_elements-1) == ele->data ) { + if ((size_elements - 1) == ele->data) { test_success(); } else { test_failure(" error in opal_list_remove_last"); } - i=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { + i = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { i++; } - if( (size_elements-1) == i ) { + if ((size_elements - 1) == i) { test_success(); } else { test_failure(" error in opal_list_remove_last - list size changed "); } /* test opal_list_append */ - opal_list_append(&list,(opal_list_item_t *)(elements+size_elements-1)); - ele = (test_data_t *)NULL; + opal_list_append(&list, (opal_list_item_t *) (elements + size_elements - 1)); + ele = (test_data_t *) NULL; ele = (test_data_t *) opal_list_get_last(&list); assert(ele); - if( (size_elements-1) == ele->data ) { + if ((size_elements - 1) == ele->data) { test_success(); } else { test_failure(" error in opal_list_append"); } - i=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { + i = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { i++; } - if( size_elements == i ) { + if (size_elements == i) { test_success(); } else { test_failure(" error in opal_list_append - list size changed "); } /* remove element from list */ - indx=size_elements/2; - if( 0 == indx ) - indx=1; + indx = size_elements / 2; + if (0 == indx) + indx = 1; assert(2 <= size_elements); - ele = (test_data_t *)NULL; - ele = (test_data_t *) - opal_list_remove_item(&list,(opal_list_item_t *)(elements+indx)); + ele = (test_data_t *) NULL; + ele = (test_data_t *) opal_list_remove_item(&list, (opal_list_item_t *) (elements + indx)); assert(ele); - if( (indx-1) == ele->data ) { + if ((indx - 1) == ele->data) { test_success(); } else { test_failure(" error in opal_list_remove - previous"); } - ele=(test_data_t *)(((opal_list_item_t *)ele)->opal_list_next); - if( (indx+1) == ele->data ) { + ele = (test_data_t *) (((opal_list_item_t *) ele)->opal_list_next); + if ((indx + 1) == ele->data) { test_success(); } else { test_failure(" error in opal_list_remove - next"); } - i=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { + i = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { i++; } - if( (size_elements-1) == i ) { + if ((size_elements - 1) == i) { test_success(); } else { test_failure(" error in opal_list_remove - list size changed incorrectly"); } /* test the insert function */ - i=opal_list_insert(&list,(opal_list_item_t *)(elements+indx),indx); - if( 1 == i ) { + i = opal_list_insert(&list, (opal_list_item_t *) (elements + indx), indx); + if (1 == i) { test_success(); } else { test_failure(" error in opal_list_remove_item \n"); } - i=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { + i = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { i++; } - if( size_elements == i ) { + if (size_elements == i) { test_success(); } else { test_failure(" error in opal_list_insert - incorrect list length"); } - i=0; - error_cnt=0; - for(ele = (test_data_t *) opal_list_get_first(&list); - ele != (test_data_t *) opal_list_get_end(&list); - ele = (test_data_t *) ((opal_list_item_t *)ele)->opal_list_next) { - if( ele->data != i ) + i = 0; + error_cnt = 0; + for (ele = (test_data_t *) opal_list_get_first(&list); + ele != (test_data_t *) opal_list_get_end(&list); + ele = (test_data_t *) ((opal_list_item_t *) ele)->opal_list_next) { + if (ele->data != i) error_cnt++; i++; } - if( 0 == error_cnt ) { + if (0 == error_cnt) { test_success(); } else { test_failure(" error in list order - opal_list_remove_item "); @@ -315,11 +312,10 @@ int main(int argc, char **argv) /* test the splice and join functions */ list_size = opal_list_get_size(&list); - for (i = 0, item = opal_list_get_first(&list) ; - i < list_size / 2 ; ++i, item = opal_list_get_next(item)) { + for (i = 0, item = opal_list_get_first(&list); i < list_size / 2; + ++i, item = opal_list_get_next(item)) { } - opal_list_splice(&x, opal_list_get_end(&x), - &list, item, opal_list_get_end(&list)); + opal_list_splice(&x, opal_list_get_end(&x), &list, item, opal_list_get_end(&list)); tmp_size_1 = opal_list_get_size(&list); tmp_size_2 = opal_list_get_size(&x); if (tmp_size_1 != i) { @@ -341,9 +337,10 @@ int main(int argc, char **argv) test_success(); } - if (NULL != elements) free(elements); + if (NULL != elements) + free(elements); - opal_finalize_util (); + opal_finalize_util(); return test_finalize(); } diff --git a/test/class/opal_pointer_array.c b/test/class/opal_pointer_array.c index 5c7bec1860..b0ce90b2a5 100644 --- a/test/class/opal_pointer_array.c +++ b/test/class/opal_pointer_array.c @@ -24,25 +24,26 @@ */ #include "opal_config.h" -#include <stdlib.h> -#include <stdio.h> #include <assert.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> -#include "support.h" #include "opal/class/opal_pointer_array.h" +#include "support.h" typedef union { int ivalue; char *cvalue; } value_t; -static void test(bool thread_usage){ +static void test(bool thread_usage) +{ /* local variables */ opal_pointer_array_t *array; value_t *test_data; - int len_test_data,i,test_len_in_array,error_cnt; + int len_test_data, i, test_len_in_array, error_cnt; int ele_index; int error_code; value_t value; @@ -50,39 +51,39 @@ static void test(bool thread_usage){ /* initialize thread levels */ opal_set_using_threads(thread_usage); - array=OBJ_NEW(opal_pointer_array_t); + array = OBJ_NEW(opal_pointer_array_t); assert(array); - len_test_data=5; - test_data=malloc(sizeof(value_t)*len_test_data); + len_test_data = 5; + test_data = malloc(sizeof(value_t) * len_test_data); assert(test_data); - for(i=0 ; i < len_test_data ; i++ ) { - test_data[i].ivalue = (i+1); + for (i = 0; i < len_test_data; i++) { + test_data[i].ivalue = (i + 1); } /* add data to table */ - test_len_in_array=3; - assert(len_test_data>=test_len_in_array); - for(i=0 ; i < test_len_in_array ; i++ ) { - opal_pointer_array_add(array,test_data[i].cvalue); + test_len_in_array = 3; + assert(len_test_data >= test_len_in_array); + for (i = 0; i < test_len_in_array; i++) { + opal_pointer_array_add(array, test_data[i].cvalue); } /* check to see that test_len_in_array are in array */ - if( (array->size - array->number_free) == test_len_in_array) { + if ((array->size - array->number_free) == test_len_in_array) { test_success(); } else { test_failure("check on number of elements in array"); } /* check order of data */ - error_cnt=0; - for(i=0 ; i < test_len_in_array ; i++ ) { + error_cnt = 0; + for (i = 0; i < test_len_in_array; i++) { value.cvalue = array->addr[i]; - if( (i+1) != value.ivalue ) { + if ((i + 1) != value.ivalue) { error_cnt++; } } - if( 0 == error_cnt ) { + if (0 == error_cnt) { test_success(); } else { test_failure(" data check "); @@ -90,19 +91,19 @@ static void test(bool thread_usage){ /* free 2nd element and make sure that value is reset correctly, * and that the lowest_index is also reset correctly */ - ele_index=1; - error_code=opal_pointer_array_set_item(array,ele_index,NULL); - if( 0 == error_code ) { + ele_index = 1; + error_code = opal_pointer_array_set_item(array, ele_index, NULL); + if (0 == error_code) { test_success(); } else { test_failure(" opal_pointer_array_set_item "); } - if( NULL == array->addr[ele_index]){ + if (NULL == array->addr[ele_index]) { test_success(); } else { test_failure(" set pointer value"); } - if( ele_index == array->lowest_free ) { + if (ele_index == array->lowest_free) { test_success(); } else { test_failure(" lowest free "); @@ -110,28 +111,28 @@ static void test(bool thread_usage){ /* test opal_pointer_array_get_item */ opal_pointer_array_remove_all(array); - error_cnt=0; - for(i=0 ; i < array->size ; i++ ) { + error_cnt = 0; + for (i = 0; i < array->size; i++) { value.ivalue = i + 2; - ele_index=opal_pointer_array_add(array, value.cvalue); - if( i != ele_index ) { + ele_index = opal_pointer_array_add(array, value.cvalue); + if (i != ele_index) { error_cnt++; } } - if( 0 == error_cnt ) { + if (0 == error_cnt) { test_success(); } else { test_failure(" opal_pointer_array_add 2nd "); } - error_cnt=0; - for(i=0 ; i < array->size ; i++ ) { - value.cvalue = opal_pointer_array_get_item(array,i); - if( (i+2) != value.ivalue ) { + error_cnt = 0; + for (i = 0; i < array->size; i++) { + value.cvalue = opal_pointer_array_get_item(array, i); + if ((i + 2) != value.ivalue) { error_cnt++; } } - if( 0 == error_cnt ) { + if (0 == error_cnt) { test_success(); } else { test_failure(" data check - 2nd "); @@ -140,23 +141,23 @@ static void test(bool thread_usage){ OBJ_RELEASE(array); assert(NULL == array); - array=OBJ_NEW(opal_pointer_array_t); + array = OBJ_NEW(opal_pointer_array_t); assert(array); opal_pointer_array_init(array, 0, 4, 2); - for( i = 0; i < 4; i++ ) { + for (i = 0; i < 4; i++) { value.ivalue = i + 1; - if( 0 > opal_pointer_array_add( array, value.cvalue ) ) { + if (0 > opal_pointer_array_add(array, value.cvalue)) { test_failure("Add/Remove: failure during initial data_add "); } } - for( i = i-1; i >= 0; i-- ) { - if( i % 2 ) - if( 0 != opal_pointer_array_set_item(array, i, NULL) ) + for (i = i - 1; i >= 0; i--) { + if (i % 2) + if (0 != opal_pointer_array_set_item(array, i, NULL)) test_failure("Add/Remove: failure during item removal "); } - for( i = 0; i < 4; i++ ) { - if( !opal_pointer_array_add( array, (void*)(uintptr_t)(i+1) ) ) { - if( i != 2 ) { + for (i = 0; i < 4; i++) { + if (!opal_pointer_array_add(array, (void *) (uintptr_t)(i + 1))) { + if (i != 2) { test_failure("Add/Remove: failure during the readd "); break; } @@ -169,7 +170,6 @@ static void test(bool thread_usage){ free(test_data); } - int main(int argc, char **argv) { test_init("opal_pointer_array"); diff --git a/test/class/opal_proc_table.c b/test/class/opal_proc_table.c index 1720f98848..c6ab08b75d 100644 --- a/test/class/opal_proc_table.c +++ b/test/class/opal_proc_table.c @@ -24,47 +24,32 @@ */ #include "opal_config.h" -#include <stdint.h> -#include <string.h> -#include "support.h" -#include "opal/class/opal_object.h" #include "opal/class/opal_hash_table.h" -#include "opal/runtime/opal.h" +#include "opal/class/opal_object.h" #include "opal/constants.h" +#include "opal/runtime/opal.h" +#include "support.h" +#include <stdint.h> +#include <string.h> -static FILE *error_out=NULL; - -char *num_keys[] = { - "0", "1234", "1234", - "0", "5678", "5678", - "1", "12450", "12450", - "1", "45623", "45623", - NULL -}; - +static FILE *error_out = NULL; -char *str_keys[] = { - "foo", "bar", - "2", "this cow jumped over the moon", - "this is another key", "this is another value", - "key key", "value value", - NULL -}; +char *num_keys[] = {"0", "1234", "1234", "0", "5678", "5678", "1", + "12450", "12450", "1", "45623", "45623", NULL}; +char *str_keys[] = {"foo", + "bar", + "2", + "this cow jumped over the moon", + "this is another key", + "this is another value", + "key key", + "value value", + NULL}; -char *perm_keys[] = { - "abcdef", "abcdef", - "bcdefa", "bcdefa", - "cdefab", "cdefab", - "defabc", "defabc", - "efabcd", "efabcd", - "fabcde", "fabcde", - "badcfe", "badcfe", - "badcef", "badcef", - "abdcfe", "abdcfe", - "bcdaef", "bcdaef", - NULL -}; +char *perm_keys[] = {"abcdef", "abcdef", "bcdefa", "bcdefa", "cdefab", "cdefab", "defabc", + "defabc", "efabcd", "efabcd", "fabcde", "fabcde", "badcfe", "badcfe", + "badcef", "badcef", "abdcfe", "abdcfe", "bcdaef", "bcdaef", NULL}; #if 0 /* @@ -92,19 +77,18 @@ typedef union { static void validate_table(opal_proc_table_t *table, char *keys[]) { - int j, ret; + int j, ret; value_t value; - for ( j = 0; keys[j]; j += 3) { + for (j = 0; keys[j]; j += 3) { opal_process_name_t key; key.jobid = atoi(keys[j]); - key.vpid = atoi(keys[j+1]); - ret = opal_proc_table_get_value(table, key, - (void**) &value.uvalue); + key.vpid = atoi(keys[j + 1]); + ret = opal_proc_table_get_value(table, key, (void **) &value.uvalue); if (OPAL_SUCCESS != ret) { test_failure("opal_proc_table_get_value failed"); } - test_verify_str(keys[j+2], value.vvalue); + test_verify_str(keys[j + 2], value.vvalue); } } @@ -175,44 +159,41 @@ static void test_ptable(opal_proc_table_t *table) { int j; char *n1, *n2; - char * v; + char *v; int rc; opal_process_name_t key; fprintf(error_out, "\nTesting integer keys...\n"); - for ( j = 0; num_keys[j]; j += 3) - { + for (j = 0; num_keys[j]; j += 3) { opal_process_name_t key; key.jobid = atoi(num_keys[j]); - key.vpid = atoi(num_keys[j+1]); - opal_proc_table_set_value(table, key, num_keys[j+2]); + key.vpid = atoi(num_keys[j + 1]); + opal_proc_table_set_value(table, key, num_keys[j + 2]); } validate_table(table, num_keys); - rc = opal_proc_table_get_first_key(table, &key, (void **)&v, (void **)&n1, (void **)&n2); + rc = opal_proc_table_get_first_key(table, &key, (void **) &v, (void **) &n1, (void **) &n2); if (OPAL_SUCCESS != rc) { fprintf(error_out, "*** FAILED opal_proc_table_get_first_key ***\n"); - return ; + return; } - for (j=0; num_keys[j]; j+=3) { + for (j = 0; num_keys[j]; j += 3) { if (OPAL_SUCCESS != rc) { - fprintf(error_out, "*** FAILED opal_proc_table_get_next_key (%d) ***\n", j/3); + fprintf(error_out, "*** FAILED opal_proc_table_get_next_key (%d) ***\n", j / 3); } - if (key.jobid != (opal_jobid_t)atoi(num_keys[j]) || - key.vpid != (opal_vpid_t)atoi(num_keys[j+1]) || - 0 != strcmp(num_keys[j+2], v)) { - fprintf(error_out, "*** FAILED at %d, expected ((%s,%s),%s) got ((%d,%d),%s)\n", j/3, - num_keys[j], num_keys[j+1], num_keys[j+2], - key.jobid, key.vpid, v); + if (key.jobid != (opal_jobid_t) atoi(num_keys[j]) + || key.vpid != (opal_vpid_t) atoi(num_keys[j + 1]) || 0 != strcmp(num_keys[j + 2], v)) { + fprintf(error_out, "*** FAILED at %d, expected ((%s,%s),%s) got ((%d,%d),%s)\n", j / 3, + num_keys[j], num_keys[j + 1], num_keys[j + 2], key.jobid, key.vpid, v); } - rc = opal_proc_table_get_next_key(table, &key, (void **)&v, n1, (void **)&n1, n2, (void **)&n2); + rc = opal_proc_table_get_next_key(table, &key, (void **) &v, n1, (void **) &n1, n2, + (void **) &n2); } if (OPAL_SUCCESS == rc) { - fprintf(error_out, "*** DID NOT FAIL last opal_proc_table_get_next_key %d\n", j/3); + fprintf(error_out, "*** DID NOT FAIL last opal_proc_table_get_next_key %d\n", j / 3); return; } - #if 0 /* remove all values for next test */ opal_proc_table_remove_all(table); @@ -242,14 +223,12 @@ static void test_ptable(opal_proc_table_t *table) fprintf(error_out, "\n\n"); } - static void test_dynamic(void) { - opal_proc_table_t *table; + opal_proc_table_t *table; table = OBJ_NEW(opal_proc_table_t); - if ( NULL == table ) - { + if (NULL == table) { fprintf(error_out, "Error: Unable to create hash table.\n"); exit(-1); } @@ -260,10 +239,9 @@ static void test_dynamic(void) OBJ_RELEASE(table); } - static void test_static(void) { - opal_proc_table_t table; + opal_proc_table_t table; OBJ_CONSTRUCT(&table, opal_proc_table_t); opal_proc_table_init(&table, 8, 128); @@ -274,7 +252,6 @@ static void test_static(void) OBJ_DESTRUCT(&table); } - int main(int argc, char **argv) { int rc; @@ -291,17 +268,18 @@ int main(int argc, char **argv) #ifdef STANDALONE error_out = stderr; #else - error_out = fopen( "./opal_proc_table_test_out.txt", "w" ); - if( error_out == NULL ) error_out = stderr; + error_out = fopen("./opal_proc_table_test_out.txt", "w"); + if (error_out == NULL) + error_out = stderr; #endif test_dynamic(); test_static(); #ifndef STANDALONE - fclose( error_out ); + fclose(error_out); #endif - opal_finalize_util (); + opal_finalize_util(); return test_finalize(); } diff --git a/test/class/opal_value_array.c b/test/class/opal_value_array.c index be09ce4ca7..2145e2fabc 100644 --- a/test/class/opal_value_array.c +++ b/test/class/opal_value_array.c @@ -22,18 +22,17 @@ */ #include "opal_config.h" -#include <stdlib.h> -#include <stdio.h> #include <assert.h> +#include <stdio.h> +#include <stdlib.h> #include <string.h> -#include "support.h" #include "opal/class/opal_value_array.h" #include "opal/runtime/opal.h" +#include "support.h" #define NUM_ITEMS 10 - int main(int argc, char **argv) { uint64_t i, val; @@ -55,13 +54,13 @@ int main(int argc, char **argv) test_verify_int(0, opal_value_array_get_size(&array)); /* add several items to the array */ - for(i=0; i < NUM_ITEMS; i++) { + for (i = 0; i < NUM_ITEMS; i++) { opal_value_array_append_item(&array, &i); } test_verify_int(NUM_ITEMS, opal_value_array_get_size(&array)); /* verify contents */ - for(i=0; i < NUM_ITEMS; i++) { + for (i = 0; i < NUM_ITEMS; i++) { val = OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i); if (val != i) { test_failure("Comparison failure"); @@ -80,12 +79,12 @@ int main(int argc, char **argv) /* initialize array */ count = 0; - for(i=0; i < NUM_ITEMS; i++) { + for (i = 0; i < NUM_ITEMS; i++) { OPAL_VALUE_ARRAY_SET_ITEM(&array, uint64_t, i, count++); } /* grow it */ - for(i=0; i < NUM_ITEMS; i++) { + for (i = 0; i < NUM_ITEMS; i++) { opal_value_array_append_item(&array, &count); count++; } @@ -93,7 +92,7 @@ int main(int argc, char **argv) test_verify_int(count, opal_value_array_get_size(&array)); /* validate contents */ - for(i=0; i < count; i++) { + for (i = 0; i < count; i++) { test_verify_int(i, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i)); } @@ -101,12 +100,12 @@ int main(int argc, char **argv) opal_value_array_remove_item(&array, NUM_ITEMS); /* check size */ - test_verify_int(count-1, opal_value_array_get_size(&array)); + test_verify_int(count - 1, opal_value_array_get_size(&array)); /* validate contents */ - for(i=0; i < count-1; i++) { - if(i >= NUM_ITEMS) { - test_verify_int(i+1, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i)); + for (i = 0; i < count - 1; i++) { + if (i >= NUM_ITEMS) { + test_verify_int(i + 1, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i)); } else { test_verify_int(i, OPAL_VALUE_ARRAY_GET_ITEM(&array, uint64_t, i)); } @@ -114,7 +113,7 @@ int main(int argc, char **argv) OBJ_DESTRUCT(&array); - opal_finalize_util (); + opal_finalize_util(); return test_finalize(); } diff --git a/test/datatype/checksum.c b/test/datatype/checksum.c index f470c920de..4c8a60bf91 100644 --- a/test/datatype/checksum.c +++ b/test/datatype/checksum.c @@ -13,8 +13,8 @@ */ #include "ompi_config.h" -#include "opal/datatype/opal_convertor.h" #include "ompi/datatype/ompi_datatype.h" +#include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype_checksum.h" #include "opal/runtime/opal.h" @@ -29,34 +29,34 @@ typedef struct { int useless; } my_data_t; -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { MPI_Datatype sparse; int *array, *packed; - my_data_t* sparse_array; + my_data_t *sparse_array; int i; uint32_t iov_count; size_t max_data; uint32_t pack_checksum, contiguous_checksum, sparse_checksum, manual_checksum; struct iovec iov[2]; - opal_convertor_t* convertor; + opal_convertor_t *convertor; - opal_init_util (NULL, NULL); + opal_init_util(NULL, NULL); ompi_datatype_init(); - srandom( (int)time(NULL) ); + srandom((int) time(NULL)); /*srandomdev();*/ - ompi_datatype_create_vector( SIZE, 1, 2, MPI_INT, &sparse ); - ompi_datatype_commit( &sparse ); + ompi_datatype_create_vector(SIZE, 1, 2, MPI_INT, &sparse); + ompi_datatype_commit(&sparse); - sparse_array = (my_data_t*)malloc( sizeof(my_data_t) * SIZE ); - array = (int*)malloc( sizeof(int) * SIZE ); - packed = (int*)malloc( sizeof(int) * SIZE ); + sparse_array = (my_data_t *) malloc(sizeof(my_data_t) * SIZE); + array = (int *) malloc(sizeof(int) * SIZE); + packed = (int *) malloc(sizeof(int) * SIZE); /** * Initialize the sparse data using the index. */ - for( i = 0; i < SIZE; i++ ) { + for (i = 0; i < SIZE; i++) { sparse_array[i].useful = random(); sparse_array[i].useless = 0; } @@ -65,16 +65,16 @@ int main( int argc, char* argv[] ) * Pack the sparse data into the packed array. This simulate the first step * of the buffered operation. */ - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_personalize( convertor, CONVERTOR_WITH_CHECKSUM, NULL ); - opal_convertor_prepare_for_send( convertor, &(sparse->super), SIZE, sparse_array ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_personalize(convertor, CONVERTOR_WITH_CHECKSUM, NULL); + opal_convertor_prepare_for_send(convertor, &(sparse->super), SIZE, sparse_array); iov[0].iov_base = packed; iov[0].iov_len = sizeof(int) * SIZE; max_data = iov[0].iov_len; iov_count = 1; - opal_convertor_pack( convertor, iov, &iov_count, &max_data ); + opal_convertor_pack(convertor, iov, &iov_count, &max_data); pack_checksum = convertor->checksum; OBJ_RELEASE(convertor); @@ -83,16 +83,16 @@ int main( int argc, char* argv[] ) * Now move the data from the packed array into the fragment to * be sent over the network (still simulation). */ - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_personalize( convertor, CONVERTOR_WITH_CHECKSUM, NULL ); - opal_convertor_prepare_for_send( convertor, &(ompi_mpi_int.dt.super), SIZE, packed ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_personalize(convertor, CONVERTOR_WITH_CHECKSUM, NULL); + opal_convertor_prepare_for_send(convertor, &(ompi_mpi_int.dt.super), SIZE, packed); iov[0].iov_base = array; iov[0].iov_len = sizeof(int) * SIZE; max_data = iov[0].iov_len; iov_count = 1; - opal_convertor_pack( convertor, iov, &iov_count, &max_data ); + opal_convertor_pack(convertor, iov, &iov_count, &max_data); contiguous_checksum = convertor->checksum; OBJ_RELEASE(convertor); @@ -102,18 +102,18 @@ int main( int argc, char* argv[] ) * the network and now we unpack it in the user memory using 2 * separate iovec. */ - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_personalize( convertor, CONVERTOR_WITH_CHECKSUM, NULL ); - opal_convertor_prepare_for_recv( convertor, &(sparse->super), SIZE, sparse_array ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_personalize(convertor, CONVERTOR_WITH_CHECKSUM, NULL); + opal_convertor_prepare_for_recv(convertor, &(sparse->super), SIZE, sparse_array); max_data = sizeof(int) * SIZE; iov[0].iov_base = array; iov[0].iov_len = max_data / 2; - iov[1].iov_base = (char*)array + iov[0].iov_len; + iov[1].iov_base = (char *) array + iov[0].iov_len; iov[1].iov_len = max_data - iov[0].iov_len; iov_count = 2; - opal_convertor_unpack( convertor, iov, &iov_count, &max_data ); + opal_convertor_unpack(convertor, iov, &iov_count, &max_data); sparse_checksum = convertor->checksum; OBJ_RELEASE(convertor); @@ -126,15 +126,14 @@ int main( int argc, char* argv[] ) /** * The 3 checksum have to match. */ - printf( "contiguous checksum %x\n", contiguous_checksum ); - printf( "packed checksum %x\n", pack_checksum ); - printf( "sparse checksum %x\n", sparse_checksum ); - if( (sparse_checksum != contiguous_checksum) || - (pack_checksum != sparse_checksum) ) { - printf( "ERROR!!! the checksum algorithm does not work as expected\n" ); + printf("contiguous checksum %x\n", contiguous_checksum); + printf("packed checksum %x\n", pack_checksum); + printf("sparse checksum %x\n", sparse_checksum); + if ((sparse_checksum != contiguous_checksum) || (pack_checksum != sparse_checksum)) { + printf("ERROR!!! the checksum algorithm does not work as expected\n"); return 1; } - printf( "COOL the 3 checksum match\n" ); + printf("COOL the 3 checksum match\n"); /** * Now that the packed buffer contain the data we want, let's try to call @@ -143,9 +142,9 @@ int main( int argc, char* argv[] ) { uint32_t ui1 = 0; size_t ui2 = 0; - manual_checksum = OPAL_CSUM_PARTIAL( packed, sizeof(int) * SIZE, &ui1, &ui2 ); + manual_checksum = OPAL_CSUM_PARTIAL(packed, sizeof(int) * SIZE, &ui1, &ui2); } - printf( "manual checksum %x\n", manual_checksum ); + printf("manual checksum %x\n", manual_checksum); free(sparse_array); free(array); @@ -153,7 +152,7 @@ int main( int argc, char* argv[] ) /* clean-ups all data allocations */ ompi_datatype_finalize(); - opal_finalize_util (); + opal_finalize_util(); return 0; } diff --git a/test/datatype/ddt_lib.c b/test/datatype/ddt_lib.c index ffdee2b57f..0a0e9dc7e0 100644 --- a/test/datatype/ddt_lib.c +++ b/test/datatype/ddt_lib.c @@ -24,17 +24,18 @@ #include "ompi_config.h" #include "ddt_lib.h" #include "ompi/constants.h" -#include <time.h> #include <stdlib.h> +#include <time.h> #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #endif #include <stdio.h> #include <string.h> #define TIMER_DATA_TYPE struct timeval -#define GET_TIME(TV) gettimeofday( &(TV), NULL ) -#define ELAPSED_TIME(TSTART, TEND) (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) +#define GET_TIME(TV) gettimeofday(&(TV), NULL) +#define ELAPSED_TIME(TSTART, TEND) \ + (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) #define DUMP_DATA_AFTER_COMMIT 0x00000001 #define CHECK_PACK_UNPACK 0x00000002 @@ -44,168 +45,165 @@ uint32_t outputFlags = CHECK_PACK_UNPACK | VALIDATE_DATA; /** * Cache cleanup. */ -#define CACHE_SIZE (4*1024*1024) -void cache_trash( void ) +#define CACHE_SIZE (4 * 1024 * 1024) +void cache_trash(void) { - char* buffer; + char *buffer; - buffer = (char*)malloc( sizeof(char) * CACHE_SIZE ); - memset( buffer, 1, CACHE_SIZE ); - memset( buffer, 0xff, CACHE_SIZE ); - free( buffer ); + buffer = (char *) malloc(sizeof(char) * CACHE_SIZE); + memset(buffer, 1, CACHE_SIZE); + memset(buffer, 0xff, CACHE_SIZE); + free(buffer); } /** * Data-type functions. */ -ompi_datatype_t* create_inversed_vector( const ompi_datatype_t* type, int length ) +ompi_datatype_t *create_inversed_vector(const ompi_datatype_t *type, int length) { - ompi_datatype_t* type1; + ompi_datatype_t *type1; - ompi_datatype_create_vector( length, 1, 2, type, &type1 ); + ompi_datatype_create_vector(length, 1, 2, type, &type1); - ompi_datatype_commit( &type1 ); - return type1; + ompi_datatype_commit(&type1); + return type1; } -void print_double_mat( unsigned int N, double* mat ) +void print_double_mat(unsigned int N, double *mat) { - unsigned int i, j; - double* pMat; - - for( i = 0; i < N; i++ ) { - printf( "(%4d) :", i * N * (int)sizeof(double) ); - pMat = mat + i * N; - for( j = 0; j < N; j++ ) { - printf( "%5.1f ", *pMat ); - pMat++; - } - printf( "\n" ); - } + unsigned int i, j; + double *pMat; + + for (i = 0; i < N; i++) { + printf("(%4d) :", i * N * (int) sizeof(double)); + pMat = mat + i * N; + for (j = 0; j < N; j++) { + printf("%5.1f ", *pMat); + pMat++; + } + printf("\n"); + } } -int init_random_upper_matrix( unsigned int N, double* mat ) +int init_random_upper_matrix(unsigned int N, double *mat) { unsigned int i, j; - srand( time(NULL) ); - for( i = 0; i < N; i++ ) { + srand(time(NULL)); + for (i = 0; i < N; i++) { mat += i; - for( j = i; j < N; j++ ) { - *mat = (double)random(); + for (j = i; j < N; j++) { + *mat = (double) random(); mat++; } } return OMPI_SUCCESS; } -int check_diag_matrix( unsigned int N, double* mat1, double* mat2 ) +int check_diag_matrix(unsigned int N, double *mat1, double *mat2) { - unsigned int i, j; - - for( i = 0; i < N; i++ ) { - mat1 += i; - mat2 += i; - for( j = i; j < N; j++ ) { - if( *mat1 != *mat2 ) { - printf( "error in position (%d, %d) expect %f and find %f\n", - i, j, *mat1, *mat2 ); - printf( "hex %lx != %lx\n", *(long*)mat1, *(long*)mat2 ); - return OMPI_ERROR; - } - mat1++; mat2++; - } - } - return OMPI_SUCCESS; + unsigned int i, j; + + for (i = 0; i < N; i++) { + mat1 += i; + mat2 += i; + for (j = i; j < N; j++) { + if (*mat1 != *mat2) { + printf("error in position (%d, %d) expect %f and find %f\n", i, j, *mat1, *mat2); + printf("hex %lx != %lx\n", *(long *) mat1, *(long *) mat2); + return OMPI_ERROR; + } + mat1++; + mat2++; + } + } + return OMPI_SUCCESS; } -ompi_datatype_t* upper_matrix( unsigned int mat_size ) +ompi_datatype_t *upper_matrix(unsigned int mat_size) { int *disp, *blocklen; unsigned int i; - ompi_datatype_t* upper; + ompi_datatype_t *upper; - disp = (int*)malloc( sizeof(int) * mat_size ); - blocklen = (int*)malloc( sizeof(int) * mat_size ); + disp = (int *) malloc(sizeof(int) * mat_size); + blocklen = (int *) malloc(sizeof(int) * mat_size); - for( i = 0; i < mat_size; i++ ) { + for (i = 0; i < mat_size; i++) { disp[i] = i * mat_size + i; blocklen[i] = mat_size - i; } - ompi_datatype_create_indexed( mat_size, blocklen, disp, &ompi_mpi_double.dt, - &upper ); - ompi_datatype_commit( &upper ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( upper ); + ompi_datatype_create_indexed(mat_size, blocklen, disp, &ompi_mpi_double.dt, &upper); + ompi_datatype_commit(&upper); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(upper); } - free( disp ); - free( blocklen ); + free(disp); + free(blocklen); return upper; } -ompi_datatype_t* lower_matrix( unsigned int mat_size ) +ompi_datatype_t *lower_matrix(unsigned int mat_size) { int *disp, *blocklen; unsigned int i; - ompi_datatype_t* upper; + ompi_datatype_t *upper; - disp = (int*)malloc( sizeof(int) * mat_size ); - blocklen = (int*)malloc( sizeof(int) * mat_size ); + disp = (int *) malloc(sizeof(int) * mat_size); + blocklen = (int *) malloc(sizeof(int) * mat_size); - for( i = 0; i < mat_size; i++ ) { + for (i = 0; i < mat_size; i++) { disp[i] = i * mat_size; blocklen[i] = i; } - ompi_datatype_create_indexed( mat_size, blocklen, disp, &ompi_mpi_double.dt, - &upper ); - free( disp ); - free( blocklen ); + ompi_datatype_create_indexed(mat_size, blocklen, disp, &ompi_mpi_double.dt, &upper); + free(disp); + free(blocklen); return upper; } -ompi_datatype_t* test_matrix_borders( unsigned int size, unsigned int width ) +ompi_datatype_t *test_matrix_borders(unsigned int size, unsigned int width) { - ompi_datatype_t *pdt, *pdt_line; - int disp[2]; - int blocklen[2]; - - disp[0] = 0; - blocklen[0] = width; - disp[1] = (size - width) * sizeof(double); - blocklen[1] = width; - - ompi_datatype_create_indexed( 2, blocklen, disp, &ompi_mpi_double.dt, - &pdt_line ); - ompi_datatype_create_contiguous( size, pdt_line, &pdt ); - OBJ_RELEASE( pdt_line ); /*assert( pdt_line == NULL );*/ - return pdt; + ompi_datatype_t *pdt, *pdt_line; + int disp[2]; + int blocklen[2]; + + disp[0] = 0; + blocklen[0] = width; + disp[1] = (size - width) * sizeof(double); + blocklen[1] = width; + + ompi_datatype_create_indexed(2, blocklen, disp, &ompi_mpi_double.dt, &pdt_line); + ompi_datatype_create_contiguous(size, pdt_line, &pdt); + OBJ_RELEASE(pdt_line); /*assert( pdt_line == NULL );*/ + return pdt; } -ompi_datatype_t* test_contiguous( void ) +ompi_datatype_t *test_contiguous(void) { ompi_datatype_t *pdt, *pdt1, *pdt2; - printf( "test contiguous (alignment)\n" ); + printf("test contiguous (alignment)\n"); ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt1); - ompi_datatype_add( pdt1, &ompi_mpi_double.dt, 1, 0, -1 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt1 ); + ompi_datatype_add(pdt1, &ompi_mpi_double.dt, 1, 0, -1); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt1); } - ompi_datatype_add( pdt1, &ompi_mpi_char.dt, 1, 8, -1 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt1 ); + ompi_datatype_add(pdt1, &ompi_mpi_char.dt, 1, 8, -1); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt1); } - ompi_datatype_create_contiguous( 4, pdt1, &pdt2 ); - OBJ_RELEASE( pdt1 ); /*assert( pdt1 == NULL );*/ - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt2 ); + ompi_datatype_create_contiguous(4, pdt1, &pdt2); + OBJ_RELEASE(pdt1); /*assert( pdt1 == NULL );*/ + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt2); } - ompi_datatype_create_contiguous( 2, pdt2, &pdt ); - OBJ_RELEASE( pdt2 ); /*assert( pdt2 == NULL );*/ - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + ompi_datatype_create_contiguous(2, pdt2, &pdt); + OBJ_RELEASE(pdt2); /*assert( pdt2 == NULL );*/ + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } return pdt; } @@ -215,33 +213,33 @@ typedef struct __struct_char_double { double d; } char_double_t; -ompi_datatype_t* test_struct_char_double( void ) +ompi_datatype_t *test_struct_char_double(void) { char_double_t data; int lengths[] = {1, 1}; MPI_Aint displ[] = {0, 0}; ompi_datatype_t *pdt; - ompi_datatype_t* types[] = { &ompi_mpi_char.dt, &ompi_mpi_double.dt}; + ompi_datatype_t *types[] = {&ompi_mpi_char.dt, &ompi_mpi_double.dt}; - displ[0] = (char*)&(data.c) - (char*)&(data); - displ[1] = (char*)&(data.d) - (char*)&(data); + displ[0] = (char *) &(data.c) - (char *) &(data); + displ[1] = (char *) &(data.d) - (char *) &(data); - ompi_datatype_create_struct( 2, lengths, displ, types, &pdt ); - ompi_datatype_commit( &pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + ompi_datatype_create_struct(2, lengths, displ, types, &pdt); + ompi_datatype_commit(&pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } return pdt; } -ompi_datatype_t* test_create_twice_two_doubles( void ) +ompi_datatype_t *test_create_twice_two_doubles(void) { - ompi_datatype_t* pdt; + ompi_datatype_t *pdt; - ompi_datatype_create_vector( 2, 2, 5, &ompi_mpi_double.dt, &pdt ); - ompi_datatype_commit( &pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + ompi_datatype_create_vector(2, 2, 5, &ompi_mpi_double.dt, &pdt); + ompi_datatype_commit(&pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } return pdt; } @@ -270,69 +268,69 @@ ompi_datatype_t* test_create_twice_two_doubles( void ) --C-----D*-[ C ][INT] MPI_INT count 2 disp 0xa24 (2596) extent 4 --C-----D*-[ C ][INT] MPI_INT count 1 disp 0xa80 (2688) extent 4 */ -static int blacs_length[] = { 13, 13, 13, 13, 13, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; -static int blacs_indices[] = { 1144/4, 1232/4, 1320/4, 1408/4, 1496/4, 1584/4, 1676/4, 1768/4, - 1860/4, 1952/4, 2044/4, 2136/4, 2228/4, 2320/4, 2412/4, 2504/4, - 2596/4, 2688/4 }; -ompi_datatype_t* test_create_blacs_type( void ) +static int blacs_length[] = {13, 13, 13, 13, 13, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; +static int blacs_indices[] = {1144 / 4, 1232 / 4, 1320 / 4, 1408 / 4, 1496 / 4, 1584 / 4, + 1676 / 4, 1768 / 4, 1860 / 4, 1952 / 4, 2044 / 4, 2136 / 4, + 2228 / 4, 2320 / 4, 2412 / 4, 2504 / 4, 2596 / 4, 2688 / 4}; +ompi_datatype_t *test_create_blacs_type(void) { ompi_datatype_t *pdt; - ompi_datatype_create_indexed( 18, blacs_length, blacs_indices, &ompi_mpi_int.dt, &pdt ); - ompi_datatype_commit( &pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + ompi_datatype_create_indexed(18, blacs_length, blacs_indices, &ompi_mpi_int.dt, &pdt); + ompi_datatype_commit(&pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } return pdt; } -ompi_datatype_t* test_create_blacs_type1( const ompi_datatype_t* base_type ) +ompi_datatype_t *test_create_blacs_type1(const ompi_datatype_t *base_type) { ompi_datatype_t *pdt; - ompi_datatype_create_vector( 7, 1, 3, base_type, &pdt ); - ompi_datatype_commit( &pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + ompi_datatype_create_vector(7, 1, 3, base_type, &pdt); + ompi_datatype_commit(&pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } return pdt; } -ompi_datatype_t* test_create_blacs_type2( const ompi_datatype_t* base_type ) +ompi_datatype_t *test_create_blacs_type2(const ompi_datatype_t *base_type) { ompi_datatype_t *pdt; - ompi_datatype_create_vector( 7, 1, 2, base_type, &pdt ); - ompi_datatype_commit( &pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + ompi_datatype_create_vector(7, 1, 2, base_type, &pdt); + ompi_datatype_commit(&pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } return pdt; } -ompi_datatype_t* test_struct( void ) +ompi_datatype_t *test_struct(void) { - ompi_datatype_t* types[] = { &ompi_mpi_float.dt /* ompi_datatype_basicDatatypes[DT_FLOAT] */, - NULL, - &ompi_mpi_char.dt /* ompi_datatype_basicDatatypes[DT_CHAR] */ }; - int lengths[] = { 2, 1, 3 }; - MPI_Aint disp[] = { 0, 16, 26 }; - ompi_datatype_t* pdt, *pdt1; - - printf( "test struct\n" ); + ompi_datatype_t *types[] = {&ompi_mpi_float.dt /* ompi_datatype_basicDatatypes[DT_FLOAT] */, + NULL, + &ompi_mpi_char.dt /* ompi_datatype_basicDatatypes[DT_CHAR] */}; + int lengths[] = {2, 1, 3}; + MPI_Aint disp[] = {0, 16, 26}; + ompi_datatype_t *pdt, *pdt1; + + printf("test struct\n"); ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt1); - ompi_datatype_add( pdt1, &ompi_mpi_double.dt, 1, 0, -1 ); - ompi_datatype_add( pdt1, &ompi_mpi_char.dt, 1, 8, -1 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt1 ); + ompi_datatype_add(pdt1, &ompi_mpi_double.dt, 1, 0, -1); + ompi_datatype_add(pdt1, &ompi_mpi_char.dt, 1, 8, -1); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt1); } types[1] = pdt1; - ompi_datatype_create_struct( 3, lengths, disp, types, &pdt ); - OBJ_RELEASE( pdt1 ); /*assert( pdt1 == NULL );*/ - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + ompi_datatype_create_struct(3, lengths, disp, types, &pdt); + OBJ_RELEASE(pdt1); /*assert( pdt1 == NULL );*/ + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } return pdt; } @@ -344,7 +342,7 @@ struct structure { double transfered_2; }; -ompi_datatype_t* create_struct_constant_gap_resized_ddt( ompi_datatype_t* type ) +ompi_datatype_t *create_struct_constant_gap_resized_ddt(ompi_datatype_t *type) { struct structure data[1]; ompi_datatype_t *struct_type, *temp_type; @@ -361,9 +359,10 @@ ompi_datatype_t* create_struct_constant_gap_resized_ddt( ompi_datatype_t* type ) ompi_datatype_create_struct(2, blocklens, disps, types, &temp_type); ompi_datatype_create_resized(temp_type, 0, sizeof(data[0]), &struct_type); ompi_datatype_commit(&struct_type); - OBJ_RELEASE(temp_type); assert( temp_type == NULL ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( struct_type ); + OBJ_RELEASE(temp_type); + assert(temp_type == NULL); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(struct_type); } return struct_type; @@ -384,74 +383,75 @@ typedef struct { #define SSTRANGE_CNT 10 #define USE_RESIZED -ompi_datatype_t* create_strange_dt( void ) +ompi_datatype_t *create_strange_dt(void) { sdata_intern v[2]; MPI_Aint displ[3]; - ompi_datatype_t* types[3] = { &ompi_mpi_int.dt }; + ompi_datatype_t *types[3] = {&ompi_mpi_int.dt}; sstrange t[2]; int pBlock[3] = {1, 10, 1}, dispi[3]; ompi_datatype_t *pdt, *pdt1, *pdt2, *pdtTemp; - dispi[0] = (int)((char*)&(v[0].i1) - (char*)&(v[0])); /* 0 */ - dispi[1] = (int)(((char*)(&(v[0].i2)) - (char*)&(v[0])) / sizeof(int)); /* 2 */ - ompi_datatype_create_indexed_block( 2, 1, dispi, &ompi_mpi_int.dt, &pdtTemp ); + dispi[0] = (int) ((char *) &(v[0].i1) - (char *) &(v[0])); /* 0 */ + dispi[1] = (int) (((char *) (&(v[0].i2)) - (char *) &(v[0])) / sizeof(int)); /* 2 */ + ompi_datatype_create_indexed_block(2, 1, dispi, &ompi_mpi_int.dt, &pdtTemp); #ifdef USE_RESIZED /* optional */ displ[0] = 0; - displ[1] = (char*)&(v[1]) - (char*)&(v[0]); - ompi_datatype_create_resized( pdtTemp, displ[0], displ[1], &pdt1 ); - OBJ_RELEASE( pdtTemp ); assert( pdtTemp == NULL ); + displ[1] = (char *) &(v[1]) - (char *) &(v[0]); + ompi_datatype_create_resized(pdtTemp, displ[0], displ[1], &pdt1); + OBJ_RELEASE(pdtTemp); + assert(pdtTemp == NULL); #else pdt1 = pdtTemp; -#endif /* USE_RESIZED */ +#endif /* USE_RESIZED */ types[1] = pdt1; types[2] = &ompi_mpi_int.dt; displ[0] = 0; - displ[1] = (long)((char*)&(t[0].v[0]) - (char*)&(t[0])); - displ[2] = (long)((char*)&(t[0].last) - (char*)&(t[0])); - ompi_datatype_create_struct( 3, pBlock, displ, types, &pdtTemp ); + displ[1] = (long) ((char *) &(t[0].v[0]) - (char *) &(t[0])); + displ[2] = (long) ((char *) &(t[0].last) - (char *) &(t[0])); + ompi_datatype_create_struct(3, pBlock, displ, types, &pdtTemp); #ifdef USE_RESIZED /* optional */ - displ[1] = (char*)&(t[1]) - (char*)&(t[0]); - ompi_datatype_create_resized( pdtTemp, displ[0], displ[1], &pdt2 ); - OBJ_RELEASE( pdtTemp ); assert( pdtTemp == NULL ); + displ[1] = (char *) &(t[1]) - (char *) &(t[0]); + ompi_datatype_create_resized(pdtTemp, displ[0], displ[1], &pdt2); + OBJ_RELEASE(pdtTemp); + assert(pdtTemp == NULL); #else pdt2 = pdtTemp; -#endif /* USE_RESIZED */ +#endif /* USE_RESIZED */ - ompi_datatype_create_contiguous( SSTRANGE_CNT, pdt2, &pdt ); + ompi_datatype_create_contiguous(SSTRANGE_CNT, pdt2, &pdt); - OBJ_RELEASE( pdt1 ); - OBJ_RELEASE( pdt2 ); - printf( "\nStrange datatype BEFORE COMMIT\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + OBJ_RELEASE(pdt1); + OBJ_RELEASE(pdt2); + printf("\nStrange datatype BEFORE COMMIT\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } - ompi_datatype_commit( &pdt ); - printf( "\nStrange datatype AFTER COMMIT\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + ompi_datatype_commit(&pdt); + printf("\nStrange datatype AFTER COMMIT\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } return pdt; } -ompi_datatype_t* create_contiguous_type( const ompi_datatype_t* data, int count ) +ompi_datatype_t *create_contiguous_type(const ompi_datatype_t *data, int count) { - ompi_datatype_t* contiguous; + ompi_datatype_t *contiguous; - ompi_datatype_create_contiguous( count, data, &contiguous ); - ompi_datatype_commit( &contiguous ); + ompi_datatype_create_contiguous(count, data, &contiguous); + ompi_datatype_commit(&contiguous); return contiguous; } -ompi_datatype_t* create_vector_type( const ompi_datatype_t* data, int count, int length, int stride ) +ompi_datatype_t *create_vector_type(const ompi_datatype_t *data, int count, int length, int stride) { - ompi_datatype_t* vector; + ompi_datatype_t *vector; - ompi_datatype_create_vector( count, length, stride, data, &vector ); - ompi_datatype_commit( &vector ); + ompi_datatype_create_vector(count, length, stride, data, &vector); + ompi_datatype_commit(&vector); return vector; } - diff --git a/test/datatype/ddt_lib.h b/test/datatype/ddt_lib.h index fc4bb81188..78b11855ab 100644 --- a/test/datatype/ddt_lib.h +++ b/test/datatype/ddt_lib.h @@ -22,16 +22,17 @@ #include "ompi_config.h" #include "ompi/datatype/ompi_datatype.h" -#include <time.h> #include <stdlib.h> +#include <time.h> #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #endif #include <stdio.h> #define TIMER_DATA_TYPE struct timeval -#define GET_TIME(TV) gettimeofday( &(TV), NULL ) -#define ELAPSED_TIME(TSTART, TEND) (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) +#define GET_TIME(TV) gettimeofday(&(TV), NULL) +#define ELAPSED_TIME(TSTART, TEND) \ + (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) #define DUMP_DATA_AFTER_COMMIT 0x00000001 #define CHECK_PACK_UNPACK 0x00000002 @@ -41,22 +42,22 @@ extern uint32_t outputFlags; /** * Cache cleanup. */ -extern void cache_trash( void ); +extern void cache_trash(void); /** * Data-type functions. */ -ompi_datatype_t* create_inversed_vector( const ompi_datatype_t* type, int length ); +ompi_datatype_t *create_inversed_vector(const ompi_datatype_t *type, int length); -extern void print_double_mat( unsigned int N, double* mat ); -extern int init_random_upper_matrix( unsigned int N, double* mat ); -extern int check_diag_matrix( unsigned int N, double* mat1, double* mat2 ); -extern ompi_datatype_t* upper_matrix( unsigned int mat_size ); -extern ompi_datatype_t* lower_matrix( unsigned int mat_size ); -extern ompi_datatype_t* test_matrix_borders( unsigned int size, unsigned int width ); -extern ompi_datatype_t* test_contiguous( void ); -extern ompi_datatype_t* test_struct_char_double( void ); -extern ompi_datatype_t* test_create_twice_two_doubles( void ); +extern void print_double_mat(unsigned int N, double *mat); +extern int init_random_upper_matrix(unsigned int N, double *mat); +extern int check_diag_matrix(unsigned int N, double *mat1, double *mat2); +extern ompi_datatype_t *upper_matrix(unsigned int mat_size); +extern ompi_datatype_t *lower_matrix(unsigned int mat_size); +extern ompi_datatype_t *test_matrix_borders(unsigned int size, unsigned int width); +extern ompi_datatype_t *test_contiguous(void); +extern ompi_datatype_t *test_struct_char_double(void); +extern ompi_datatype_t *test_create_twice_two_doubles(void); /* Datatype 0x832cf28 size 0 align 1 id 0 length 4 used 0 @@ -82,13 +83,12 @@ extern ompi_datatype_t* test_create_twice_two_doubles( void ); --C-----D*-[ C ][INT] MPI_INT count 2 disp 0xa24 (2596) extent 4 --C-----D*-[ C ][INT] MPI_INT count 1 disp 0xa80 (2688) extent 4 */ -extern ompi_datatype_t* test_create_blacs_type( void ); -extern ompi_datatype_t* test_create_blacs_type1( const ompi_datatype_t* base_type ); -extern ompi_datatype_t* test_create_blacs_type2( const ompi_datatype_t* base_type ); -extern ompi_datatype_t* test_struct( void ); -extern ompi_datatype_t* create_strange_dt( void ); -extern ompi_datatype_t* create_contiguous_type( const ompi_datatype_t* data, int count ); -extern ompi_datatype_t* create_vector_type( const ompi_datatype_t* data, int count, - int length, int stride ); -extern ompi_datatype_t* create_struct_constant_gap_resized_ddt( ompi_datatype_t* type ); - +extern ompi_datatype_t *test_create_blacs_type(void); +extern ompi_datatype_t *test_create_blacs_type1(const ompi_datatype_t *base_type); +extern ompi_datatype_t *test_create_blacs_type2(const ompi_datatype_t *base_type); +extern ompi_datatype_t *test_struct(void); +extern ompi_datatype_t *create_strange_dt(void); +extern ompi_datatype_t *create_contiguous_type(const ompi_datatype_t *data, int count); +extern ompi_datatype_t *create_vector_type(const ompi_datatype_t *data, int count, int length, + int stride); +extern ompi_datatype_t *create_struct_constant_gap_resized_ddt(ompi_datatype_t *type); diff --git a/test/datatype/ddt_pack.c b/test/datatype/ddt_pack.c index 60d5fd278d..7d0f0461ba 100644 --- a/test/datatype/ddt_pack.c +++ b/test/datatype/ddt_pack.c @@ -25,8 +25,8 @@ #include "ompi_config.h" #include "ompi/datatype/ompi_datatype.h" -#include "opal/datatype/opal_convertor.h" #include "ompi/proc/proc.h" +#include "opal/datatype/opal_convertor.h" #include "opal/runtime/opal.h" #include <stdlib.h> @@ -34,40 +34,43 @@ #include <poll.h> -static int get_extents(ompi_datatype_t * type, ptrdiff_t *lb, ptrdiff_t *extent, ptrdiff_t *true_lb, ptrdiff_t *true_extent) { +static int get_extents(ompi_datatype_t *type, ptrdiff_t *lb, ptrdiff_t *extent, ptrdiff_t *true_lb, + ptrdiff_t *true_extent) +{ int ret; ret = ompi_datatype_get_extent(type, lb, extent); - if (MPI_SUCCESS != ret) return ret; + if (MPI_SUCCESS != ret) + return ret; ret = ompi_datatype_get_true_extent(type, true_lb, true_extent); - if (MPI_SUCCESS != ret) return ret; + if (MPI_SUCCESS != ret) + return ret; return 0; } -int -main(int argc, char* argv[]) +int main(int argc, char *argv[]) { size_t packed_ddt_len; const void *packed_ddt; void *payload, *ptr; struct ompi_datatype_t *unpacked_dt; int ret = 0; - int blen[4]; - ptrdiff_t disp[4]; + int blen[4]; + ptrdiff_t disp[4]; ompi_datatype_t *newType, *types[4], *struct_type, *vec_type, *dup_type; - ptrdiff_t old_lb, old_extent, old_true_lb, old_true_extent; - ptrdiff_t lb, extent, true_lb, true_extent; + ptrdiff_t old_lb, old_extent, old_true_lb, old_true_extent; + ptrdiff_t lb, extent, true_lb, true_extent; /* make ompi_proc_local () work ... */ struct ompi_proc_t dummy_proc; ompi_proc_local_proc = &dummy_proc; - int _dbg = 0; - while (_dbg) poll(NULL, 0, 1); + while (_dbg) + poll(NULL, 0, 1); - opal_init_util (NULL, NULL); + opal_init_util(NULL, NULL); ompi_datatype_init(); /** @@ -82,11 +85,11 @@ main(int argc, char* argv[]) packed_ddt_len = ompi_datatype_pack_description_length(&ompi_mpi_int.dt); ptr = payload = malloc(packed_ddt_len); ret = ompi_datatype_get_pack_description(&ompi_mpi_int.dt, &packed_ddt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; memcpy(payload, packed_ddt, packed_ddt_len); - unpacked_dt = ompi_datatype_create_from_packed_description(&payload, - ompi_proc_local()); + unpacked_dt = ompi_datatype_create_from_packed_description(&payload, ompi_proc_local()); free(ptr); if (unpacked_dt == &ompi_mpi_int32_t.dt) { printf("\tPASSED\n"); @@ -103,30 +106,44 @@ main(int argc, char* argv[]) */ printf("---> Simple test using a struct and few predefined datatype (4 * MPI_INT).\n"); - blen[0] = 1; blen[1] = 2; blen[2] = 3; blen[3] = 4; - disp[0] = 0; disp[1] = 4; disp[2] = 8; disp[3] = 12; - types[0] = &ompi_mpi_int.dt; types[1] = &ompi_mpi_int.dt; types[2] = &ompi_mpi_int.dt; types[3] = &ompi_mpi_int.dt; - ret = ompi_datatype_create_struct( 4, blen, disp, types, &struct_type ); - if (ret != 0) goto cleanup; + blen[0] = 1; + blen[1] = 2; + blen[2] = 3; + blen[3] = 4; + disp[0] = 0; + disp[1] = 4; + disp[2] = 8; + disp[3] = 12; + types[0] = &ompi_mpi_int.dt; + types[1] = &ompi_mpi_int.dt; + types[2] = &ompi_mpi_int.dt; + types[3] = &ompi_mpi_int.dt; + ret = ompi_datatype_create_struct(4, blen, disp, types, &struct_type); + if (ret != 0) + goto cleanup; { int count = 4; - const int* a_i[2] = {&count, blen}; - ret = ompi_datatype_set_args( struct_type, count + 1, a_i, count, disp, - count, types, MPI_COMBINER_STRUCT); - if (ret != 0) goto cleanup; + const int *a_i[2] = {&count, blen}; + ret = ompi_datatype_set_args(struct_type, count + 1, a_i, count, disp, count, types, + MPI_COMBINER_STRUCT); + if (ret != 0) + goto cleanup; } ret = ompi_datatype_commit(&struct_type); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = get_extents(struct_type, &old_lb, &old_extent, &old_true_lb, &old_true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; packed_ddt_len = ompi_datatype_pack_description_length(struct_type); ptr = payload = malloc(packed_ddt_len); ret = ompi_datatype_get_pack_description(struct_type, &packed_ddt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; memcpy(payload, packed_ddt, packed_ddt_len); @@ -138,10 +155,11 @@ main(int argc, char* argv[]) goto cleanup; } else { ret = get_extents(unpacked_dt, &lb, &extent, &true_lb, &true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; - if (old_lb != lb || old_extent != extent || - old_true_lb != true_lb || old_true_extent != extent) { + if (old_lb != lb || old_extent != extent || old_true_lb != true_lb + || old_true_extent != extent) { printf("\tFAILED: datatypes don't match\n"); ret = 1; goto cleanup; @@ -149,10 +167,12 @@ main(int argc, char* argv[]) printf("\tPASSED\n"); } ret = ompi_datatype_destroy(&struct_type); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = ompi_datatype_destroy(&unpacked_dt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; /** * @@ -163,33 +183,37 @@ main(int argc, char* argv[]) printf("---> Less Basic test with MPI_Type_vector\n"); ret = ompi_datatype_create_vector(2, 1, 1, &ompi_mpi_int.dt, &vec_type); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; { int count = 2; int blocklength = 1; int stride = 1; - const int* a_i[3] = {&count, &blocklength, &stride}; - ompi_datatype_t * type = &ompi_mpi_int.dt; - ret = ompi_datatype_set_args(vec_type, 3, a_i, 0, NULL, 1, &type, MPI_COMBINER_VECTOR ); - if (ret != 0) goto cleanup; + const int *a_i[3] = {&count, &blocklength, &stride}; + ompi_datatype_t *type = &ompi_mpi_int.dt; + ret = ompi_datatype_set_args(vec_type, 3, a_i, 0, NULL, 1, &type, MPI_COMBINER_VECTOR); + if (ret != 0) + goto cleanup; } ret = ompi_datatype_commit(&vec_type); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = get_extents(vec_type, &old_lb, &old_extent, &old_true_lb, &old_true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; packed_ddt_len = ompi_datatype_pack_description_length(vec_type); ptr = payload = malloc(packed_ddt_len); ret = ompi_datatype_get_pack_description(vec_type, &packed_ddt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; memcpy(payload, packed_ddt, packed_ddt_len); - unpacked_dt = ompi_datatype_create_from_packed_description(&payload, - ompi_proc_local()); + unpacked_dt = ompi_datatype_create_from_packed_description(&payload, ompi_proc_local()); free(ptr); if (unpacked_dt == NULL) { printf("\tFAILED: could not unpack datatype\n"); @@ -197,10 +221,11 @@ main(int argc, char* argv[]) goto cleanup; } else { ret = get_extents(unpacked_dt, &lb, &extent, &true_lb, &true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; - if (old_lb != lb || old_extent != extent || - old_true_lb != true_lb || old_true_extent != extent) { + if (old_lb != lb || old_extent != extent || old_true_lb != true_lb + || old_true_extent != extent) { printf("\tFAILED: datatypes don't match\n"); ret = 1; goto cleanup; @@ -208,10 +233,12 @@ main(int argc, char* argv[]) printf("\tPASSED\n"); } ret = ompi_datatype_destroy(&vec_type); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = ompi_datatype_destroy(&unpacked_dt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; /** * @@ -222,36 +249,40 @@ main(int argc, char* argv[]) printf("---> Test with MPI_Type_create_indexed_block\n"); blen[0] = 0; - blen[1] = 20*sizeof(double); + blen[1] = 20 * sizeof(double); ret = ompi_datatype_create_indexed_block(2, 10, blen, &ompi_mpi_double.dt, &newType); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; { int count = 2; int blocklength = 10; - const int* a_i[3] = {&count, &blocklength, blen}; - ompi_datatype_t * oldtype = &ompi_mpi_double.dt; - ompi_datatype_set_args( newType, 2 + count, a_i, 0, NULL, 1, &oldtype, - MPI_COMBINER_INDEXED_BLOCK ); - if (ret != 0) goto cleanup; + const int *a_i[3] = {&count, &blocklength, blen}; + ompi_datatype_t *oldtype = &ompi_mpi_double.dt; + ompi_datatype_set_args(newType, 2 + count, a_i, 0, NULL, 1, &oldtype, + MPI_COMBINER_INDEXED_BLOCK); + if (ret != 0) + goto cleanup; } ret = ompi_datatype_commit(&newType); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = get_extents(newType, &old_lb, &old_extent, &old_true_lb, &old_true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; packed_ddt_len = ompi_datatype_pack_description_length(newType); ptr = payload = malloc(packed_ddt_len); ret = ompi_datatype_get_pack_description(newType, &packed_ddt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; memcpy(payload, packed_ddt, packed_ddt_len); - unpacked_dt = ompi_datatype_create_from_packed_description(&payload, - ompi_proc_local()); + unpacked_dt = ompi_datatype_create_from_packed_description(&payload, ompi_proc_local()); free(ptr); if (unpacked_dt == NULL) { printf("\tFAILED: could not unpack datatype\n"); @@ -259,10 +290,11 @@ main(int argc, char* argv[]) goto cleanup; } else { ret = get_extents(unpacked_dt, &lb, &extent, &true_lb, &true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; - if (old_lb != lb || old_extent != extent || - old_true_lb != true_lb || old_true_extent != extent) { + if (old_lb != lb || old_extent != extent || old_true_lb != true_lb + || old_true_extent != extent) { printf("\tFAILED: datatypes don't match\n"); ret = 1; goto cleanup; @@ -270,10 +302,12 @@ main(int argc, char* argv[]) printf("\tPASSED\n"); } ret = ompi_datatype_destroy(&newType); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = ompi_datatype_destroy(&unpacked_dt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; /** * @@ -286,33 +320,37 @@ main(int argc, char* argv[]) blen[0] = 10; blen[1] = 10; disp[0] = 0; - disp[1] = 20*sizeof(double); + disp[1] = 20 * sizeof(double); ret = ompi_datatype_create_hindexed(2, blen, disp, &ompi_mpi_double.dt, &newType); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; { int count = 2; - const int* a_i[2] = {&count, blen}; - ompi_datatype_t * oldtype = &ompi_mpi_double.dt; - ret = ompi_datatype_set_args( newType, count + 1, a_i, count, disp, - 1, &oldtype, MPI_COMBINER_HINDEXED ); - if (ret != 0) goto cleanup; + const int *a_i[2] = {&count, blen}; + ompi_datatype_t *oldtype = &ompi_mpi_double.dt; + ret = ompi_datatype_set_args(newType, count + 1, a_i, count, disp, 1, &oldtype, + MPI_COMBINER_HINDEXED); + if (ret != 0) + goto cleanup; } ret = ompi_datatype_commit(&newType); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = get_extents(newType, &old_lb, &old_extent, &old_true_lb, &old_true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; packed_ddt_len = ompi_datatype_pack_description_length(newType); ptr = payload = malloc(packed_ddt_len); ret = ompi_datatype_get_pack_description(newType, &packed_ddt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; memcpy(payload, packed_ddt, packed_ddt_len); - unpacked_dt = ompi_datatype_create_from_packed_description(&payload, - ompi_proc_local()); + unpacked_dt = ompi_datatype_create_from_packed_description(&payload, ompi_proc_local()); free(ptr); if (unpacked_dt == NULL) { printf("\tFAILED: could not unpack datatype\n"); @@ -320,10 +358,11 @@ main(int argc, char* argv[]) goto cleanup; } else { ret = get_extents(unpacked_dt, &lb, &extent, &true_lb, &true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; - if (old_lb != lb || old_extent != extent || - old_true_lb != true_lb || old_true_extent != extent) { + if (old_lb != lb || old_extent != extent || old_true_lb != true_lb + || old_true_extent != extent) { printf("\tFAILED: datatypes don't match\n"); ret = 1; goto cleanup; @@ -331,9 +370,10 @@ main(int argc, char* argv[]) printf("\tPASSED\n"); } ret = ompi_datatype_destroy(&newType); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; - newType = unpacked_dt; /* save it for later */ + newType = unpacked_dt; /* save it for later */ /** * @@ -348,34 +388,39 @@ main(int argc, char* argv[]) disp[1] = 64; types[0] = &ompi_mpi_int.dt; types[1] = newType; - ret = ompi_datatype_create_struct( 2, blen, disp, types, &struct_type ); - if (ret != 0) goto cleanup; + ret = ompi_datatype_create_struct(2, blen, disp, types, &struct_type); + if (ret != 0) + goto cleanup; { int count = 2; - const int* a_i[2] = {&count, blen}; - ret = ompi_datatype_set_args( struct_type, count + 1, a_i, count, disp, - count, types, MPI_COMBINER_STRUCT ); - if (ret != 0) goto cleanup; + const int *a_i[2] = {&count, blen}; + ret = ompi_datatype_set_args(struct_type, count + 1, a_i, count, disp, count, types, + MPI_COMBINER_STRUCT); + if (ret != 0) + goto cleanup; } ret = ompi_datatype_commit(&struct_type); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = ompi_datatype_destroy(&newType); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = get_extents(struct_type, &old_lb, &old_extent, &old_true_lb, &old_true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; packed_ddt_len = ompi_datatype_pack_description_length(struct_type); ptr = payload = malloc(packed_ddt_len); ret = ompi_datatype_get_pack_description(struct_type, &packed_ddt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; memcpy(payload, packed_ddt, packed_ddt_len); - unpacked_dt = ompi_datatype_create_from_packed_description(&payload, - ompi_proc_local()); + unpacked_dt = ompi_datatype_create_from_packed_description(&payload, ompi_proc_local()); free(ptr); if (unpacked_dt == NULL) { printf("\tFAILED: could not unpack datatype\n"); @@ -383,10 +428,11 @@ main(int argc, char* argv[]) goto cleanup; } else { ret = get_extents(unpacked_dt, &lb, &extent, &true_lb, &true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; - if (old_lb != lb || old_extent != extent || - old_true_lb != true_lb || old_true_extent != extent) { + if (old_lb != lb || old_extent != extent || old_true_lb != true_lb + || old_true_extent != extent) { printf("\tFAILED: datatypes don't match\n"); ret = 1; goto cleanup; @@ -394,10 +440,12 @@ main(int argc, char* argv[]) printf("\tPASSED\n"); } ret = ompi_datatype_destroy(&struct_type); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = ompi_datatype_destroy(&unpacked_dt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; /** * @@ -407,20 +455,23 @@ main(int argc, char* argv[]) printf("---> Basic test with dup'ed MPI_INT\n"); ret = get_extents(&ompi_mpi_int.dt, &old_lb, &old_extent, &old_true_lb, &old_true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; ret = ompi_datatype_duplicate(&ompi_mpi_int.dt, &dup_type); - if (ret != 0) goto cleanup; - ompi_datatype_t * type = &ompi_mpi_int.dt; + if (ret != 0) + goto cleanup; + ompi_datatype_t *type = &ompi_mpi_int.dt; ret = ompi_datatype_set_args(dup_type, 0, NULL, 0, NULL, 1, &type, MPI_COMBINER_DUP); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; packed_ddt_len = ompi_datatype_pack_description_length(dup_type); ptr = payload = malloc(packed_ddt_len); ret = ompi_datatype_get_pack_description(dup_type, &packed_ddt); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; memcpy(payload, packed_ddt, packed_ddt_len); - unpacked_dt = ompi_datatype_create_from_packed_description(&payload, - ompi_proc_local()); + unpacked_dt = ompi_datatype_create_from_packed_description(&payload, ompi_proc_local()); free(ptr); if (unpacked_dt == NULL) { printf("\tFAILED: could not unpack datatype\n"); @@ -428,10 +479,11 @@ main(int argc, char* argv[]) goto cleanup; } else { ret = get_extents(unpacked_dt, &lb, &extent, &true_lb, &true_extent); - if (ret != 0) goto cleanup; + if (ret != 0) + goto cleanup; - if (old_lb != lb || old_extent != extent || - old_true_lb != true_lb || old_true_extent != extent) { + if (old_lb != lb || old_extent != extent || old_true_lb != true_lb + || old_true_extent != extent) { printf("\tFAILED: datatypes don't match\n"); ret = 1; goto cleanup; @@ -447,9 +499,9 @@ main(int argc, char* argv[]) } ompi_datatype_destroy(&dup_type); - cleanup: +cleanup: ompi_datatype_finalize(); - opal_finalize_util (); + opal_finalize_util(); return ret; } diff --git a/test/datatype/ddt_raw.c b/test/datatype/ddt_raw.c index 00da61f0a2..0dcc5e13a3 100644 --- a/test/datatype/ddt_raw.c +++ b/test/datatype/ddt_raw.c @@ -27,30 +27,33 @@ #include "opal/datatype/opal_convertor.h" #include "opal/runtime/opal.h" -#include <time.h> #include <stdlib.h> +#include <time.h> #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #endif #include <stdio.h> /* Compile with: -mpicc -DHAVE_CONFIG_H -I. -I../../include -I../../../ompi-trunk/include -I../.. -I../../include -I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -I../../../ompi-trunk/ompi -g ddt_test.c -o ddt_test +mpicc -DHAVE_CONFIG_H -I. -I../../include -I../../../ompi-trunk/include -I../.. -I../../include +-I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -I../../../ompi-trunk/ompi -g ddt_test.c -o +ddt_test */ #define TIMER_DATA_TYPE struct timeval -#define GET_TIME(TV) gettimeofday( &(TV), NULL ) -#define ELAPSED_TIME(TSTART, TEND) (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) +#define GET_TIME(TV) gettimeofday(&(TV), NULL) +#define ELAPSED_TIME(TSTART, TEND) \ + (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) #define DUMP_DATA_AFTER_COMMIT 0x00000001 #define CHECK_PACK_UNPACK 0x00000002 uint32_t remote_arch = 0xffffffff; -static int test_upper( unsigned int length ) +static int test_upper(unsigned int length) { ompi_datatype_t *pdt; - opal_convertor_t * pConv; + opal_convertor_t *pConv; int rc = OMPI_SUCCESS; unsigned int i, iov_count, total_length; size_t max_data; @@ -58,33 +61,34 @@ static int test_upper( unsigned int length ) TIMER_DATA_TYPE start, end; long total_time; - printf( "test upper matrix\n" ); - pdt = upper_matrix( length ); + printf("test upper matrix\n"); + pdt = upper_matrix(length); /*dt_dump( pdt );*/ - total_length = length * (length + 1) * ( sizeof(double) / 2); + total_length = length * (length + 1) * (sizeof(double) / 2); - pConv = opal_convertor_create( remote_arch, 0 ); - if( OMPI_SUCCESS != opal_convertor_prepare_for_send( pConv, &(pdt->super), 1, NULL ) ) { - printf( "Cannot attach the datatype to a convertor\n" ); + pConv = opal_convertor_create(remote_arch, 0); + if (OMPI_SUCCESS != opal_convertor_prepare_for_send(pConv, &(pdt->super), 1, NULL)) { + printf("Cannot attach the datatype to a convertor\n"); return OMPI_ERROR; } - GET_TIME( start ); - for( i = total_length; i > 0; ) { + GET_TIME(start); + for (i = total_length; i > 0;) { iov_count = 5; max_data = 0; - opal_convertor_raw( pConv, iov, &iov_count, &max_data ); + opal_convertor_raw(pConv, iov, &iov_count, &max_data); i -= max_data; } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "complete raw in %ld microsec\n", total_time ); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("complete raw in %ld microsec\n", total_time); /* test the automatic destruction pf the data */ - ompi_datatype_destroy( &pdt ); assert( pdt == NULL ); + ompi_datatype_destroy(&pdt); + assert(pdt == NULL); - OBJ_RELEASE( pConv ); + OBJ_RELEASE(pConv); return rc; } @@ -97,26 +101,26 @@ static int test_upper( unsigned int length ) * - and one using 2 convertors created from different datatypes. * */ -static int local_copy_ddt_raw( ompi_datatype_t* pdt, int count, int iov_num ) +static int local_copy_ddt_raw(ompi_datatype_t *pdt, int count, int iov_num) { - struct iovec* iov; - opal_convertor_t* convertor; + struct iovec *iov; + opal_convertor_t *convertor; TIMER_DATA_TYPE start, end; long total_time; uint32_t iov_count = iov_num; size_t max_data = 0, remaining_length; - iov = (struct iovec*)malloc(iov_num * sizeof(struct iovec)); + iov = (struct iovec *) malloc(iov_num * sizeof(struct iovec)); - convertor = opal_convertor_create( remote_arch, 0 ); - if( OMPI_SUCCESS != opal_convertor_prepare_for_send( convertor, &(pdt->super), count, NULL ) ) { - printf( "Cannot attach the datatype to a convertor\n" ); + convertor = opal_convertor_create(remote_arch, 0); + if (OMPI_SUCCESS != opal_convertor_prepare_for_send(convertor, &(pdt->super), count, NULL)) { + printf("Cannot attach the datatype to a convertor\n"); return OMPI_ERROR; } remaining_length = count * pdt->super.size; - GET_TIME( start ); - while( 0 == opal_convertor_raw(convertor, iov, &iov_count, &max_data) ) { + GET_TIME(start); + while (0 == opal_convertor_raw(convertor, iov, &iov_count, &max_data)) { #if 0 printf( "New raw extraction (iov_count = %d, max_data = %zu)\n", iov_count, max_data ); @@ -128,13 +132,13 @@ static int local_copy_ddt_raw( ompi_datatype_t* pdt, int count, int iov_num ) iov_count = iov_num; } remaining_length -= max_data; - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "raw extraction in %ld microsec\n", total_time ); - OBJ_RELEASE( convertor ); - if( remaining_length != 0 ) { - printf( "Not all raw description was been extracted (%lu bytes missing)\n", - (unsigned long) remaining_length ); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("raw extraction in %ld microsec\n", total_time); + OBJ_RELEASE(convertor); + if (remaining_length != 0) { + printf("Not all raw description was been extracted (%lu bytes missing)\n", + (unsigned long) remaining_length); } free(iov); return OMPI_SUCCESS; @@ -151,175 +155,195 @@ static int local_copy_ddt_raw( ompi_datatype_t* pdt, int count, int iov_num ) * modifications on the datatype engine should first pass all the tests from this file, * before going into other tests. */ -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { ompi_datatype_t *pdt, *pdt1, *pdt2, *pdt3; int rc, length = 500, iov_num = 5; - opal_init_util (NULL, NULL); + opal_init_util(NULL, NULL); ompi_datatype_init(); /** * By default simulate homogeneous architectures. */ remote_arch = opal_local_arch; - printf( "\n\n#\n * TEST INVERSED VECTOR\n #\n\n" ); - pdt = create_inversed_vector( &ompi_mpi_int.dt, 10 ); - if( outputFlags & CHECK_PACK_UNPACK ) { + printf("\n\n#\n * TEST INVERSED VECTOR\n #\n\n"); + pdt = create_inversed_vector(&ompi_mpi_int.dt, 10); + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_raw(pdt, 100, iov_num); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "\n\n#\n * TEST STRANGE DATATYPE\n #\n\n" ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("\n\n#\n * TEST STRANGE DATATYPE\n #\n\n"); pdt = create_strange_dt(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_raw(pdt, 1, iov_num); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST UPPER TRIANGULAR MATRIX (size 100)\n #\n\n" ); + printf("\n\n#\n * TEST UPPER TRIANGULAR MATRIX (size 100)\n #\n\n"); pdt = upper_matrix(100); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_raw(pdt, 1, iov_num); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST UPPER MATRIX\n #\n\n" ); - rc = test_upper( length ); - if( rc == 0 ) - printf( "decode [PASSED]\n" ); + printf("\n\n#\n * TEST UPPER MATRIX\n #\n\n"); + rc = test_upper(length); + if (rc == 0) + printf("decode [PASSED]\n"); else - printf( "decode [NOT PASSED]\n" ); + printf("decode [NOT PASSED]\n"); - printf( "\n\n#\n * TEST MATRIX BORDERS\n #\n\n" ); - pdt = test_matrix_borders( length, 100 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + printf("\n\n#\n * TEST MATRIX BORDERS\n #\n\n"); + pdt = test_matrix_borders(length, 100); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST CONTIGUOUS\n #\n\n" ); + printf("\n\n#\n * TEST CONTIGUOUS\n #\n\n"); pdt = test_contiguous(); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "\n\n#\n * TEST STRUCT\n #\n\n" ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("\n\n#\n * TEST STRUCT\n #\n\n"); pdt = test_struct(); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt1); ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt2); ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt3); - ompi_datatype_add( pdt3, &ompi_mpi_int.dt, 10, 0, -1 ); - ompi_datatype_add( pdt3, &ompi_mpi_float.dt, 5, 10 * sizeof(int), -1 ); + ompi_datatype_add(pdt3, &ompi_mpi_int.dt, 10, 0, -1); + ompi_datatype_add(pdt3, &ompi_mpi_float.dt, 5, 10 * sizeof(int), -1); - ompi_datatype_add( pdt2, &ompi_mpi_float.dt, 1, 0, -1 ); - ompi_datatype_add( pdt2, pdt3, 3, sizeof(int) * 1, -1 ); + ompi_datatype_add(pdt2, &ompi_mpi_float.dt, 1, 0, -1); + ompi_datatype_add(pdt2, pdt3, 3, sizeof(int) * 1, -1); - ompi_datatype_add( pdt1, &ompi_mpi_long_long_int.dt, 5, 0, -1 ); - ompi_datatype_add( pdt1, &ompi_mpi_long_double.dt, 2, sizeof(long long) * 5, -1 ); + ompi_datatype_add(pdt1, &ompi_mpi_long_long_int.dt, 5, 0, -1); + ompi_datatype_add(pdt1, &ompi_mpi_long_double.dt, 2, sizeof(long long) * 5, -1); - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt1 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt1); } - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt2 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt2); } - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt3 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt3); } - OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL ); - OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL ); - OBJ_RELEASE( pdt3 ); assert( pdt3 == NULL ); + OBJ_RELEASE(pdt1); + assert(pdt1 == NULL); + OBJ_RELEASE(pdt2); + assert(pdt2 == NULL); + OBJ_RELEASE(pdt3); + assert(pdt3 == NULL); - printf( ">>--------------------------------------------<<\n" ); - printf( " Contiguous datatype (MPI_DOUBLE)\n" ); + printf(">>--------------------------------------------<<\n"); + printf(" Contiguous datatype (MPI_DOUBLE)\n"); pdt = MPI_DOUBLE; - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_raw(pdt, 4500, iov_num); } - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & CHECK_PACK_UNPACK ) { - printf( "Contiguous multiple datatype (4500*1)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 4500 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & CHECK_PACK_UNPACK) { + printf("Contiguous multiple datatype (4500*1)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 4500); local_copy_ddt_raw(pdt, 1, iov_num); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple datatype (450*10)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 450 ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple datatype (450*10)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 450); local_copy_ddt_raw(pdt, 10, iov_num); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple datatype (45*100)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 45 ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple datatype (45*100)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 45); local_copy_ddt_raw(pdt, 100, iov_num); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple datatype (100*45)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 100 ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple datatype (100*45)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 100); local_copy_ddt_raw(pdt, 45, iov_num); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple datatype (10*450)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 10 ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple datatype (10*450)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 10); local_copy_ddt_raw(pdt, 450, iov_num); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple datatype (1*4500)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 1 ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple datatype (1*4500)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 1); local_copy_ddt_raw(pdt, 4500, iov_num); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); } - printf( ">>--------------------------------------------<<\n" ); - printf( ">>--------------------------------------------<<\n" ); - printf( "Vector datatype (450 times 10 double stride 11)\n" ); - pdt = create_vector_type( MPI_DOUBLE, 450, 10, 11 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + printf(">>--------------------------------------------<<\n"); + printf(">>--------------------------------------------<<\n"); + printf("Vector datatype (450 times 10 double stride 11)\n"); + pdt = create_vector_type(MPI_DOUBLE, 450, 10, 11); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_raw(pdt, 1, iov_num); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); pdt = test_struct_char_double(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_raw(pdt, 4500, iov_num); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); pdt = test_create_twice_two_doubles(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_raw(pdt, 4500, iov_num); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); pdt = test_create_blacs_type(); - if( outputFlags & CHECK_PACK_UNPACK ) { - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + if (outputFlags & CHECK_PACK_UNPACK) { + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } local_copy_ddt_raw(pdt, 4500, iov_num); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - - printf( ">>--------------------------------------------<<\n" ); - pdt1 = test_create_blacs_type1( &ompi_mpi_int.dt ); - if( outputFlags & CHECK_PACK_UNPACK ) { - local_copy_ddt_raw( pdt1, 1, iov_num ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + + printf(">>--------------------------------------------<<\n"); + pdt1 = test_create_blacs_type1(&ompi_mpi_int.dt); + if (outputFlags & CHECK_PACK_UNPACK) { + local_copy_ddt_raw(pdt1, 1, iov_num); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt1); + assert(pdt1 == NULL); /* clean-ups all data allocations */ ompi_datatype_finalize(); - opal_finalize_util (); + opal_finalize_util(); return OMPI_SUCCESS; } diff --git a/test/datatype/ddt_raw2.c b/test/datatype/ddt_raw2.c index 7e91a323f7..ea38f5d228 100644 --- a/test/datatype/ddt_raw2.c +++ b/test/datatype/ddt_raw2.c @@ -18,39 +18,33 @@ #include "opal/datatype/opal_datatype_internal.h" #include "opal/runtime/opal.h" -#include <time.h> #include <stdlib.h> +#include <time.h> #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #endif #include <stdio.h> - -static int -mca_common_ompio_decode_datatype ( ompi_datatype_t *datatype, - int count, - struct iovec **iov, - uint32_t *iovec_count, - int increment) +static int mca_common_ompio_decode_datatype(ompi_datatype_t *datatype, int count, + struct iovec **iov, uint32_t *iovec_count, + int increment) { opal_convertor_t *convertor; size_t remaining_length = 0; uint32_t i; uint32_t temp_count; - struct iovec *temp_iov=NULL; + struct iovec *temp_iov = NULL; size_t temp_data; - convertor = opal_convertor_create( opal_local_arch, 0 ); + convertor = opal_convertor_create(opal_local_arch, 0); - if (OMPI_SUCCESS != opal_convertor_prepare_for_send (convertor, - &(datatype->super), - count, - NULL)) { - opal_output (1, "Cannot attach the datatype to a convertor\n"); + if (OMPI_SUCCESS + != opal_convertor_prepare_for_send(convertor, &(datatype->super), count, NULL)) { + opal_output(1, "Cannot attach the datatype to a convertor\n"); return OMPI_ERROR; } - if ( 0 == datatype->super.size ) { + if (0 == datatype->super.size) { *iovec_count = 0; *iov = NULL; return OMPI_SUCCESS; @@ -59,247 +53,155 @@ mca_common_ompio_decode_datatype ( ompi_datatype_t *datatype, remaining_length = count * datatype->super.size; temp_count = increment; - temp_iov = (struct iovec*)malloc(temp_count * sizeof(struct iovec)); + temp_iov = (struct iovec *) malloc(temp_count * sizeof(struct iovec)); if (NULL == temp_iov) { - opal_output (1, "OUT OF MEMORY\n"); + opal_output(1, "OUT OF MEMORY\n"); return OMPI_ERR_OUT_OF_RESOURCE; } - while (0 == opal_convertor_raw(convertor, temp_iov, - &temp_count, &temp_data)) { + while (0 == opal_convertor_raw(convertor, temp_iov, &temp_count, &temp_data)) { *iovec_count = *iovec_count + temp_count; - *iov = (struct iovec *) realloc (*iov, *iovec_count * sizeof(struct iovec)); + *iov = (struct iovec *) realloc(*iov, *iovec_count * sizeof(struct iovec)); if (NULL == *iov) { opal_output(1, "OUT OF MEMORY\n"); free(temp_iov); return OMPI_ERR_OUT_OF_RESOURCE; } - for (i = 0 ; i < temp_count ; i++) { - (*iov)[i+(*iovec_count-temp_count)].iov_base = temp_iov[i].iov_base; - (*iov)[i+(*iovec_count-temp_count)].iov_len = temp_iov[i].iov_len; + for (i = 0; i < temp_count; i++) { + (*iov)[i + (*iovec_count - temp_count)].iov_base = temp_iov[i].iov_base; + (*iov)[i + (*iovec_count - temp_count)].iov_len = temp_iov[i].iov_len; } remaining_length -= temp_data; temp_count = increment; } *iovec_count = *iovec_count + temp_count; - if ( temp_count > 0 ) { - *iov = (struct iovec *) realloc (*iov, *iovec_count * sizeof(struct iovec)); + if (temp_count > 0) { + *iov = (struct iovec *) realloc(*iov, *iovec_count * sizeof(struct iovec)); if (NULL == *iov) { opal_output(1, "OUT OF MEMORY\n"); free(temp_iov); return OMPI_ERR_OUT_OF_RESOURCE; } } - for (i=0 ; i<temp_count ; i++) { - (*iov)[i+(*iovec_count-temp_count)].iov_base = temp_iov[i].iov_base; - (*iov)[i+(*iovec_count-temp_count)].iov_len = temp_iov[i].iov_len; + for (i = 0; i < temp_count; i++) { + (*iov)[i + (*iovec_count - temp_count)].iov_base = temp_iov[i].iov_base; + (*iov)[i + (*iovec_count - temp_count)].iov_len = temp_iov[i].iov_len; } remaining_length -= temp_data; if (remaining_length != 0) { - printf( "Not all raw description was been extracted (%lu bytes missing)\n", - (unsigned long) remaining_length ); + printf("Not all raw description was been extracted (%lu bytes missing)\n", + (unsigned long) remaining_length); } - free (temp_iov); + free(temp_iov); return OMPI_SUCCESS; } -int main (int argc, char *argv[]) { +int main(int argc, char *argv[]) +{ dt_elem_desc_t descs[185] = { - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 4} }, - { .end_loop = { {16, 1}, 2, -1, 12, 4} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 64} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 1408} }, - { .end_loop = { {16, 1}, 2, -1, 8, 1424} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 10932} }, - { .end_loop = { {16, 1}, 2, -1, 12, 10932} }, - { .elem = { { 310, 9 }, 1, 640, 1, 10992} }, - { .elem = { { 310, 9 }, 1, 712, 1, 14248} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 14952} }, - { .end_loop = { {16, 1}, 2, -1, 8, 14968} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 21860} }, - { .end_loop = { {16, 1}, 2, -1, 12, 21860} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 21920} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 23264} }, - { .end_loop = { {16, 1}, 2, -1, 8, 23280} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 30172} }, - { .end_loop = { {16, 1}, 2, -1, 12, 30172} }, - { .elem = { { 310, 9 }, 1, 192, 1, 30232} }, - { .elem = { { 310, 9 }, 1, 1160, 1, 33040} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 34192} }, - { .end_loop = { {16, 1}, 2, -1, 8, 34208} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 41100} }, - { .end_loop = { {16, 1}, 2, -1, 12, 41100} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 41160} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 42504} }, - { .end_loop = { {16, 1}, 2, -1, 8, 42520} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 52028} }, - { .end_loop = { {16, 1}, 2, -1, 12, 52028} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 52088} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 53432} }, - { .end_loop = { {16, 1}, 2, -1, 8, 53448} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 60340} }, - { .end_loop = { {16, 1}, 2, -1, 12, 60340} }, - { .elem = { { 310, 9 }, 1, 1344, 1, 60400} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 64360} }, - { .end_loop = { {16, 1}, 2, -1, 8, 64360} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 71268} }, - { .end_loop = { {16, 1}, 2, -1, 12, 71268} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 71328} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 72672} }, - { .end_loop = { {16, 1}, 2, -1, 8, 72688} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 79580} }, - { .end_loop = { {16, 1}, 2, -1, 12, 79580} }, - { .elem = { { 310, 9 }, 1, 896, 1, 79640} }, - { .elem = { { 310, 9 }, 1, 456, 1, 83152} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 83600} }, - { .end_loop = { {16, 1}, 2, -1, 8, 83616} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 90508} }, - { .end_loop = { {16, 1}, 2, -1, 12, 90508} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 90568} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 91912} }, - { .end_loop = { {16, 1}, 2, -1, 8, 91928} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 98820} }, - { .end_loop = { {16, 1}, 2, -1, 12, 98820} }, - { .elem = { { 310, 9 }, 1, 448, 1, 98880} }, - { .elem = { { 310, 9 }, 1, 904, 1, 101944} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 102840} }, - { .end_loop = { {16, 1}, 2, -1, 8, 102856} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 109748} }, - { .end_loop = { {16, 1}, 2, -1, 12, 109748} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 109808} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 111152} }, - { .end_loop = { {16, 1}, 2, -1, 8, 111168} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 118060} }, - { .end_loop = { {16, 1}, 2, -1, 12, 118060} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 120736} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 122080} }, - { .end_loop = { {16, 1}, 2, -1, 8, 122096} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 128988} }, - { .end_loop = { {16, 1}, 2, -1, 12, 128988} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 129048} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 130392} }, - { .end_loop = { {16, 1}, 2, -1, 8, 130408} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 139916} }, - { .end_loop = { {16, 1}, 2, -1, 12, 139916} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 139976} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 141320} }, - { .end_loop = { {16, 1}, 2, -1, 8, 141336} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 148228} }, - { .end_loop = { {16, 1}, 2, -1, 12, 148228} }, - { .elem = { { 310, 9 }, 1, 1152, 1, 148288} }, - { .elem = { { 310, 9 }, 1, 200, 1, 152056} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 152248} }, - { .end_loop = { {16, 1}, 2, -1, 8, 152264} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 159156} }, - { .end_loop = { {16, 1}, 2, -1, 12, 159156} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 159216} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 160560} }, - { .end_loop = { {16, 1}, 2, -1, 8, 160576} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 167468} }, - { .end_loop = { {16, 1}, 2, -1, 12, 167468} }, - { .elem = { { 310, 9 }, 1, 704, 1, 167528} }, - { .elem = { { 310, 9 }, 1, 648, 1, 170848} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 171488} }, - { .end_loop = { {16, 1}, 2, -1, 8, 171504} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 178396} }, - { .end_loop = { {16, 1}, 2, -1, 12, 178396} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 178456} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 179800} }, - { .end_loop = { {16, 1}, 2, -1, 8, 179816} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 186708} }, - { .end_loop = { {16, 1}, 2, -1, 12, 186708} }, - { .elem = { { 310, 9 }, 1, 256, 1, 186768} }, - { .elem = { { 310, 9 }, 1, 1096, 1, 189640} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 190728} }, - { .end_loop = { {16, 1}, 2, -1, 8, 190744} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 197636} }, - { .end_loop = { {16, 1}, 2, -1, 12, 197636} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 197696} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 199040} }, - { .end_loop = { {16, 1}, 2, -1, 8, 199056} }, - { .loop = { { 16, 0}, 2, 4, -1, 16} }, - { .elem = { { 310, 9 }, 1, 12, 1, 208564} }, - { .end_loop = { {16, 1}, 2, -1, 12, 208564} }, - { .elem = { { 310, 9 }, 1, 1352, 1, 208624} }, - { .loop = { { 16, 0}, 2, 3, -1, 16} }, - { .elem = { { 310, 9 }, 1, 8, 1, 209968} }, - { .end_loop = { {16, 1}, 2, -1, 8, 209984} }, - { .elem = { { 310, 9 }, 1, 12, 1, 216876} }, - { .elem = { { 310, 9 }, 1, 16, 1, 216936} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217000} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217064} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217128} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217192} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217256} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217320} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217384} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217448} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217512} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217576} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217640} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217704} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217768} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217832} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217896} }, - { .elem = { { 310, 9 }, 1, 16, 1, 217960} }, - { .elem = { { 310, 9 }, 1, 16, 1, 218024} }, - { .elem = { { 310, 9 }, 1, 16, 1, 218088} }, - { .elem = { { 310, 9 }, 1, 16, 1, 218152} }, - { .elem = { { 310, 9 }, 1, 16, 1, 218216} }, - { .elem = { { 310, 9 }, 1, 8, 1, 218280} }, - { .end_loop = { {0, 1}, 184, -1, 31684, 4} }, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 4}}, + {.end_loop = {{16, 1}, 2, -1, 12, 4}}, {.elem = {{310, 9}, 1, 1352, 1, 64}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 1408}}, + {.end_loop = {{16, 1}, 2, -1, 8, 1424}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 10932}}, {.end_loop = {{16, 1}, 2, -1, 12, 10932}}, + {.elem = {{310, 9}, 1, 640, 1, 10992}}, {.elem = {{310, 9}, 1, 712, 1, 14248}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 14952}}, + {.end_loop = {{16, 1}, 2, -1, 8, 14968}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 21860}}, {.end_loop = {{16, 1}, 2, -1, 12, 21860}}, + {.elem = {{310, 9}, 1, 1352, 1, 21920}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 23264}}, {.end_loop = {{16, 1}, 2, -1, 8, 23280}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 30172}}, + {.end_loop = {{16, 1}, 2, -1, 12, 30172}}, {.elem = {{310, 9}, 1, 192, 1, 30232}}, + {.elem = {{310, 9}, 1, 1160, 1, 33040}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 34192}}, {.end_loop = {{16, 1}, 2, -1, 8, 34208}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 41100}}, + {.end_loop = {{16, 1}, 2, -1, 12, 41100}}, {.elem = {{310, 9}, 1, 1352, 1, 41160}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 42504}}, + {.end_loop = {{16, 1}, 2, -1, 8, 42520}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 52028}}, {.end_loop = {{16, 1}, 2, -1, 12, 52028}}, + {.elem = {{310, 9}, 1, 1352, 1, 52088}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 53432}}, {.end_loop = {{16, 1}, 2, -1, 8, 53448}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 60340}}, + {.end_loop = {{16, 1}, 2, -1, 12, 60340}}, {.elem = {{310, 9}, 1, 1344, 1, 60400}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 64360}}, + {.end_loop = {{16, 1}, 2, -1, 8, 64360}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 71268}}, {.end_loop = {{16, 1}, 2, -1, 12, 71268}}, + {.elem = {{310, 9}, 1, 1352, 1, 71328}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 72672}}, {.end_loop = {{16, 1}, 2, -1, 8, 72688}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 79580}}, + {.end_loop = {{16, 1}, 2, -1, 12, 79580}}, {.elem = {{310, 9}, 1, 896, 1, 79640}}, + {.elem = {{310, 9}, 1, 456, 1, 83152}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 83600}}, {.end_loop = {{16, 1}, 2, -1, 8, 83616}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 90508}}, + {.end_loop = {{16, 1}, 2, -1, 12, 90508}}, {.elem = {{310, 9}, 1, 1352, 1, 90568}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 91912}}, + {.end_loop = {{16, 1}, 2, -1, 8, 91928}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 98820}}, {.end_loop = {{16, 1}, 2, -1, 12, 98820}}, + {.elem = {{310, 9}, 1, 448, 1, 98880}}, {.elem = {{310, 9}, 1, 904, 1, 101944}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 102840}}, + {.end_loop = {{16, 1}, 2, -1, 8, 102856}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 109748}}, {.end_loop = {{16, 1}, 2, -1, 12, 109748}}, + {.elem = {{310, 9}, 1, 1352, 1, 109808}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 111152}}, {.end_loop = {{16, 1}, 2, -1, 8, 111168}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 118060}}, + {.end_loop = {{16, 1}, 2, -1, 12, 118060}}, {.elem = {{310, 9}, 1, 1352, 1, 120736}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 122080}}, + {.end_loop = {{16, 1}, 2, -1, 8, 122096}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 128988}}, {.end_loop = {{16, 1}, 2, -1, 12, 128988}}, + {.elem = {{310, 9}, 1, 1352, 1, 129048}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 130392}}, {.end_loop = {{16, 1}, 2, -1, 8, 130408}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 139916}}, + {.end_loop = {{16, 1}, 2, -1, 12, 139916}}, {.elem = {{310, 9}, 1, 1352, 1, 139976}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 141320}}, + {.end_loop = {{16, 1}, 2, -1, 8, 141336}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 148228}}, {.end_loop = {{16, 1}, 2, -1, 12, 148228}}, + {.elem = {{310, 9}, 1, 1152, 1, 148288}}, {.elem = {{310, 9}, 1, 200, 1, 152056}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 152248}}, + {.end_loop = {{16, 1}, 2, -1, 8, 152264}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 159156}}, {.end_loop = {{16, 1}, 2, -1, 12, 159156}}, + {.elem = {{310, 9}, 1, 1352, 1, 159216}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 160560}}, {.end_loop = {{16, 1}, 2, -1, 8, 160576}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 167468}}, + {.end_loop = {{16, 1}, 2, -1, 12, 167468}}, {.elem = {{310, 9}, 1, 704, 1, 167528}}, + {.elem = {{310, 9}, 1, 648, 1, 170848}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 171488}}, {.end_loop = {{16, 1}, 2, -1, 8, 171504}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 178396}}, + {.end_loop = {{16, 1}, 2, -1, 12, 178396}}, {.elem = {{310, 9}, 1, 1352, 1, 178456}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 179800}}, + {.end_loop = {{16, 1}, 2, -1, 8, 179816}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 186708}}, {.end_loop = {{16, 1}, 2, -1, 12, 186708}}, + {.elem = {{310, 9}, 1, 256, 1, 186768}}, {.elem = {{310, 9}, 1, 1096, 1, 189640}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 190728}}, + {.end_loop = {{16, 1}, 2, -1, 8, 190744}}, {.loop = {{16, 0}, 2, 4, -1, 16}}, + {.elem = {{310, 9}, 1, 12, 1, 197636}}, {.end_loop = {{16, 1}, 2, -1, 12, 197636}}, + {.elem = {{310, 9}, 1, 1352, 1, 197696}}, {.loop = {{16, 0}, 2, 3, -1, 16}}, + {.elem = {{310, 9}, 1, 8, 1, 199040}}, {.end_loop = {{16, 1}, 2, -1, 8, 199056}}, + {.loop = {{16, 0}, 2, 4, -1, 16}}, {.elem = {{310, 9}, 1, 12, 1, 208564}}, + {.end_loop = {{16, 1}, 2, -1, 12, 208564}}, {.elem = {{310, 9}, 1, 1352, 1, 208624}}, + {.loop = {{16, 0}, 2, 3, -1, 16}}, {.elem = {{310, 9}, 1, 8, 1, 209968}}, + {.end_loop = {{16, 1}, 2, -1, 8, 209984}}, {.elem = {{310, 9}, 1, 12, 1, 216876}}, + {.elem = {{310, 9}, 1, 16, 1, 216936}}, {.elem = {{310, 9}, 1, 16, 1, 217000}}, + {.elem = {{310, 9}, 1, 16, 1, 217064}}, {.elem = {{310, 9}, 1, 16, 1, 217128}}, + {.elem = {{310, 9}, 1, 16, 1, 217192}}, {.elem = {{310, 9}, 1, 16, 1, 217256}}, + {.elem = {{310, 9}, 1, 16, 1, 217320}}, {.elem = {{310, 9}, 1, 16, 1, 217384}}, + {.elem = {{310, 9}, 1, 16, 1, 217448}}, {.elem = {{310, 9}, 1, 16, 1, 217512}}, + {.elem = {{310, 9}, 1, 16, 1, 217576}}, {.elem = {{310, 9}, 1, 16, 1, 217640}}, + {.elem = {{310, 9}, 1, 16, 1, 217704}}, {.elem = {{310, 9}, 1, 16, 1, 217768}}, + {.elem = {{310, 9}, 1, 16, 1, 217832}}, {.elem = {{310, 9}, 1, 16, 1, 217896}}, + {.elem = {{310, 9}, 1, 16, 1, 217960}}, {.elem = {{310, 9}, 1, 16, 1, 218024}}, + {.elem = {{310, 9}, 1, 16, 1, 218088}}, {.elem = {{310, 9}, 1, 16, 1, 218152}}, + {.elem = {{310, 9}, 1, 16, 1, 218216}}, {.elem = {{310, 9}, 1, 8, 1, 218280}}, + {.end_loop = {{0, 1}, 184, -1, 31684, 4}}, }; opal_init_util(NULL, NULL); ompi_datatype_init(); - ompi_datatype_t * datatype = OBJ_NEW(ompi_datatype_t); + ompi_datatype_t *datatype = OBJ_NEW(ompi_datatype_t); datatype->super.flags = 3332; datatype->super.id = 0; @@ -321,20 +223,20 @@ int main (int argc, char *argv[]) { /* Get the entire raw description of the datatype in a single call */ uint32_t iovec_count_300 = 0; - struct iovec * iov_300 = NULL; - mca_common_ompio_decode_datatype ( datatype, 1, &iov_300, &iovec_count_300, 300); + struct iovec *iov_300 = NULL; + mca_common_ompio_decode_datatype(datatype, 1, &iov_300, &iovec_count_300, 300); /* Get the raw description of the datatype 10 elements at the time. This stresses some * of the execution paths in the convertor raw. */ uint32_t iovec_count_10 = 0; - struct iovec * iov_10 = NULL; - mca_common_ompio_decode_datatype ( datatype, 1, &iov_10, &iovec_count_10, 10); + struct iovec *iov_10 = NULL; + mca_common_ompio_decode_datatype(datatype, 1, &iov_10, &iovec_count_10, 10); /* Get the raw description of the datatype one element at the time. This stresses all * execution paths in the convertor raw. */ uint32_t iovec_count_1 = 0; - struct iovec * iov_1 = NULL; - mca_common_ompio_decode_datatype ( datatype, 1, &iov_1, &iovec_count_1, 1); + struct iovec *iov_1 = NULL; + mca_common_ompio_decode_datatype(datatype, 1, &iov_1, &iovec_count_1, 1); assert(iovec_count_300 == iovec_count_10); assert(iovec_count_300 == iovec_count_1); @@ -349,4 +251,3 @@ int main (int argc, char *argv[]) { return 0; } - diff --git a/test/datatype/ddt_test.c b/test/datatype/ddt_test.c index aa2de4954a..a61019cc4e 100644 --- a/test/datatype/ddt_test.c +++ b/test/datatype/ddt_test.c @@ -20,34 +20,37 @@ #include "ompi_config.h" #include "ddt_lib.h" -#include "opal/runtime/opal.h" #include "opal/datatype/opal_convertor.h" -#include <time.h> +#include "opal/runtime/opal.h" #include <stdlib.h> +#include <time.h> #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #endif #include <stdio.h> #include <string.h> /* Compile with: -mpicc -DHAVE_CONFIG_H -I. -I../../include -I../../../ompi-trunk/include -I../.. -I../../include -I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -I../../../ompi-trunk/ompi -g ddt_test.c -o ddt_test +mpicc -DHAVE_CONFIG_H -I. -I../../include -I../../../ompi-trunk/include -I../.. -I../../include +-I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -I../../../ompi-trunk/ompi -g ddt_test.c -o +ddt_test */ #define TIMER_DATA_TYPE struct timeval -#define GET_TIME(TV) gettimeofday( &(TV), NULL ) -#define ELAPSED_TIME(TSTART, TEND) (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) +#define GET_TIME(TV) gettimeofday(&(TV), NULL) +#define ELAPSED_TIME(TSTART, TEND) \ + (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) #define DUMP_DATA_AFTER_COMMIT 0x00000001 #define CHECK_PACK_UNPACK 0x00000002 uint32_t remote_arch = 0xffffffff; -static int test_upper( unsigned int length ) +static int test_upper(unsigned int length) { double *mat1, *mat2, *inbuf; ompi_datatype_t *pdt; - opal_convertor_t * pConv; + opal_convertor_t *pConv; char *ptr; int rc; unsigned int i, j, iov_count, split_chunk, total_length; @@ -56,60 +59,62 @@ static int test_upper( unsigned int length ) TIMER_DATA_TYPE start, end; long total_time; - printf( "test upper matrix\n" ); - pdt = upper_matrix( length ); + printf("test upper matrix\n"); + pdt = upper_matrix(length); /*dt_dump( pdt );*/ - mat1 = malloc( length * length * sizeof(double) ); - init_random_upper_matrix( length, mat1 ); - mat2 = calloc( length * length, sizeof(double) ); + mat1 = malloc(length * length * sizeof(double)); + init_random_upper_matrix(length, mat1); + mat2 = calloc(length * length, sizeof(double)); - total_length = length * (length + 1) * ( sizeof(double) / 2); - inbuf = (double*)malloc( total_length ); - ptr = (char*)inbuf; + total_length = length * (length + 1) * (sizeof(double) / 2); + inbuf = (double *) malloc(total_length); + ptr = (char *) inbuf; /* copy upper matrix in the array simulating the input buffer */ - for( i = 0; i < length; i++ ) { + for (i = 0; i < length; i++) { uint32_t pos = i * length + i; - for( j = i; j < length; j++, pos++ ) { + for (j = i; j < length; j++, pos++) { *inbuf = mat1[pos]; inbuf++; } } - inbuf = (double*)ptr; - pConv = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &(pdt->super), 1, mat2 ) ) { - printf( "Cannot attach the datatype to a convertor\n" ); + inbuf = (double *) ptr; + pConv = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS != opal_convertor_prepare_for_recv(pConv, &(pdt->super), 1, mat2)) { + printf("Cannot attach the datatype to a convertor\n"); return OMPI_ERROR; } - GET_TIME( start ); + GET_TIME(start); split_chunk = (length + 1) * sizeof(double); /* split_chunk = (total_length + 1) * sizeof(double); */ - for( i = total_length; i > 0; ) { - if( i <= split_chunk ) { /* equal test just to be able to set a breakpoint */ + for (i = total_length; i > 0;) { + if (i <= split_chunk) { /* equal test just to be able to set a breakpoint */ split_chunk = i; } a.iov_base = ptr; a.iov_len = split_chunk; iov_count = 1; max_data = split_chunk; - opal_convertor_unpack( pConv, &a, &iov_count, &max_data ); + opal_convertor_unpack(pConv, &a, &iov_count, &max_data); ptr += max_data; i -= max_data; - if( mat2[0] != inbuf[0] ) assert(0); + if (mat2[0] != inbuf[0]) + assert(0); } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "complete unpacking in %ld microsec\n", total_time ); - free( inbuf ); - rc = check_diag_matrix( length, mat1, mat2 ); - free( mat1 ); - free( mat2 ); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("complete unpacking in %ld microsec\n", total_time); + free(inbuf); + rc = check_diag_matrix(length, mat1, mat2); + free(mat1); + free(mat2); /* test the automatic destruction pf the data */ - ompi_datatype_destroy( &pdt ); assert( pdt == NULL ); + ompi_datatype_destroy(&pdt); + assert(pdt == NULL); - OBJ_RELEASE( pConv ); + OBJ_RELEASE(pConv); return rc; } @@ -118,16 +123,17 @@ static int test_upper( unsigned int length ) * is not an easy task. Define a function to centralize the complexity in a * single location. */ -static size_t compute_buffer_length(ompi_datatype_t* pdt, int count) +static size_t compute_buffer_length(ompi_datatype_t *pdt, int count) { MPI_Aint extent, lb, true_extent, true_lb; size_t length; ompi_datatype_get_extent(pdt, &lb, &extent); - ompi_datatype_get_true_extent(pdt, &true_lb, &true_extent); (void)true_lb; + ompi_datatype_get_true_extent(pdt, &true_lb, &true_extent); + (void) true_lb; length = true_lb + true_extent + (count - 1) * extent; - return length; + return length; } /** @@ -139,7 +145,7 @@ static size_t compute_buffer_length(ompi_datatype_t* pdt, int count) * - and one using 2 convertors created from different data-types. * */ -static int local_copy_ddt_count( ompi_datatype_t* pdt, int count ) +static int local_copy_ddt_count(ompi_datatype_t *pdt, int count) { void *pdst, *psrc; TIMER_DATA_TYPE start, end; @@ -151,30 +157,29 @@ static int local_copy_ddt_count( ompi_datatype_t* pdt, int count ) pdst = malloc(length); psrc = malloc(length); - for( size_t i = 0; i < length; i++ ) - ((char*)psrc)[i] = i % 128 + 32; + for (size_t i = 0; i < length; i++) + ((char *) psrc)[i] = i % 128 + 32; memset(pdst, 0, length); - cache_trash(); /* make sure the cache is useless */ + cache_trash(); /* make sure the cache is useless */ - GET_TIME( start ); - if( OMPI_SUCCESS != ompi_datatype_copy_content_same_ddt( pdt, count, pdst, psrc ) ) { - printf( "Unable to copy the datatype in the function local_copy_ddt_count." - " Is the datatype committed ?\n" ); + GET_TIME(start); + if (OMPI_SUCCESS != ompi_datatype_copy_content_same_ddt(pdt, count, pdst, psrc)) { + printf("Unable to copy the datatype in the function local_copy_ddt_count." + " Is the datatype committed ?\n"); } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "direct local copy in %ld microsec\n", total_time ); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("direct local copy in %ld microsec\n", total_time); free(pdst); free(psrc); return OMPI_SUCCESS; } -static int -local_copy_with_convertor_2datatypes( ompi_datatype_t* send_type, int send_count, - ompi_datatype_t* recv_type, int recv_count, - int chunk ) +static int local_copy_with_convertor_2datatypes(ompi_datatype_t *send_type, int send_count, + ompi_datatype_t *recv_type, int recv_count, + int chunk) { void *pdst = NULL, *psrc = NULL, *ptemp = NULL; opal_convertor_t *send_convertor = NULL, *recv_convertor = NULL; @@ -188,35 +193,37 @@ local_copy_with_convertor_2datatypes( ompi_datatype_t* send_type, int send_count rlength = compute_buffer_length(recv_type, recv_count); slength = compute_buffer_length(send_type, send_count); - pdst = malloc( rlength ); - psrc = malloc( slength ); - ptemp = malloc( chunk ); + pdst = malloc(rlength); + psrc = malloc(slength); + ptemp = malloc(chunk); /* initialize the buffers to prevent valgrind from complaining */ - for( size_t i = 0; i < slength; i++ ) - ((char*)psrc)[i] = i % 128 + 32; + for (size_t i = 0; i < slength; i++) + ((char *) psrc)[i] = i % 128 + 32; memset(pdst, 0, rlength); - send_convertor = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_send( send_convertor, &(send_type->super), send_count, psrc ) ) { - printf( "Unable to create the send convertor. Is the datatype committed ?\n" ); + send_convertor = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS + != opal_convertor_prepare_for_send(send_convertor, &(send_type->super), send_count, psrc)) { + printf("Unable to create the send convertor. Is the datatype committed ?\n"); goto clean_and_return; } - recv_convertor = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( recv_convertor, &(recv_type->super), recv_count, pdst ) ) { - printf( "Unable to create the recv convertor. Is the datatype committed ?\n" ); + recv_convertor = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS + != opal_convertor_prepare_for_recv(recv_convertor, &(recv_type->super), recv_count, pdst)) { + printf("Unable to create the recv convertor. Is the datatype committed ?\n"); goto clean_and_return; } - cache_trash(); /* make sure the cache is useless */ + cache_trash(); /* make sure the cache is useless */ - GET_TIME( start ); - while( (done1 & done2) != 1 ) { + GET_TIME(start); + while ((done1 & done2) != 1) { /* They are supposed to finish in exactly the same time. */ - if( done1 | done2 ) { - printf( "WRONG !!! the send is %s but the receive is %s in local_copy_with_convertor_2datatypes\n", - (done1 ? "finish" : "not finish"), - (done2 ? "finish" : "not finish") ); + if (done1 | done2) { + printf("WRONG !!! the send is %s but the receive is %s in " + "local_copy_with_convertor_2datatypes\n", + (done1 ? "finish" : "not finish"), (done2 ? "finish" : "not finish")); } max_data = chunk; @@ -224,38 +231,43 @@ local_copy_with_convertor_2datatypes( ompi_datatype_t* send_type, int send_count iov.iov_base = ptemp; iov.iov_len = chunk; - if( done1 == 0 ) { - done1 = opal_convertor_pack( send_convertor, &iov, &iov_count, &max_data ); + if (done1 == 0) { + done1 = opal_convertor_pack(send_convertor, &iov, &iov_count, &max_data); } - if( done2 == 0 ) { - GET_TIME( unpack_start ); - done2 = opal_convertor_unpack( recv_convertor, &iov, &iov_count, &max_data ); - GET_TIME( unpack_end ); - unpack_time += ELAPSED_TIME( unpack_start, unpack_end ); + if (done2 == 0) { + GET_TIME(unpack_start); + done2 = opal_convertor_unpack(recv_convertor, &iov, &iov_count, &max_data); + GET_TIME(unpack_end); + unpack_time += ELAPSED_TIME(unpack_start, unpack_end); } length += max_data; } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "copying different data-types using convertors in %ld microsec\n", total_time ); - printf( "\t unpack in %ld microsec [pack in %ld microsec]\n", unpack_time, - total_time - unpack_time ); - clean_and_return: - if( send_convertor != NULL ) { - OBJ_RELEASE( send_convertor ); assert( send_convertor == NULL ); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("copying different data-types using convertors in %ld microsec\n", total_time); + printf("\t unpack in %ld microsec [pack in %ld microsec]\n", unpack_time, + total_time - unpack_time); +clean_and_return: + if (send_convertor != NULL) { + OBJ_RELEASE(send_convertor); + assert(send_convertor == NULL); } - if( recv_convertor != NULL ) { - OBJ_RELEASE( recv_convertor ); assert( recv_convertor == NULL ); + if (recv_convertor != NULL) { + OBJ_RELEASE(recv_convertor); + assert(recv_convertor == NULL); } - if( NULL != pdst ) free( pdst ); - if( NULL != psrc ) free( psrc ); - if( NULL != ptemp ) free( ptemp ); + if (NULL != pdst) + free(pdst); + if (NULL != psrc) + free(psrc); + if (NULL != ptemp) + free(ptemp); return OMPI_SUCCESS; } -static int local_copy_with_convertor( ompi_datatype_t* pdt, int count, int chunk ) +static int local_copy_with_convertor(ompi_datatype_t *pdt, int count, int chunk) { void *pdst = NULL, *psrc = NULL, *ptemp = NULL; opal_convertor_t *send_convertor = NULL, *recv_convertor = NULL; @@ -268,34 +280,36 @@ static int local_copy_with_convertor( ompi_datatype_t* pdt, int count, int chunk max_data = compute_buffer_length(pdt, count); - pdst = malloc(max_data); - psrc = malloc(max_data); + pdst = malloc(max_data); + psrc = malloc(max_data); ptemp = malloc(chunk); - for( int i = 0; i < length; ((char*)psrc)[i] = i % 128 + 32, i++ ); - memset( pdst, 0, length ); + for (int i = 0; i < length; ((char *) psrc)[i] = i % 128 + 32, i++) + ; + memset(pdst, 0, length); - send_convertor = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_send( send_convertor, &(pdt->super), count, psrc ) ) { - printf( "Unable to create the send convertor. Is the datatype committed ?\n" ); + send_convertor = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS + != opal_convertor_prepare_for_send(send_convertor, &(pdt->super), count, psrc)) { + printf("Unable to create the send convertor. Is the datatype committed ?\n"); goto clean_and_return; } - recv_convertor = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( recv_convertor, &(pdt->super), count, pdst ) ) { - printf( "Unable to create the recv convertor. Is the datatype committed ?\n" ); + recv_convertor = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS + != opal_convertor_prepare_for_recv(recv_convertor, &(pdt->super), count, pdst)) { + printf("Unable to create the recv convertor. Is the datatype committed ?\n"); goto clean_and_return; } - cache_trash(); /* make sure the cache is useless */ + cache_trash(); /* make sure the cache is useless */ - GET_TIME( start ); - while( (done1 & done2) != 1 ) { + GET_TIME(start); + while ((done1 & done2) != 1) { /* They are supposed to finish in exactly the same time. */ - if( done1 | done2 ) { - printf( "WRONG !!! the send is %s but the receive is %s in local_copy_with_convertor\n", - (done1 ? "finish" : "not finish"), - (done2 ? "finish" : "not finish") ); + if (done1 | done2) { + printf("WRONG !!! the send is %s but the receive is %s in local_copy_with_convertor\n", + (done1 ? "finish" : "not finish"), (done2 ? "finish" : "not finish")); } max_data = chunk; @@ -303,31 +317,36 @@ static int local_copy_with_convertor( ompi_datatype_t* pdt, int count, int chunk iov.iov_base = ptemp; iov.iov_len = chunk; - if( done1 == 0 ) { - done1 = opal_convertor_pack( send_convertor, &iov, &iov_count, &max_data ); + if (done1 == 0) { + done1 = opal_convertor_pack(send_convertor, &iov, &iov_count, &max_data); } - if( done2 == 0 ) { - GET_TIME( unpack_start ); - done2 = opal_convertor_unpack( recv_convertor, &iov, &iov_count, &max_data ); - GET_TIME( unpack_end ); - unpack_time += ELAPSED_TIME( unpack_start, unpack_end ); + if (done2 == 0) { + GET_TIME(unpack_start); + done2 = opal_convertor_unpack(recv_convertor, &iov, &iov_count, &max_data); + GET_TIME(unpack_end); + unpack_time += ELAPSED_TIME(unpack_start, unpack_end); } length += max_data; } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "copying same data-type using convertors in %ld microsec\n", total_time ); - printf( "\t unpack in %ld microsec [pack in %ld microsec]\n", unpack_time, - total_time - unpack_time ); - clean_and_return: - if( NULL != send_convertor ) OBJ_RELEASE( send_convertor ); - if( NULL != recv_convertor ) OBJ_RELEASE( recv_convertor ); - - if( NULL != pdst ) free( pdst ); - if( NULL != psrc ) free( psrc ); - if( NULL != ptemp ) free( ptemp ); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("copying same data-type using convertors in %ld microsec\n", total_time); + printf("\t unpack in %ld microsec [pack in %ld microsec]\n", unpack_time, + total_time - unpack_time); +clean_and_return: + if (NULL != send_convertor) + OBJ_RELEASE(send_convertor); + if (NULL != recv_convertor) + OBJ_RELEASE(recv_convertor); + + if (NULL != pdst) + free(pdst); + if (NULL != psrc) + free(psrc); + if (NULL != ptemp) + free(ptemp); return OMPI_SUCCESS; } @@ -338,7 +357,7 @@ static int local_copy_with_convertor( ompi_datatype_t* pdt, int count, int chunk * on the data-type engine should first pass all the tests from this file, before going into other * tests. */ -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { ompi_datatype_t *pdt, *pdt1, *pdt2, *pdt3; int rc, length = 500; @@ -350,193 +369,214 @@ int main( int argc, char* argv[] ) * By default simulate homogeneous architectures. */ remote_arch = opal_local_arch; - printf( "\n\n#\n * TEST INVERSED VECTOR\n #\n\n" ); - pdt = create_inversed_vector( &ompi_mpi_int.dt, 10 ); - if( outputFlags & CHECK_PACK_UNPACK ) { + printf("\n\n#\n * TEST INVERSED VECTOR\n #\n\n"); + pdt = create_inversed_vector(&ompi_mpi_int.dt, 10); + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 100); local_copy_with_convertor(pdt, 100, 956); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "\n\n#\n * TEST STRANGE DATATYPE\n #\n\n" ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("\n\n#\n * TEST STRANGE DATATYPE\n #\n\n"); pdt = create_strange_dt(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 1); local_copy_with_convertor(pdt, 1, 956); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST UPPER TRIANGULAR MATRIX (size 100)\n #\n\n" ); + printf("\n\n#\n * TEST UPPER TRIANGULAR MATRIX (size 100)\n #\n\n"); pdt = upper_matrix(100); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 1); local_copy_with_convertor(pdt, 1, 48); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST UPPER MATRIX\n #\n\n" ); - rc = test_upper( length ); - if( rc == 0 ) - printf( "decode [PASSED]\n" ); + printf("\n\n#\n * TEST UPPER MATRIX\n #\n\n"); + rc = test_upper(length); + if (rc == 0) + printf("decode [PASSED]\n"); else - printf( "decode [NOT PASSED]\n" ); + printf("decode [NOT PASSED]\n"); - printf( "\n\n#\n * TEST MATRIX BORDERS\n #\n\n" ); - pdt = test_matrix_borders( length, 100 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt ); + printf("\n\n#\n * TEST MATRIX BORDERS\n #\n\n"); + pdt = test_matrix_borders(length, 100); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST CONTIGUOUS\n #\n\n" ); + printf("\n\n#\n * TEST CONTIGUOUS\n #\n\n"); pdt = test_contiguous(); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "\n\n#\n * TEST STRUCT\n #\n\n" ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("\n\n#\n * TEST STRUCT\n #\n\n"); pdt = test_struct(); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt1); ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt2); ompi_datatype_create_contiguous(0, &ompi_mpi_datatype_null.dt, &pdt3); - ompi_datatype_add( pdt3, &ompi_mpi_int.dt, 10, 0, -1 ); - ompi_datatype_add( pdt3, &ompi_mpi_float.dt, 5, 10 * sizeof(int), -1 ); + ompi_datatype_add(pdt3, &ompi_mpi_int.dt, 10, 0, -1); + ompi_datatype_add(pdt3, &ompi_mpi_float.dt, 5, 10 * sizeof(int), -1); - ompi_datatype_add( pdt2, &ompi_mpi_float.dt, 1, 0, -1 ); - ompi_datatype_add( pdt2, pdt3, 3, sizeof(int) * 1, -1 ); + ompi_datatype_add(pdt2, &ompi_mpi_float.dt, 1, 0, -1); + ompi_datatype_add(pdt2, pdt3, 3, sizeof(int) * 1, -1); - ompi_datatype_add( pdt1, &ompi_mpi_long_long_int.dt, 5, 0, -1 ); - ompi_datatype_add( pdt1, &ompi_mpi_long_double.dt, 2, sizeof(long long) * 5, -1 ); + ompi_datatype_add(pdt1, &ompi_mpi_long_long_int.dt, 5, 0, -1); + ompi_datatype_add(pdt1, &ompi_mpi_long_double.dt, 2, sizeof(long long) * 5, -1); - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt1 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt1); } - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt2 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt2); } - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - ompi_datatype_dump( pdt3 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + ompi_datatype_dump(pdt3); } - OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL ); - OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL ); - OBJ_RELEASE( pdt3 ); assert( pdt3 == NULL ); + OBJ_RELEASE(pdt1); + assert(pdt1 == NULL); + OBJ_RELEASE(pdt2); + assert(pdt2 == NULL); + OBJ_RELEASE(pdt3); + assert(pdt3 == NULL); - printf( ">>--------------------------------------------<<\n" ); - printf( " Contiguous data-type (MPI_DOUBLE)\n" ); + printf(">>--------------------------------------------<<\n"); + printf(" Contiguous data-type (MPI_DOUBLE)\n"); pdt = MPI_DOUBLE; - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 12 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 12 ); + local_copy_with_convertor(pdt, 4500, 12); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 12); } - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & CHECK_PACK_UNPACK ) { - printf( "Contiguous multiple data-type (4500*1)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 4500 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & CHECK_PACK_UNPACK) { + printf("Contiguous multiple data-type (4500*1)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 4500); local_copy_ddt_count(pdt, 1); - local_copy_with_convertor( pdt, 1, 12 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (450*10)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 450 ); + local_copy_with_convertor(pdt, 1, 12); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (450*10)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 450); local_copy_ddt_count(pdt, 10); - local_copy_with_convertor( pdt, 10, 12 ); - local_copy_with_convertor_2datatypes( pdt, 10, pdt, 10, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (45*100)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 45 ); + local_copy_with_convertor(pdt, 10, 12); + local_copy_with_convertor_2datatypes(pdt, 10, pdt, 10, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (45*100)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 45); local_copy_ddt_count(pdt, 100); - local_copy_with_convertor( pdt, 100, 12 ); - local_copy_with_convertor_2datatypes( pdt, 100, pdt, 100, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (100*45)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 100 ); + local_copy_with_convertor(pdt, 100, 12); + local_copy_with_convertor_2datatypes(pdt, 100, pdt, 100, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (100*45)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 100); local_copy_ddt_count(pdt, 45); - local_copy_with_convertor( pdt, 45, 12 ); - local_copy_with_convertor_2datatypes( pdt, 45, pdt, 45, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (10*450)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 10 ); + local_copy_with_convertor(pdt, 45, 12); + local_copy_with_convertor_2datatypes(pdt, 45, pdt, 45, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (10*450)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 10); local_copy_ddt_count(pdt, 450); - local_copy_with_convertor( pdt, 450, 12 ); - local_copy_with_convertor_2datatypes( pdt, 450, pdt, 450, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (1*4500)\n" ); - pdt = create_contiguous_type( MPI_DOUBLE, 1 ); + local_copy_with_convertor(pdt, 450, 12); + local_copy_with_convertor_2datatypes(pdt, 450, pdt, 450, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (1*4500)\n"); + pdt = create_contiguous_type(MPI_DOUBLE, 1); local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 12 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + local_copy_with_convertor(pdt, 4500, 12); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); } - printf( ">>--------------------------------------------<<\n" ); - printf( ">>--------------------------------------------<<\n" ); - printf( "Vector data-type (450 times 10 double stride 11)\n" ); - pdt = create_vector_type( MPI_DOUBLE, 450, 10, 11 ); - ompi_datatype_dump( pdt ); - if( outputFlags & CHECK_PACK_UNPACK ) { + printf(">>--------------------------------------------<<\n"); + printf(">>--------------------------------------------<<\n"); + printf("Vector data-type (450 times 10 double stride 11)\n"); + pdt = create_vector_type(MPI_DOUBLE, 450, 10, 11); + ompi_datatype_dump(pdt); + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 1); - local_copy_with_convertor( pdt, 1, 12 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 12 ); - local_copy_with_convertor( pdt, 1, 82 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 82 ); - local_copy_with_convertor( pdt, 1, 6000 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 6000 ); - local_copy_with_convertor( pdt, 1, 36000 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 36000 ); + local_copy_with_convertor(pdt, 1, 12); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 12); + local_copy_with_convertor(pdt, 1, 82); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 82); + local_copy_with_convertor(pdt, 1, 6000); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 6000); + local_copy_with_convertor(pdt, 1, 36000); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 36000); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); pdt = test_struct_char_double(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 12 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 12 ); + local_copy_with_convertor(pdt, 4500, 12); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 12); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); pdt = test_create_twice_two_doubles(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 12 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 12 ); + local_copy_with_convertor(pdt, 4500, 12); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 12); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); pdt = test_create_blacs_type(); - if( outputFlags & CHECK_PACK_UNPACK ) { - ompi_datatype_dump( pdt ); + if (outputFlags & CHECK_PACK_UNPACK) { + ompi_datatype_dump(pdt); local_copy_ddt_count(pdt, 2); local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 956 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 956 ); - local_copy_with_convertor( pdt, 4500, 16*1024 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 16*1024 ); - local_copy_with_convertor( pdt, 4500, 64*1024 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 64*1024 ); + local_copy_with_convertor(pdt, 4500, 956); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 956); + local_copy_with_convertor(pdt, 4500, 16 * 1024); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 16 * 1024); + local_copy_with_convertor(pdt, 4500, 64 * 1024); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 64 * 1024); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - - printf( ">>--------------------------------------------<<\n" ); - pdt1 = test_create_blacs_type1( &ompi_mpi_int.dt ); - pdt2 = test_create_blacs_type2( &ompi_mpi_int.dt ); - if( outputFlags & CHECK_PACK_UNPACK ) { - local_copy_with_convertor_2datatypes( pdt1, 1, pdt2, 1, 100 ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + + printf(">>--------------------------------------------<<\n"); + pdt1 = test_create_blacs_type1(&ompi_mpi_int.dt); + pdt2 = test_create_blacs_type2(&ompi_mpi_int.dt); + if (outputFlags & CHECK_PACK_UNPACK) { + local_copy_with_convertor_2datatypes(pdt1, 1, pdt2, 1, 100); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL ); - OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt1); + assert(pdt1 == NULL); + OBJ_RELEASE(pdt2); + assert(pdt2 == NULL); /* clean-ups all data allocations */ ompi_datatype_finalize(); diff --git a/test/datatype/external32.c b/test/datatype/external32.c index 9d47e60950..397c5b5e21 100644 --- a/test/datatype/external32.c +++ b/test/datatype/external32.c @@ -15,72 +15,74 @@ #include "ompi_config.h" #include "ompi/datatype/ompi_datatype.h" -#include "opal/runtime/opal.h" #include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype_internal.h" +#include "opal/runtime/opal.h" #include <arpa/inet.h> static int verbose = 0; - -typedef int (*checker_t)(void*, void*, ompi_datatype_t *, int, void*); -int check_contiguous( void* send_buffer, void* packed, - ompi_datatype_t * datatype, int count, void* arg ); +typedef int (*checker_t)(void *, void *, ompi_datatype_t *, int, void *); + +int check_contiguous(void *send_buffer, void *packed, ompi_datatype_t *datatype, int count, + void *arg); -int check_vector( void* send_buffer, void* packed, - ompi_datatype_t * datatype, int count, void* arg ); +int check_vector(void *send_buffer, void *packed, ompi_datatype_t *datatype, int count, void *arg); -static int pack_unpack_datatype( void* send_data, ompi_datatype_t *datatype, int count, - void* recv_data, checker_t validator, void *validator_arg ); +static int pack_unpack_datatype(void *send_data, ompi_datatype_t *datatype, int count, + void *recv_data, checker_t validator, void *validator_arg); -static void -dump_hex(const char* msg, const void* vbuf, int nbytes, - int start_from, int stop_at, int vals_per_line) +static void dump_hex(const char *msg, const void *vbuf, int nbytes, int start_from, int stop_at, + int vals_per_line) { - const char* buf = (const char*)vbuf; + const char *buf = (const char *) vbuf; - if( -1 == stop_at ) stop_at = nbytes; + if (-1 == stop_at) + stop_at = nbytes; for (int i = (start_from / vals_per_line) * vals_per_line; i < nbytes; ++i) { - if( i >= stop_at ) return; + if (i >= stop_at) + return; if (0 == (i % vals_per_line)) { - if( NULL == msg) printf("\n"); - else printf("\n%s", msg); + if (NULL == msg) + printf("\n"); + else + printf("\n%s", msg); } else { if (i % 4 == 0) { printf(" "); } } printf(" "); - if( i < start_from ) + if (i < start_from) printf(" "); else - printf("%02x", *((unsigned char *)(buf + i))); + printf("%02x", *((unsigned char *) (buf + i))); } } -int check_contiguous( void* send_buffer, void* packed, - ompi_datatype_t* datatype, int count, void* arg ) +int check_contiguous(void *send_buffer, void *packed, ompi_datatype_t *datatype, int count, + void *arg) { int i; - if( (datatype == &ompi_mpi_int.dt) || (datatype == &ompi_mpi_int32_t.dt) ) { + if ((datatype == &ompi_mpi_int.dt) || (datatype == &ompi_mpi_int32_t.dt)) { uint32_t val; - for( i = 0 ; i < count; i++ ) { - val = htonl(((uint32_t*)send_buffer)[i]); - if( val != ((uint32_t*)packed)[i] ) { - printf("Error at position %d expected %x found %x (type %s)\n", - i, ((uint32_t*)packed)[i], ((uint32_t*)send_buffer)[i], datatype->name); + for (i = 0; i < count; i++) { + val = htonl(((uint32_t *) send_buffer)[i]); + if (val != ((uint32_t *) packed)[i]) { + printf("Error at position %d expected %x found %x (type %s)\n", i, + ((uint32_t *) packed)[i], ((uint32_t *) send_buffer)[i], datatype->name); return -1; } } - } else if( (datatype == &ompi_mpi_short.dt) || (datatype == &ompi_mpi_int16_t.dt) ) { + } else if ((datatype == &ompi_mpi_short.dt) || (datatype == &ompi_mpi_int16_t.dt)) { uint16_t val; - for( i = 0 ; i < count; i++ ) { - val = htons(((uint16_t*)send_buffer)[i]); - if( val != ((uint16_t*)packed)[i] ) { - printf("Error at position %d expected %x found %x (type %s)\n", - i, ((uint16_t*)packed)[i], ((uint16_t*)send_buffer)[i], datatype->name); + for (i = 0; i < count; i++) { + val = htons(((uint16_t *) send_buffer)[i]); + if (val != ((uint16_t *) packed)[i]) { + printf("Error at position %d expected %x found %x (type %s)\n", i, + ((uint16_t *) packed)[i], ((uint16_t *) send_buffer)[i], datatype->name); return -1; } } @@ -91,29 +93,28 @@ int check_contiguous( void* send_buffer, void* packed, return 0; } -int check_vector( void* send_buffer, void* packed, - ompi_datatype_t* datatype, int count, void* arg ) +int check_vector(void *send_buffer, void *packed, ompi_datatype_t *datatype, int count, void *arg) { int i; - ompi_datatype_t *origtype = (ompi_datatype_t *)arg; + ompi_datatype_t *origtype = (ompi_datatype_t *) arg; - if( (origtype == &ompi_mpi_int.dt) || (origtype == &ompi_mpi_int32_t.dt) ) { + if ((origtype == &ompi_mpi_int.dt) || (origtype == &ompi_mpi_int32_t.dt)) { uint32_t val; - for( i = 0 ; i < count; i++ ) { - val = htonl(((uint32_t*)send_buffer)[2*i]); - if( val != ((uint32_t*)packed)[i] ) { - printf("Error at position %d expected %x found %x (type %s)\n", - i, ((uint32_t*)packed)[i], ((uint32_t*)send_buffer)[2*i], datatype->name); + for (i = 0; i < count; i++) { + val = htonl(((uint32_t *) send_buffer)[2 * i]); + if (val != ((uint32_t *) packed)[i]) { + printf("Error at position %d expected %x found %x (type %s)\n", i, + ((uint32_t *) packed)[i], ((uint32_t *) send_buffer)[2 * i], datatype->name); return -1; } } - } else if( (origtype == &ompi_mpi_short.dt) || (origtype == &ompi_mpi_int16_t.dt) ) { + } else if ((origtype == &ompi_mpi_short.dt) || (origtype == &ompi_mpi_int16_t.dt)) { uint16_t val; - for( i = 0 ; i < count; i++ ) { - val = htons(((uint16_t*)send_buffer)[2*i]); - if( val != ((uint16_t*)packed)[i] ) { - printf("Error at position %d expected %x found %x (type %s)\n", - i, ((uint16_t*)packed)[i], ((uint16_t*)send_buffer)[2*i], datatype->name); + for (i = 0; i < count; i++) { + val = htons(((uint16_t *) send_buffer)[2 * i]); + if (val != ((uint16_t *) packed)[i]) { + printf("Error at position %d expected %x found %x (type %s)\n", i, + ((uint16_t *) packed)[i], ((uint16_t *) send_buffer)[2 * i], datatype->name); return -1; } } @@ -124,39 +125,44 @@ int check_vector( void* send_buffer, void* packed, return 0; } -static int pack_unpack_datatype( void* send_data, ompi_datatype_t *datatype, int count, - void* recv_data, - checker_t validator, void* validator_arg) +static int pack_unpack_datatype(void *send_data, ompi_datatype_t *datatype, int count, + void *recv_data, checker_t validator, void *validator_arg) { MPI_Aint position = 0, buffer_size; - void* buffer; + void *buffer; int error; - error = ompi_datatype_pack_external_size("external32", - count, datatype, &buffer_size); - if( MPI_SUCCESS != error ) goto return_error_code; + error = ompi_datatype_pack_external_size("external32", count, datatype, &buffer_size); + if (MPI_SUCCESS != error) + goto return_error_code; - buffer = (void*)malloc(buffer_size); - if( NULL == buffer ) { error = MPI_ERR_UNKNOWN; goto return_error_code; } + buffer = (void *) malloc(buffer_size); + if (NULL == buffer) { + error = MPI_ERR_UNKNOWN; + goto return_error_code; + } - error = ompi_datatype_pack_external("external32", (void*)send_data, count, datatype, - buffer, buffer_size, &position); - if( MPI_SUCCESS != error ) goto return_error_code; - if( 0 != validator(send_data, buffer, datatype, count, validator_arg) ) { + error = ompi_datatype_pack_external("external32", (void *) send_data, count, datatype, buffer, + buffer_size, &position); + if (MPI_SUCCESS != error) + goto return_error_code; + if (0 != validator(send_data, buffer, datatype, count, validator_arg)) { printf("Error during pack external. Bailing out\n"); return -1; } printf("packed %ld bytes into a %ld bytes buffer ", position, buffer_size); - dump_hex(NULL, buffer, position, 0, -1, 24); printf("\n"); + dump_hex(NULL, buffer, position, 0, -1, 24); + printf("\n"); position = 0; - error = ompi_datatype_unpack_external("external32", buffer, buffer_size, &position, - recv_data, count, datatype); - if( MPI_SUCCESS != error ) goto return_error_code; + error = ompi_datatype_unpack_external("external32", buffer, buffer_size, &position, recv_data, + count, datatype); + if (MPI_SUCCESS != error) + goto return_error_code; free(buffer); - return_error_code: +return_error_code: return (error == MPI_SUCCESS ? 0 : -1); } @@ -170,19 +176,21 @@ int main(int argc, char *argv[]) int32_t send_data[2] = {1234, 5678}; int32_t recv_data[2] = {-1, -1}; - if( verbose ) { + if (verbose) { printf("send data %08x %08x \n", send_data[0], send_data[1]); printf("data "); - dump_hex(NULL, &send_data, sizeof(int32_t) * 2, 0, -1, 24); printf("\n"); + dump_hex(NULL, &send_data, sizeof(int32_t) * 2, 0, -1, 24); + printf("\n"); } - (void)pack_unpack_datatype( send_data, &ompi_mpi_int32_t.dt, 2, - recv_data, check_contiguous, (void*)&ompi_mpi_int32_t.dt ); - if( verbose ) { + (void) pack_unpack_datatype(send_data, &ompi_mpi_int32_t.dt, 2, recv_data, check_contiguous, + (void *) &ompi_mpi_int32_t.dt); + if (verbose) { printf("recv "); - dump_hex(NULL, &recv_data, sizeof(int32_t) * 2, 0, -1, 24); printf("\n"); + dump_hex(NULL, &recv_data, sizeof(int32_t) * 2, 0, -1, 24); + printf("\n"); printf("recv data %08x %08x \n", recv_data[0], recv_data[1]); } - if( (send_data[0] != recv_data[0]) || (send_data[1] != recv_data[1]) ) { + if ((send_data[0] != recv_data[0]) || (send_data[1] != recv_data[1])) { printf("Error during external32 pack/unack for contiguous types (MPI_INT32_T)\n"); exit(-1); } @@ -192,19 +200,21 @@ int main(int argc, char *argv[]) int16_t send_data[2] = {1234, 5678}; int16_t recv_data[2] = {-1, -1}; - if( verbose ) { + if (verbose) { printf("send data %08x %08x \n", send_data[0], send_data[1]); printf("data "); - dump_hex(NULL, &send_data, sizeof(int16_t) * 2, 0, -1, 24); printf("\n"); + dump_hex(NULL, &send_data, sizeof(int16_t) * 2, 0, -1, 24); + printf("\n"); } - (void)pack_unpack_datatype( send_data, &ompi_mpi_int16_t.dt, 2, - recv_data, check_contiguous, (void*)&ompi_mpi_int16_t.dt ); - if( verbose ) { + (void) pack_unpack_datatype(send_data, &ompi_mpi_int16_t.dt, 2, recv_data, check_contiguous, + (void *) &ompi_mpi_int16_t.dt); + if (verbose) { printf("recv "); - dump_hex(NULL, &recv_data, sizeof(int16_t) * 2, 0, -1, 24); printf("\n"); + dump_hex(NULL, &recv_data, sizeof(int16_t) * 2, 0, -1, 24); + printf("\n"); printf("recv data %08x %08x \n", recv_data[0], recv_data[1]); } - if( (send_data[0] != recv_data[0]) || (send_data[1] != recv_data[1]) ) { + if ((send_data[0] != recv_data[0]) || (send_data[1] != recv_data[1])) { printf("Error during external32 pack/unack for contiguous types\n"); exit(-1); } @@ -213,31 +223,36 @@ int main(int argc, char *argv[]) /* Vector datatype */ printf("\n\nVector datatype\n\n"); { - int count=2, blocklength=1, stride=2; + int count = 2, blocklength = 1, stride = 2; int send_data[3] = {1234, 0, 5678}; int recv_data[3] = {-1, -1, -1}; ompi_datatype_t *ddt; - ompi_datatype_create_vector ( count, blocklength, stride, &ompi_mpi_int.dt, &ddt ); + ompi_datatype_create_vector(count, blocklength, stride, &ompi_mpi_int.dt, &ddt); { - const int* a_i[3] = {&count, &blocklength, &stride}; + const int *a_i[3] = {&count, &blocklength, &stride}; ompi_datatype_t *type = &ompi_mpi_int.dt; - ompi_datatype_set_args( ddt, 3, a_i, 0, NULL, 1, &type, MPI_COMBINER_VECTOR ); + ompi_datatype_set_args(ddt, 3, a_i, 0, NULL, 1, &type, MPI_COMBINER_VECTOR); } ompi_datatype_commit(&ddt); - if( verbose ) { + if (verbose) { printf("send data %08x %x08x %08x \n", send_data[0], send_data[1], send_data[2]); - printf("data "); dump_hex(NULL, &send_data, sizeof(int32_t) * 3, 0, -1, 24); printf("\n"); + printf("data "); + dump_hex(NULL, &send_data, sizeof(int32_t) * 3, 0, -1, 24); + printf("\n"); } - (void)pack_unpack_datatype( send_data, ddt, 1, recv_data, check_vector, (void*)&ompi_mpi_int32_t.dt ); - if( verbose ) { - printf("recv "); dump_hex(NULL, &recv_data, sizeof(int32_t) * 3, 0, -1, 24); printf("\n"); + (void) pack_unpack_datatype(send_data, ddt, 1, recv_data, check_vector, + (void *) &ompi_mpi_int32_t.dt); + if (verbose) { + printf("recv "); + dump_hex(NULL, &recv_data, sizeof(int32_t) * 3, 0, -1, 24); + printf("\n"); printf("recv data %08x %08x %08x \n", recv_data[0], recv_data[1], recv_data[2]); } ompi_datatype_destroy(&ddt); - if( (send_data[0] != recv_data[0]) || (send_data[2] != recv_data[2]) ) { + if ((send_data[0] != recv_data[0]) || (send_data[2] != recv_data[2])) { printf("Error during external32 pack/unack for vector types (MPI_INT32_T)\n"); printf("[0]: %d ? %d | [2]: %d ? %d ([1]: %d ? %d)\n", send_data[0], recv_data[0], send_data[2], recv_data[2], send_data[1], recv_data[1]); diff --git a/test/datatype/large_data.c b/test/datatype/large_data.c index 1c031b3662..df1d58eb11 100644 --- a/test/datatype/large_data.c +++ b/test/datatype/large_data.c @@ -16,75 +16,73 @@ */ #include <mpi.h> -#include <stdio.h> #include <stddef.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include "ompi_config.h" #include "ompi/datatype/ompi_datatype.h" -#include "opal/runtime/opal.h" #include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype_internal.h" +#include "opal/runtime/opal.h" #define MAX_IOVEC 10 -#define MAX_CHUNK (1024*1024*1024) /* 1GB */ +#define MAX_CHUNK (1024 * 1024 * 1024) /* 1GB */ static int verbose = 0; -static size_t -count_length_via_convertor_raw(char* msg, - MPI_Datatype dtype, int count) +static size_t count_length_via_convertor_raw(char *msg, MPI_Datatype dtype, int count) { - opal_convertor_t* pconv; + opal_convertor_t *pconv; struct iovec iov[MAX_IOVEC]; uint32_t iov_count = MAX_IOVEC, i; size_t length = MAX_CHUNK, packed_iovec = 0, packed = 0; - pconv = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_prepare_for_send(pconv, (const struct opal_datatype_t *)dtype, 1, NULL); - while( 0 == opal_convertor_raw(pconv, iov, &iov_count, &length) ) { - if( verbose ) { - printf("iov_count = %d packed_iovec = %"PRIsize_t" length = %"PRIsize_t"\n", + pconv = opal_convertor_create(opal_local_arch, 0); + opal_convertor_prepare_for_send(pconv, (const struct opal_datatype_t *) dtype, 1, NULL); + while (0 == opal_convertor_raw(pconv, iov, &iov_count, &length)) { + if (verbose) { + printf("iov_count = %d packed_iovec = %" PRIsize_t " length = %" PRIsize_t "\n", iov_count, packed_iovec, length); } packed += length; - for( i = 0; i < iov_count; i++ ) { + for (i = 0; i < iov_count; i++) { packed_iovec += iov[i].iov_len; - if( verbose ) { - printf("[%s] add %"PRIsize_t" bytes -> so far %"PRIsize_t" bytes\n", - msg, iov[i].iov_len, packed_iovec); + if (verbose) { + printf("[%s] add %" PRIsize_t " bytes -> so far %" PRIsize_t " bytes\n", msg, + iov[i].iov_len, packed_iovec); } } - if( packed != packed_iovec ) { - printf( "[%s] Raw data amount diverges %"PRIsize_t" != %"PRIsize_t"\n", - msg, packed, packed_iovec); + if (packed != packed_iovec) { + printf("[%s] Raw data amount diverges %" PRIsize_t " != %" PRIsize_t "\n", msg, packed, + packed_iovec); exit(-1); } - iov_count = MAX_IOVEC; /* number of available iov */ + iov_count = MAX_IOVEC; /* number of available iov */ length = MAX_CHUNK; } - if( verbose ) { - printf("iov_count = %d packed_iovec = %"PRIsize_t" length = %"PRIsize_t"\n", - iov_count, packed_iovec, length); + if (verbose) { + printf("iov_count = %d packed_iovec = %" PRIsize_t " length = %" PRIsize_t "\n", iov_count, + packed_iovec, length); } packed += length; - for( i = 0; i < iov_count; i++ ) { + for (i = 0; i < iov_count; i++) { packed_iovec += iov[i].iov_len; - if( verbose ) { - printf("[%s] add %"PRIsize_t" bytes -> so far %"PRIsize_t" bytes\n", - msg, iov[i].iov_len, packed_iovec); + if (verbose) { + printf("[%s] add %" PRIsize_t " bytes -> so far %" PRIsize_t " bytes\n", msg, + iov[i].iov_len, packed_iovec); } } - if( packed != packed_iovec ) { - printf( "[%s] Raw data amount diverges %"PRIsize_t" != %"PRIsize_t"\n", - msg, packed, packed_iovec); + if (packed != packed_iovec) { + printf("[%s] Raw data amount diverges %" PRIsize_t " != %" PRIsize_t "\n", msg, packed, + packed_iovec); exit(-1); } return packed_iovec; } -int main(int argc, char * argv[]) +int main(int argc, char *argv[]) { int const per_process = 192; @@ -92,9 +90,9 @@ int main(int argc, char * argv[]) int blocklen, stride, count; int scounts[2] = {per_process, per_process}; - int sdispls[2] = {3*per_process, 0*per_process}; + int sdispls[2] = {3 * per_process, 0 * per_process}; int rcounts[2] = {per_process, per_process}; - int rdispls[2] = {1*per_process, 2*per_process}; + int rdispls[2] = {1 * per_process, 2 * per_process}; MPI_Datatype ddt, stype, rtype; size_t length, packed; @@ -102,7 +100,7 @@ int main(int argc, char * argv[]) opal_init_util(&argc, &argv); ompi_datatype_init(); - ompi_datatype_create_contiguous( per_type, MPI_FLOAT, &ddt); + ompi_datatype_create_contiguous(per_type, MPI_FLOAT, &ddt); /* * Large sparse datatype: indexed contiguous @@ -112,8 +110,9 @@ int main(int argc, char * argv[]) packed = count_length_via_convertor_raw("1. INDEX", stype, 1); opal_datatype_type_size(&stype->super, &length); - if( length != packed ) { - printf("Mismatched length of packed data to datatype size (%"PRIsize_t" != %"PRIsize_t")\n", + if (length != packed) { + printf("Mismatched length of packed data to datatype size (%" PRIsize_t " != %" PRIsize_t + ")\n", packed, length); exit(-2); } @@ -127,8 +126,9 @@ int main(int argc, char * argv[]) packed = count_length_via_convertor_raw("2. INDEX", rtype, 1); opal_datatype_type_size(&rtype->super, &length); - if( length != packed ) { - printf("Mismatched length of packed data to datatype size (%"PRIsize_t" != %"PRIsize_t")\n", + if (length != packed) { + printf("Mismatched length of packed data to datatype size (%" PRIsize_t " != %" PRIsize_t + ")\n", packed, length); exit(-2); } @@ -145,8 +145,9 @@ int main(int argc, char * argv[]) packed = count_length_via_convertor_raw("3. VECTOR", ddt, 1); opal_datatype_type_size(&ddt->super, &length); - if( length != packed ) { - printf("Mismatched length of packed data to datatype size (%"PRIsize_t" != %"PRIsize_t")\n", + if (length != packed) { + printf("Mismatched length of packed data to datatype size (%" PRIsize_t " != %" PRIsize_t + ")\n", packed, length); exit(-2); } @@ -162,8 +163,9 @@ int main(int argc, char * argv[]) packed = count_length_via_convertor_raw("4. CONTIG", ddt, 1); opal_datatype_type_size(&ddt->super, &length); - if( length != packed ) { - printf("Mismatched length of packed data to datatype size (%"PRIsize_t" != %"PRIsize_t")\n", + if (length != packed) { + printf("Mismatched length of packed data to datatype size (%" PRIsize_t " != %" PRIsize_t + ")\n", packed, length); exit(-2); } diff --git a/test/datatype/opal_datatype_test.c b/test/datatype/opal_datatype_test.c index ab5c9484fa..f098e2582b 100644 --- a/test/datatype/opal_datatype_test.c +++ b/test/datatype/opal_datatype_test.c @@ -24,26 +24,28 @@ */ #include "opal_config.h" -#include "opal_ddt_lib.h" -#include "opal/runtime/opal.h" +#include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" -#include "opal/datatype/opal_convertor.h" -#include <time.h> +#include "opal/runtime/opal.h" +#include "opal_ddt_lib.h" #include <stdlib.h> +#include <time.h> #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #endif #include <stdio.h> #include <string.h> /* Compile with: -gcc -DHAVE_CONFIG_H -I. -I../../include -I../.. -I../../include -I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -g opal_datatype_test.c -o opal_datatype_test +gcc -DHAVE_CONFIG_H -I. -I../../include -I../.. -I../../include -I../../../ompi-trunk/opal +-I../../../ompi-trunk/orte -g opal_datatype_test.c -o opal_datatype_test */ #define TIMER_DATA_TYPE struct timeval -#define GET_TIME(TV) gettimeofday( &(TV), NULL ) -#define ELAPSED_TIME(TSTART, TEND) (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) +#define GET_TIME(TV) gettimeofday(&(TV), NULL) +#define ELAPSED_TIME(TSTART, TEND) \ + (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) uint32_t remote_arch = 0xffffffff; @@ -51,21 +53,21 @@ uint32_t remote_arch = 0xffffffff; * Generic function computing the amount of memory to be allocated to fit * a contiguous memory layout of count times pdt. */ -static size_t compute_memory_size( opal_datatype_t const * const pdt, int count ) +static size_t compute_memory_size(opal_datatype_t const *const pdt, int count) { ptrdiff_t extent, true_lb, true_extent; - opal_datatype_type_extent( pdt, &extent ); - opal_datatype_get_true_extent( pdt, &true_lb, &true_extent ); + opal_datatype_type_extent(pdt, &extent); + opal_datatype_get_true_extent(pdt, &true_lb, &true_extent); - return (size_t)(true_lb + true_extent + (count-1) * extent); + return (size_t)(true_lb + true_extent + (count - 1) * extent); } -static int test_upper( unsigned int length ) +static int test_upper(unsigned int length) { double *mat1, *mat2, *inbuf; opal_datatype_t *pdt; - opal_convertor_t * pConv; + opal_convertor_t *pConv; char *ptr; int rc; unsigned int i, j, iov_count, split_chunk, total_length; @@ -75,64 +77,64 @@ static int test_upper( unsigned int length ) long total_time; /*printf( "test upper matrix\n" );*/ - pdt = upper_matrix( length ); + pdt = upper_matrix(length); /*opal_datatype_dump( pdt );*/ - mat1 = malloc( length * length * sizeof(double) ); - init_random_upper_matrix( length, mat1 ); - mat2 = calloc( length * length, sizeof(double) ); + mat1 = malloc(length * length * sizeof(double)); + init_random_upper_matrix(length, mat1); + mat2 = calloc(length * length, sizeof(double)); - total_length = length * (length + 1) * ( sizeof(double) / 2); - inbuf = (double*)malloc( total_length ); - ptr = (char*)inbuf; + total_length = length * (length + 1) * (sizeof(double) / 2); + inbuf = (double *) malloc(total_length); + ptr = (char *) inbuf; /* copy upper matrix in the array simulating the input buffer */ - for( i = 0; i < length; i++ ) { + for (i = 0; i < length; i++) { uint32_t pos = i * length + i; - for( j = i; j < length; j++, pos++ ) { + for (j = i; j < length; j++, pos++) { *inbuf = mat1[pos]; inbuf++; } } - inbuf = (double*)ptr; - pConv = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, pdt, 1, mat2 ) ) { - printf( "Cannot attach the datatype to a convertor\n" ); + inbuf = (double *) ptr; + pConv = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS != opal_convertor_prepare_for_recv(pConv, pdt, 1, mat2)) { + printf("Cannot attach the datatype to a convertor\n"); return OPAL_ERROR; } - GET_TIME( start ); + GET_TIME(start); split_chunk = (length + 1) * sizeof(double); /* split_chunk = (total_length + 1) * sizeof(double); */ - for( i = total_length; i > 0; ) { - if( i <= split_chunk ) { /* equal test just to be able to set a breakpoint */ + for (i = total_length; i > 0;) { + if (i <= split_chunk) { /* equal test just to be able to set a breakpoint */ split_chunk = i; } a.iov_base = ptr; a.iov_len = split_chunk; iov_count = 1; max_data = split_chunk; - opal_convertor_unpack( pConv, &a, &iov_count, &max_data ); + opal_convertor_unpack(pConv, &a, &iov_count, &max_data); ptr += max_data; i -= max_data; - if( mat2[0] != inbuf[0] ) assert(0); + if (mat2[0] != inbuf[0]) + assert(0); } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "complete unpacking in %ld microsec\n", total_time ); - free( inbuf ); - rc = check_diag_matrix( length, mat1, mat2 ); - free( mat1 ); - free( mat2 ); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("complete unpacking in %ld microsec\n", total_time); + free(inbuf); + rc = check_diag_matrix(length, mat1, mat2); + free(mat1); + free(mat2); /* test the automatic destruction pf the data */ - opal_datatype_destroy( &pdt ); - assert( pdt == NULL ); + opal_datatype_destroy(&pdt); + assert(pdt == NULL); - OBJ_RELEASE( pConv ); + OBJ_RELEASE(pConv); return rc; } - /** * Conversion function. They deal with data-types in 3 ways, always making local copies. * In order to allow performance testings, there are 3 functions: @@ -142,7 +144,7 @@ static int test_upper( unsigned int length ) * - and one using 2 convertors created from different data-types. * */ -static int local_copy_ddt_count( opal_datatype_t const * const pdt, int count ) +static int local_copy_ddt_count(opal_datatype_t const *const pdt, int count) { ptrdiff_t lb, extent; size_t malloced_size; @@ -153,57 +155,59 @@ static int local_copy_ddt_count( opal_datatype_t const * const pdt, int count ) int errors = 0; malloced_size = compute_memory_size(pdt, count); - opal_datatype_get_extent( pdt, &lb, &extent ); + opal_datatype_get_extent(pdt, &lb, &extent); - odst = (char*)malloc( malloced_size ); - osrc = (char*)malloc( malloced_size ); + odst = (char *) malloc(malloced_size); + osrc = (char *) malloc(malloced_size); { - for( size_t i = 0; i < malloced_size; i++ ) osrc[i] = i % 128 + 32; + for (size_t i = 0; i < malloced_size; i++) + osrc[i] = i % 128 + 32; memcpy(odst, osrc, malloced_size); } pdst = odst - lb; psrc = osrc - lb; - cache_trash(); /* make sure the cache is useless */ - - GET_TIME( start ); - if( OPAL_SUCCESS != opal_datatype_copy_content_same_ddt( pdt, count, pdst, psrc ) ) { - printf( "Unable to copy the datatype in the function local_copy_ddt_count." - " Is the datatype committed ?\n" ); - } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "direct local copy in %ld microsec\n", total_time ); - if(outputFlags & VALIDATE_DATA) { - for( size_t i = 0; i < malloced_size; i++ ) { - if( odst[i] != osrc[i] ) { - printf("error at position %lu (%d != %d)\n", - (unsigned long)i, (int)(odst[i]), (int)(osrc[i])); + cache_trash(); /* make sure the cache is useless */ + + GET_TIME(start); + if (OPAL_SUCCESS != opal_datatype_copy_content_same_ddt(pdt, count, pdst, psrc)) { + printf("Unable to copy the datatype in the function local_copy_ddt_count." + " Is the datatype committed ?\n"); + } + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("direct local copy in %ld microsec\n", total_time); + if (outputFlags & VALIDATE_DATA) { + for (size_t i = 0; i < malloced_size; i++) { + if (odst[i] != osrc[i]) { + printf("error at position %lu (%d != %d)\n", (unsigned long) i, (int) (odst[i]), + (int) (osrc[i])); errors++; - if(outputFlags & QUIT_ON_FIRST_ERROR) { + if (outputFlags & QUIT_ON_FIRST_ERROR) { opal_datatype_dump(pdt); - assert(0); exit(-1); + assert(0); + exit(-1); } } } - if( 0 == errors ) { + if (0 == errors) { printf("Validation check successfully passed\n"); } else { printf("Found %d errors. Giving up!\n", errors); exit(-1); } } - free( odst ); - free( osrc ); + free(odst); + free(osrc); return (0 == errors ? OPAL_SUCCESS : errors); } -static int -local_copy_with_convertor_2datatypes( opal_datatype_t const * const send_type, int send_count, - opal_datatype_t const * const recv_type, int recv_count, - int chunk ) +static int local_copy_with_convertor_2datatypes(opal_datatype_t const *const send_type, + int send_count, + opal_datatype_t const *const recv_type, + int recv_count, int chunk) { ptrdiff_t send_lb, send_extent, recv_lb, recv_extent; void *pdst = NULL, *psrc = NULL, *ptemp = NULL; @@ -211,7 +215,8 @@ local_copy_with_convertor_2datatypes( opal_datatype_t const * const send_type, i opal_convertor_t *send_convertor = NULL, *recv_convertor = NULL; struct iovec iov; uint32_t iov_count; - size_t max_data, length = 0, send_malloced_size, recv_malloced_size;; + size_t max_data, length = 0, send_malloced_size, recv_malloced_size; + ; int32_t done1 = 0, done2 = 0; TIMER_DATA_TYPE start, end, unpack_start, unpack_end; long total_time, unpack_time = 0; @@ -219,42 +224,44 @@ local_copy_with_convertor_2datatypes( opal_datatype_t const * const send_type, i send_malloced_size = compute_memory_size(send_type, send_count); recv_malloced_size = compute_memory_size(recv_type, recv_count); - opal_datatype_get_extent( send_type, &send_lb, &send_extent ); - opal_datatype_get_extent( recv_type, &recv_lb, &recv_extent ); + opal_datatype_get_extent(send_type, &send_lb, &send_extent); + opal_datatype_get_extent(recv_type, &recv_lb, &recv_extent); - odst = (char*)malloc( recv_malloced_size ); - osrc = (char*)malloc( send_malloced_size ); - ptemp = malloc( chunk ); + odst = (char *) malloc(recv_malloced_size); + osrc = (char *) malloc(send_malloced_size); + ptemp = malloc(chunk); /* fill up the receiver with ZEROS */ { - for( size_t i = 0; i < send_malloced_size; i++ ) + for (size_t i = 0; i < send_malloced_size; i++) osrc[i] = i % 128 + 32; } - memset( odst, 0, recv_malloced_size ); - pdst = odst - recv_lb; - psrc = osrc - send_lb; + memset(odst, 0, recv_malloced_size); + pdst = odst - recv_lb; + psrc = osrc - send_lb; - send_convertor = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_send( send_convertor, send_type, send_count, psrc ) ) { - printf( "Unable to create the send convertor. Is the datatype committed ?\n" ); + send_convertor = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS + != opal_convertor_prepare_for_send(send_convertor, send_type, send_count, psrc)) { + printf("Unable to create the send convertor. Is the datatype committed ?\n"); goto clean_and_return; } - recv_convertor = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( recv_convertor, recv_type, recv_count, pdst ) ) { - printf( "Unable to create the recv convertor. Is the datatype committed ?\n" ); + recv_convertor = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS + != opal_convertor_prepare_for_recv(recv_convertor, recv_type, recv_count, pdst)) { + printf("Unable to create the recv convertor. Is the datatype committed ?\n"); goto clean_and_return; } - cache_trash(); /* make sure the cache is useless */ + cache_trash(); /* make sure the cache is useless */ - GET_TIME( start ); - while( (done1 & done2) != 1 ) { + GET_TIME(start); + while ((done1 & done2) != 1) { /* They are supposed to finish in exactly the same time. */ - if( done1 | done2 ) { - printf( "WRONG !!! the send is %s but the receive is %s in local_copy_with_convertor_2datatypes\n", - (done1 ? "finish" : "not finish"), - (done2 ? "finish" : "not finish") ); + if (done1 | done2) { + printf("WRONG !!! the send is %s but the receive is %s in " + "local_copy_with_convertor_2datatypes\n", + (done1 ? "finish" : "not finish"), (done2 ? "finish" : "not finish")); } max_data = chunk; @@ -262,20 +269,20 @@ local_copy_with_convertor_2datatypes( opal_datatype_t const * const send_type, i iov.iov_base = ptemp; iov.iov_len = chunk; - if( done1 == 0 ) { - done1 = opal_convertor_pack( send_convertor, &iov, &iov_count, &max_data ); + if (done1 == 0) { + done1 = opal_convertor_pack(send_convertor, &iov, &iov_count, &max_data); } - if( done2 == 0 ) { - GET_TIME( unpack_start ); - done2 = opal_convertor_unpack( recv_convertor, &iov, &iov_count, &max_data ); - GET_TIME( unpack_end ); - unpack_time += ELAPSED_TIME( unpack_start, unpack_end ); + if (done2 == 0) { + GET_TIME(unpack_start); + done2 = opal_convertor_unpack(recv_convertor, &iov, &iov_count, &max_data); + GET_TIME(unpack_end); + unpack_time += ELAPSED_TIME(unpack_start, unpack_end); } length += max_data; - if( outputFlags & RESET_CONVERTORS ) { + if (outputFlags & RESET_CONVERTORS) { size_t pos = 0; opal_convertor_set_position(send_convertor, &pos); pos = length; @@ -289,25 +296,30 @@ local_copy_with_convertor_2datatypes( opal_datatype_t const * const send_type, i assert(pos == length); } } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "copying different data-types using convertors in %ld microsec\n", total_time ); - printf( "\t unpack in %ld microsec [pack in %ld microsec]\n", unpack_time, - total_time - unpack_time ); - clean_and_return: - if( send_convertor != NULL ) { - OBJ_RELEASE( send_convertor ); assert( send_convertor == NULL ); - } - if( recv_convertor != NULL ) { - OBJ_RELEASE( recv_convertor ); assert( recv_convertor == NULL ); - } - if( NULL != odst ) free( odst ); - if( NULL != osrc ) free( osrc ); - if( NULL != ptemp ) free( ptemp ); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("copying different data-types using convertors in %ld microsec\n", total_time); + printf("\t unpack in %ld microsec [pack in %ld microsec]\n", unpack_time, + total_time - unpack_time); +clean_and_return: + if (send_convertor != NULL) { + OBJ_RELEASE(send_convertor); + assert(send_convertor == NULL); + } + if (recv_convertor != NULL) { + OBJ_RELEASE(recv_convertor); + assert(recv_convertor == NULL); + } + if (NULL != odst) + free(odst); + if (NULL != osrc) + free(osrc); + if (NULL != ptemp) + free(ptemp); return OPAL_SUCCESS; } -static int local_copy_with_convertor( opal_datatype_t const * const pdt, int count, int chunk ) +static int local_copy_with_convertor(opal_datatype_t const *const pdt, int count, int chunk) { ptrdiff_t lb, extent; void *pdst = NULL, *psrc = NULL, *ptemp = NULL; @@ -321,40 +333,40 @@ static int local_copy_with_convertor( opal_datatype_t const * const pdt, int cou long total_time, unpack_time = 0; malloced_size = compute_memory_size(pdt, count); - opal_datatype_get_extent( pdt, &lb, &extent ); + opal_datatype_get_extent(pdt, &lb, &extent); - odst = (char*)malloc( malloced_size ); - osrc = (char*)malloc( malloced_size ); - ptemp = malloc( chunk ); + odst = (char *) malloc(malloced_size); + osrc = (char *) malloc(malloced_size); + ptemp = malloc(chunk); { - for( size_t i = 0; i < malloced_size; osrc[i] = i % 128 + 32, i++ ); + for (size_t i = 0; i < malloced_size; osrc[i] = i % 128 + 32, i++) + ; memcpy(odst, osrc, malloced_size); } - pdst = odst - lb; - psrc = osrc - lb; + pdst = odst - lb; + psrc = osrc - lb; - send_convertor = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_send( send_convertor, pdt, count, psrc ) ) { - printf( "Unable to create the send convertor. Is the datatype committed ?\n" ); + send_convertor = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS != opal_convertor_prepare_for_send(send_convertor, pdt, count, psrc)) { + printf("Unable to create the send convertor. Is the datatype committed ?\n"); goto clean_and_return; } - recv_convertor = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( recv_convertor, pdt, count, pdst ) ) { - printf( "Unable to create the recv convertor. Is the datatype committed ?\n" ); + recv_convertor = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS != opal_convertor_prepare_for_recv(recv_convertor, pdt, count, pdst)) { + printf("Unable to create the recv convertor. Is the datatype committed ?\n"); goto clean_and_return; } - cache_trash(); /* make sure the cache is useless */ + cache_trash(); /* make sure the cache is useless */ - GET_TIME( start ); - while( (done1 & done2) != 1 ) { + GET_TIME(start); + while ((done1 & done2) != 1) { /* They are supposed to finish in exactly the same time. */ - if( done1 | done2 ) { - printf( "WRONG !!! the send is %s but the receive is %s in local_copy_with_convertor\n", - (done1 ? "finish" : "not finish"), - (done2 ? "finish" : "not finish") ); + if (done1 | done2) { + printf("WRONG !!! the send is %s but the receive is %s in local_copy_with_convertor\n", + (done1 ? "finish" : "not finish"), (done2 ? "finish" : "not finish")); } max_data = chunk; @@ -362,131 +374,187 @@ static int local_copy_with_convertor( opal_datatype_t const * const pdt, int cou iov.iov_base = ptemp; iov.iov_len = chunk; - if( done1 == 0 ) { - done1 = opal_convertor_pack( send_convertor, &iov, &iov_count, &max_data ); + if (done1 == 0) { + done1 = opal_convertor_pack(send_convertor, &iov, &iov_count, &max_data); } - if( done2 == 0 ) { - GET_TIME( unpack_start ); - done2 = opal_convertor_unpack( recv_convertor, &iov, &iov_count, &max_data ); - GET_TIME( unpack_end ); - unpack_time += ELAPSED_TIME( unpack_start, unpack_end ); + if (done2 == 0) { + GET_TIME(unpack_start); + done2 = opal_convertor_unpack(recv_convertor, &iov, &iov_count, &max_data); + GET_TIME(unpack_end); + unpack_time += ELAPSED_TIME(unpack_start, unpack_end); } length += max_data; - if( outputFlags & RESET_CONVERTORS ) { - struct dt_stack_t stack[1+send_convertor->stack_pos]; + if (outputFlags & RESET_CONVERTORS) { + struct dt_stack_t stack[1 + send_convertor->stack_pos]; int i, stack_pos = send_convertor->stack_pos; size_t pos; - if( 0 == done1 ) { - memcpy(stack, send_convertor->pStack, (1+send_convertor->stack_pos) * sizeof(struct dt_stack_t)); + if (0 == done1) { + memcpy(stack, send_convertor->pStack, + (1 + send_convertor->stack_pos) * sizeof(struct dt_stack_t)); pos = 0; opal_convertor_set_position(send_convertor, &pos); pos = length; opal_convertor_set_position(send_convertor, &pos); assert(pos == length); - for(i = 0; i <= stack_pos; i++ ) { - if( stack[i].index != send_convertor->pStack[i].index ) - {errors = 1; printf("send stack[%d].index differs (orig %d != new %d) (completed %lu/%lu)\n", - i, stack[i].index, send_convertor->pStack[i].index, - length, pdt->size * count);} - if( stack[i].count != send_convertor->pStack[i].count ) { - if( stack[i].type == send_convertor->pStack[i].type ) { - {errors = 1; printf("send stack[%d].count differs (orig %lu != new %lu) (completed %lu/%lu)\n", - i, stack[i].count, send_convertor->pStack[i].count, - length, pdt->size * count);} + for (i = 0; i <= stack_pos; i++) { + if (stack[i].index != send_convertor->pStack[i].index) { + errors = 1; + printf("send stack[%d].index differs (orig %d != new %d) (completed " + "%lu/%lu)\n", + i, stack[i].index, send_convertor->pStack[i].index, length, + pdt->size * count); + } + if (stack[i].count != send_convertor->pStack[i].count) { + if (stack[i].type == send_convertor->pStack[i].type) { + { + errors = 1; + printf("send stack[%d].count differs (orig %lu != new %lu) " + "(completed %lu/%lu)\n", + i, stack[i].count, send_convertor->pStack[i].count, length, + pdt->size * count); + } } else { - if( (OPAL_DATATYPE_MAX_PREDEFINED <= stack[i].type) || (OPAL_DATATYPE_MAX_PREDEFINED <= send_convertor->pStack[i].type) ) - {errors = 1; printf("send stack[%d].type wrong (orig %d != new %d) (completed %lu/%lu)\n", - i, (int)stack[i].type, (int)send_convertor->pStack[i].type, - length, pdt->size * count);} - else if( (stack[i].count * opal_datatype_basicDatatypes[stack[i].type]->size) != - (send_convertor->pStack[i].count * opal_datatype_basicDatatypes[send_convertor->pStack[i].type]->size) ) - {errors = 1; printf("send stack[%d].type*count differs (orig (%d,%lu) != new (%d, %lu)) (completed %lu/%lu)\n", - i, (int)stack[i].type, stack[i].count, - (int)send_convertor->pStack[i].type, send_convertor->pStack[i].count, - length, pdt->size * count);} + if ((OPAL_DATATYPE_MAX_PREDEFINED <= stack[i].type) + || (OPAL_DATATYPE_MAX_PREDEFINED + <= send_convertor->pStack[i].type)) { + errors = 1; + printf("send stack[%d].type wrong (orig %d != new %d) (completed " + "%lu/%lu)\n", + i, (int) stack[i].type, (int) send_convertor->pStack[i].type, + length, pdt->size * count); + } else if ((stack[i].count + * opal_datatype_basicDatatypes[stack[i].type]->size) + != (send_convertor->pStack[i].count + * opal_datatype_basicDatatypes[send_convertor->pStack[i] + .type] + ->size)) { + errors = 1; + printf("send stack[%d].type*count differs (orig (%d,%lu) != new " + "(%d, %lu)) (completed %lu/%lu)\n", + i, (int) stack[i].type, stack[i].count, + (int) send_convertor->pStack[i].type, + send_convertor->pStack[i].count, length, pdt->size * count); + } } } - if( stack[i].disp != send_convertor->pStack[i].disp ) - {errors = 1; printf("send stack[%d].disp differs (orig %p != new %p) (completed %lu/%lu)\n", - i, (void*)stack[i].disp, (void*)send_convertor->pStack[i].disp, - length, pdt->size * count);} - if(0 != errors) {assert(0); exit(-1);} + if (stack[i].disp != send_convertor->pStack[i].disp) { + errors = 1; + printf( + "send stack[%d].disp differs (orig %p != new %p) (completed %lu/%lu)\n", + i, (void *) stack[i].disp, (void *) send_convertor->pStack[i].disp, + length, pdt->size * count); + } + if (0 != errors) { + assert(0); + exit(-1); + } } } - if( 0 == done2 ) { - memcpy(stack, recv_convertor->pStack, (1+recv_convertor->stack_pos) * sizeof(struct dt_stack_t)); + if (0 == done2) { + memcpy(stack, recv_convertor->pStack, + (1 + recv_convertor->stack_pos) * sizeof(struct dt_stack_t)); pos = 0; opal_convertor_set_position(recv_convertor, &pos); pos = length; opal_convertor_set_position(recv_convertor, &pos); assert(pos == length); - for(i = 0; i <= stack_pos; i++ ) { - if( stack[i].index != recv_convertor->pStack[i].index ) - {errors = 1; printf("recv stack[%d].index differs (orig %d != new %d) (completed %lu/%lu)\n", - i, stack[i].index, recv_convertor->pStack[i].index, - length, pdt->size * count);} - if( stack[i].count != recv_convertor->pStack[i].count ) { - if( stack[i].type == recv_convertor->pStack[i].type ) { - {errors = 1; printf("recv stack[%d].count differs (orig %lu != new %lu) (completed %lu/%lu)\n", - i, stack[i].count, recv_convertor->pStack[i].count, - length, pdt->size * count);} + for (i = 0; i <= stack_pos; i++) { + if (stack[i].index != recv_convertor->pStack[i].index) { + errors = 1; + printf("recv stack[%d].index differs (orig %d != new %d) (completed " + "%lu/%lu)\n", + i, stack[i].index, recv_convertor->pStack[i].index, length, + pdt->size * count); + } + if (stack[i].count != recv_convertor->pStack[i].count) { + if (stack[i].type == recv_convertor->pStack[i].type) { + { + errors = 1; + printf("recv stack[%d].count differs (orig %lu != new %lu) " + "(completed %lu/%lu)\n", + i, stack[i].count, recv_convertor->pStack[i].count, length, + pdt->size * count); + } } else { - if( (OPAL_DATATYPE_MAX_PREDEFINED <= stack[i].type) || (OPAL_DATATYPE_MAX_PREDEFINED <= recv_convertor->pStack[i].type) ) - {errors = 1; printf("recv stack[%d].type wrong (orig %d != new %d) (completed %lu/%lu)\n", - i, (int)stack[i].type, (int)recv_convertor->pStack[i].type, - length, pdt->size * count);} - else if( (stack[i].count * opal_datatype_basicDatatypes[stack[i].type]->size) != - (recv_convertor->pStack[i].count * opal_datatype_basicDatatypes[recv_convertor->pStack[i].type]->size) ) - {errors = 1; printf("recv stack[%d].type*count differs (orig (%d,%lu) != new (%d, %lu)) (completed %lu/%lu)\n", - i, (int)stack[i].type, stack[i].count, - (int)recv_convertor->pStack[i].type, recv_convertor->pStack[i].count, - length, pdt->size * count);} + if ((OPAL_DATATYPE_MAX_PREDEFINED <= stack[i].type) + || (OPAL_DATATYPE_MAX_PREDEFINED + <= recv_convertor->pStack[i].type)) { + errors = 1; + printf("recv stack[%d].type wrong (orig %d != new %d) (completed " + "%lu/%lu)\n", + i, (int) stack[i].type, (int) recv_convertor->pStack[i].type, + length, pdt->size * count); + } else if ((stack[i].count + * opal_datatype_basicDatatypes[stack[i].type]->size) + != (recv_convertor->pStack[i].count + * opal_datatype_basicDatatypes[recv_convertor->pStack[i] + .type] + ->size)) { + errors = 1; + printf("recv stack[%d].type*count differs (orig (%d,%lu) != new " + "(%d, %lu)) (completed %lu/%lu)\n", + i, (int) stack[i].type, stack[i].count, + (int) recv_convertor->pStack[i].type, + recv_convertor->pStack[i].count, length, pdt->size * count); + } } } - if( stack[i].disp != recv_convertor->pStack[i].disp ) - {errors = 1; printf("recv stack[%d].disp differs (orig %p != new %p) (completed %lu/%lu)\n", - i, (void*)stack[i].disp, (void*)recv_convertor->pStack[i].disp, - length, pdt->size * count);} - if(0 != errors) {assert(0); exit(-1);} + if (stack[i].disp != recv_convertor->pStack[i].disp) { + errors = 1; + printf( + "recv stack[%d].disp differs (orig %p != new %p) (completed %lu/%lu)\n", + i, (void *) stack[i].disp, (void *) recv_convertor->pStack[i].disp, + length, pdt->size * count); + } + if (0 != errors) { + assert(0); + exit(-1); + } } } } } - GET_TIME( end ); - total_time = ELAPSED_TIME( start, end ); - printf( "copying same data-type using convertors in %ld microsec\n", total_time ); - printf( "\t unpack in %ld microsec [pack in %ld microsec]\n", unpack_time, - total_time - unpack_time ); - - if(outputFlags & VALIDATE_DATA) { - for( size_t i = errors = 0; i < malloced_size; i++ ) { - if( odst[i] != osrc[i] ) { - printf("error at position %lu (%d != %d)\n", - (unsigned long)i, (int)(odst[i]), (int)(osrc[i])); + GET_TIME(end); + total_time = ELAPSED_TIME(start, end); + printf("copying same data-type using convertors in %ld microsec\n", total_time); + printf("\t unpack in %ld microsec [pack in %ld microsec]\n", unpack_time, + total_time - unpack_time); + + if (outputFlags & VALIDATE_DATA) { + for (size_t i = errors = 0; i < malloced_size; i++) { + if (odst[i] != osrc[i]) { + printf("error at position %lu (%d != %d)\n", (unsigned long) i, (int) (odst[i]), + (int) (osrc[i])); errors++; - if(outputFlags & QUIT_ON_FIRST_ERROR) { + if (outputFlags & QUIT_ON_FIRST_ERROR) { opal_datatype_dump(pdt); - assert(0); exit(-1); + assert(0); + exit(-1); } } } - if( 0 == errors ) { + if (0 == errors) { printf("Validation check successfully passed\n"); } else { printf("Found %d errors. Giving up!\n", errors); exit(-1); } } - clean_and_return: - if( NULL != send_convertor ) OBJ_RELEASE( send_convertor ); - if( NULL != recv_convertor ) OBJ_RELEASE( recv_convertor ); - - if( NULL != odst ) free( odst ); - if( NULL != osrc ) free( osrc ); - if( NULL != ptemp ) free( ptemp ); +clean_and_return: + if (NULL != send_convertor) + OBJ_RELEASE(send_convertor); + if (NULL != recv_convertor) + OBJ_RELEASE(recv_convertor); + + if (NULL != odst) + free(odst); + if (NULL != osrc) + free(osrc); + if (NULL != ptemp) + free(ptemp); return (0 == errors ? OPAL_SUCCESS : errors); } @@ -497,226 +565,247 @@ static int local_copy_with_convertor( opal_datatype_t const * const pdt, int cou * on the data-type engine should first pass all the tests from this file, before going into other * tests. */ -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { opal_datatype_t *pdt, *pdt1, *pdt2, *pdt3; int rc, length = 500; - opal_init_util (NULL, NULL); + opal_init_util(NULL, NULL); /** * By default simulate homogeneous architectures. */ remote_arch = opal_local_arch; - printf( "\n\n#\n * TEST CREATE CONTIGUOUS\n#\n\n" ); - pdt = create_contiguous_type( &opal_datatype_int1, 10 ); - if( outputFlags & CHECK_PACK_UNPACK ) { + printf("\n\n#\n * TEST CREATE CONTIGUOUS\n#\n\n"); + pdt = create_contiguous_type(&opal_datatype_int1, 10); + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 100); local_copy_with_convertor(pdt, 100, 956); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST STRANGE DATATYPE\n#\n\n" ); + printf("\n\n#\n * TEST STRANGE DATATYPE\n#\n\n"); pdt = create_strange_dt(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 1); local_copy_with_convertor(pdt, 1, 956); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST UPPER TRIANGULAR MATRIX (size 100)\n#\n\n" ); + printf("\n\n#\n * TEST UPPER TRIANGULAR MATRIX (size 100)\n#\n\n"); pdt = upper_matrix(100); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 1); local_copy_with_convertor(pdt, 1, 48); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST UPPER MATRIX\n#\n\n" ); - rc = test_upper( length ); - if( rc == 0 ) - printf( "decode [PASSED]\n" ); + printf("\n\n#\n * TEST UPPER MATRIX\n#\n\n"); + rc = test_upper(length); + if (rc == 0) + printf("decode [PASSED]\n"); else - printf( "decode [NOT PASSED]\n" ); + printf("decode [NOT PASSED]\n"); - printf( "\n\n#\n * TEST MATRIX BORDERS\n#\n\n" ); - pdt = test_matrix_borders( length, 100 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + printf("\n\n#\n * TEST MATRIX BORDERS\n#\n\n"); + pdt = test_matrix_borders(length, 100); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( "\n\n#\n * TEST CONTIGUOUS\n#\n\n" ); + printf("\n\n#\n * TEST CONTIGUOUS\n#\n\n"); pdt = test_contiguous(); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "\n\n#\n * TEST STRUCT\n#\n\n" ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("\n\n#\n * TEST STRUCT\n#\n\n"); pdt = test_struct(); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + OBJ_RELEASE(pdt); + assert(pdt == NULL); opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt1); opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt2); opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt3); - opal_datatype_add( pdt3, &opal_datatype_int4, 10, 0, -1 ); - opal_datatype_add( pdt3, &opal_datatype_float4, 5, 10 * sizeof(int), -1 ); + opal_datatype_add(pdt3, &opal_datatype_int4, 10, 0, -1); + opal_datatype_add(pdt3, &opal_datatype_float4, 5, 10 * sizeof(int), -1); - opal_datatype_add( pdt2, &opal_datatype_float4, 1, 0, -1 ); - opal_datatype_add( pdt2, pdt3, 3, sizeof(int) * 1, -1 ); + opal_datatype_add(pdt2, &opal_datatype_float4, 1, 0, -1); + opal_datatype_add(pdt2, pdt3, 3, sizeof(int) * 1, -1); - opal_datatype_add( pdt1, &opal_datatype_int8, 5, 0, -1 ); - opal_datatype_add( pdt1, &opal_datatype_float16, 2, sizeof(long long) * 5, -1 ); + opal_datatype_add(pdt1, &opal_datatype_int8, 5, 0, -1); + opal_datatype_add(pdt1, &opal_datatype_float16, 2, sizeof(long long) * 5, -1); - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt1 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt1); } - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt2 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt2); } - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt3 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt3); } - OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL ); - OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL ); - OBJ_RELEASE( pdt3 ); assert( pdt3 == NULL ); + OBJ_RELEASE(pdt1); + assert(pdt1 == NULL); + OBJ_RELEASE(pdt2); + assert(pdt2 == NULL); + OBJ_RELEASE(pdt3); + assert(pdt3 == NULL); - printf( ">>--------------------------------------------<<\n" ); - printf( " Contiguous data-type (opal_datatype_float8)\n" ); - if( outputFlags & CHECK_PACK_UNPACK ) { - opal_datatype_t const * const ddt = &opal_datatype_float8; - local_copy_ddt_count( ddt, 4500); - local_copy_with_convertor( ddt, 4500, 12 ); - local_copy_with_convertor_2datatypes( ddt, 4500, ddt, 4500, 12 ); + printf(">>--------------------------------------------<<\n"); + printf(" Contiguous data-type (opal_datatype_float8)\n"); + if (outputFlags & CHECK_PACK_UNPACK) { + opal_datatype_t const *const ddt = &opal_datatype_float8; + local_copy_ddt_count(ddt, 4500); + local_copy_with_convertor(ddt, 4500, 12); + local_copy_with_convertor_2datatypes(ddt, 4500, ddt, 4500, 12); } - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); - printf( ">>--------------------------------------------<<\n" ); - if( outputFlags & CHECK_PACK_UNPACK ) { - printf( "Contiguous multiple data-type (4500*1)\n" ); - pdt = create_contiguous_type( &opal_datatype_float8, 4500 ); + printf(">>--------------------------------------------<<\n"); + if (outputFlags & CHECK_PACK_UNPACK) { + printf("Contiguous multiple data-type (4500*1)\n"); + pdt = create_contiguous_type(&opal_datatype_float8, 4500); local_copy_ddt_count(pdt, 1); - local_copy_with_convertor( pdt, 1, 12 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (450*10)\n" ); - pdt = create_contiguous_type( &opal_datatype_float8, 450 ); + local_copy_with_convertor(pdt, 1, 12); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (450*10)\n"); + pdt = create_contiguous_type(&opal_datatype_float8, 450); local_copy_ddt_count(pdt, 10); - local_copy_with_convertor( pdt, 10, 12 ); - local_copy_with_convertor_2datatypes( pdt, 10, pdt, 10, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (45*100)\n" ); - pdt = create_contiguous_type( &opal_datatype_float8, 45 ); + local_copy_with_convertor(pdt, 10, 12); + local_copy_with_convertor_2datatypes(pdt, 10, pdt, 10, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (45*100)\n"); + pdt = create_contiguous_type(&opal_datatype_float8, 45); local_copy_ddt_count(pdt, 100); - local_copy_with_convertor( pdt, 100, 12 ); - local_copy_with_convertor_2datatypes( pdt, 100, pdt, 100, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (100*45)\n" ); - pdt = create_contiguous_type( &opal_datatype_float8, 100 ); + local_copy_with_convertor(pdt, 100, 12); + local_copy_with_convertor_2datatypes(pdt, 100, pdt, 100, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (100*45)\n"); + pdt = create_contiguous_type(&opal_datatype_float8, 100); local_copy_ddt_count(pdt, 45); - local_copy_with_convertor( pdt, 45, 12 ); - local_copy_with_convertor_2datatypes( pdt, 45, pdt, 45, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (10*450)\n" ); - pdt = create_contiguous_type( &opal_datatype_float8, 10 ); + local_copy_with_convertor(pdt, 45, 12); + local_copy_with_convertor_2datatypes(pdt, 45, pdt, 45, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (10*450)\n"); + pdt = create_contiguous_type(&opal_datatype_float8, 10); local_copy_ddt_count(pdt, 450); - local_copy_with_convertor( pdt, 450, 12 ); - local_copy_with_convertor_2datatypes( pdt, 450, pdt, 450, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - printf( "Contiguous multiple data-type (1*4500)\n" ); - pdt = create_contiguous_type( &opal_datatype_float8, 1 ); + local_copy_with_convertor(pdt, 450, 12); + local_copy_with_convertor_2datatypes(pdt, 450, pdt, 450, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + printf("Contiguous multiple data-type (1*4500)\n"); + pdt = create_contiguous_type(&opal_datatype_float8, 1); local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 12 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 12 ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - } - printf( ">>--------------------------------------------<<\n" ); - printf( ">>--------------------------------------------<<\n" ); - printf( "Vector data-type (450 times 10 double stride 11)\n" ); - pdt = create_vector_type( &opal_datatype_float8, 450, 10, 11 ); - opal_datatype_dump( pdt ); - if( outputFlags & CHECK_PACK_UNPACK ) { + local_copy_with_convertor(pdt, 4500, 12); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 12); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + } + printf(">>--------------------------------------------<<\n"); + printf(">>--------------------------------------------<<\n"); + printf("Vector data-type (450 times 10 double stride 11)\n"); + pdt = create_vector_type(&opal_datatype_float8, 450, 10, 11); + opal_datatype_dump(pdt); + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 1); - local_copy_with_convertor( pdt, 1, 12 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 12 ); - local_copy_with_convertor( pdt, 1, 82 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 82 ); - local_copy_with_convertor( pdt, 1, 6000 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 6000 ); - local_copy_with_convertor( pdt, 1, 36000 ); - local_copy_with_convertor_2datatypes( pdt, 1, pdt, 1, 36000 ); - } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - - printf( ">>--------------------------------------------<<\n" ); - printf( "Struct data-type resized (double unused followed by 2 used doubles)\n" ); - pdt = create_struct_constant_gap_resized_ddt( &opal_datatype_float8 ); - opal_datatype_dump( pdt ); - if( outputFlags & CHECK_PACK_UNPACK ) { + local_copy_with_convertor(pdt, 1, 12); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 12); + local_copy_with_convertor(pdt, 1, 82); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 82); + local_copy_with_convertor(pdt, 1, 6000); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 6000); + local_copy_with_convertor(pdt, 1, 36000); + local_copy_with_convertor_2datatypes(pdt, 1, pdt, 1, 36000); + } + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + + printf(">>--------------------------------------------<<\n"); + printf("Struct data-type resized (double unused followed by 2 used doubles)\n"); + pdt = create_struct_constant_gap_resized_ddt(&opal_datatype_float8); + opal_datatype_dump(pdt); + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 1); - local_copy_with_convertor( pdt, 100, 11 ); - local_copy_with_convertor_2datatypes( pdt, 100, pdt, 100, 11 ); - local_copy_with_convertor( pdt, 100, 82 ); - local_copy_with_convertor_2datatypes( pdt, 100, pdt, 100, 81 ); - local_copy_with_convertor( pdt, 1500, 6000 ); - local_copy_with_convertor_2datatypes( pdt, 1500, pdt, 1500, 666 ); - local_copy_with_convertor( pdt, 10000, 36000 ); - local_copy_with_convertor_2datatypes( pdt, 10000, pdt, 10000, 1111 ); - } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - - printf( ">>--------------------------------------------<<\n" ); + local_copy_with_convertor(pdt, 100, 11); + local_copy_with_convertor_2datatypes(pdt, 100, pdt, 100, 11); + local_copy_with_convertor(pdt, 100, 82); + local_copy_with_convertor_2datatypes(pdt, 100, pdt, 100, 81); + local_copy_with_convertor(pdt, 1500, 6000); + local_copy_with_convertor_2datatypes(pdt, 1500, pdt, 1500, 666); + local_copy_with_convertor(pdt, 10000, 36000); + local_copy_with_convertor_2datatypes(pdt, 10000, pdt, 10000, 1111); + } + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + + printf(">>--------------------------------------------<<\n"); pdt = test_struct_char_double(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 12 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 12 ); + local_copy_with_convertor(pdt, 4500, 12); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 12); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); pdt = test_create_twice_two_doubles(); - if( outputFlags & CHECK_PACK_UNPACK ) { + if (outputFlags & CHECK_PACK_UNPACK) { local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 12 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 12 ); + local_copy_with_convertor(pdt, 4500, 12); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 12); } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); - printf( ">>--------------------------------------------<<\n" ); + printf(">>--------------------------------------------<<\n"); pdt = test_create_blacs_type(); - if( outputFlags & CHECK_PACK_UNPACK ) { - opal_datatype_dump( pdt ); + if (outputFlags & CHECK_PACK_UNPACK) { + opal_datatype_dump(pdt); local_copy_ddt_count(pdt, 4500); - local_copy_with_convertor( pdt, 4500, 956 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 956 ); - local_copy_with_convertor( pdt, 4500, 16*1024 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 16*1024 ); - local_copy_with_convertor( pdt, 4500, 64*1024 ); - local_copy_with_convertor_2datatypes( pdt, 4500, pdt, 4500, 64*1024 ); - } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt ); assert( pdt == NULL ); - - printf( ">>--------------------------------------------<<\n" ); - pdt1 = test_create_blacs_type1( &opal_datatype_int4 ); - pdt2 = test_create_blacs_type2( &opal_datatype_int4 ); - if( outputFlags & CHECK_PACK_UNPACK ) { - local_copy_with_convertor_2datatypes( pdt1, 1, pdt2, 1, 100 ); - } - printf( ">>--------------------------------------------<<\n" ); - OBJ_RELEASE( pdt1 ); assert( pdt1 == NULL ); - OBJ_RELEASE( pdt2 ); assert( pdt2 == NULL ); + local_copy_with_convertor(pdt, 4500, 956); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 956); + local_copy_with_convertor(pdt, 4500, 16 * 1024); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 16 * 1024); + local_copy_with_convertor(pdt, 4500, 64 * 1024); + local_copy_with_convertor_2datatypes(pdt, 4500, pdt, 4500, 64 * 1024); + } + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt); + assert(pdt == NULL); + + printf(">>--------------------------------------------<<\n"); + pdt1 = test_create_blacs_type1(&opal_datatype_int4); + pdt2 = test_create_blacs_type2(&opal_datatype_int4); + if (outputFlags & CHECK_PACK_UNPACK) { + local_copy_with_convertor_2datatypes(pdt1, 1, pdt2, 1, 100); + } + printf(">>--------------------------------------------<<\n"); + OBJ_RELEASE(pdt1); + assert(pdt1 == NULL); + OBJ_RELEASE(pdt2); + assert(pdt2 == NULL); /* clean-ups all data allocations */ - opal_finalize_util (); + opal_finalize_util(); return OPAL_SUCCESS; } diff --git a/test/datatype/opal_ddt_lib.c b/test/datatype/opal_ddt_lib.c index 605d7deedb..f21690d40f 100644 --- a/test/datatype/opal_ddt_lib.c +++ b/test/datatype/opal_ddt_lib.c @@ -24,49 +24,50 @@ #include "opal/constants.h" #include "opal/datatype/opal_datatype.h" - uint32_t outputFlags = VALIDATE_DATA | CHECK_PACK_UNPACK | RESET_CONVERTORS | QUIT_ON_FIRST_ERROR; -static int32_t opal_datatype_create_indexed( int count, const int* pBlockLength, const int* pDisp, - const opal_datatype_t* oldType, opal_datatype_t** newType ); -static int32_t opal_datatype_create_hindexed( int count, const int* pBlockLength, const ptrdiff_t* pDisp, - const opal_datatype_t* oldType, opal_datatype_t** newType ); -static int32_t opal_datatype_create_struct( int count, const int* pBlockLength, - const ptrdiff_t* pDisp, - opal_datatype_t** pTypes, opal_datatype_t** newType ); -static int32_t opal_datatype_create_vector( int count, int bLength, int stride, - const opal_datatype_t* oldType, opal_datatype_t** newType ); -static int32_t opal_datatype_create_hvector( int count, int bLength, ptrdiff_t stride, - const opal_datatype_t* oldType, opal_datatype_t** newType ); - +static int32_t opal_datatype_create_indexed(int count, const int *pBlockLength, const int *pDisp, + const opal_datatype_t *oldType, + opal_datatype_t **newType); +static int32_t opal_datatype_create_hindexed(int count, const int *pBlockLength, + const ptrdiff_t *pDisp, const opal_datatype_t *oldType, + opal_datatype_t **newType); +static int32_t opal_datatype_create_struct(int count, const int *pBlockLength, + const ptrdiff_t *pDisp, opal_datatype_t **pTypes, + opal_datatype_t **newType); +static int32_t opal_datatype_create_vector(int count, int bLength, int stride, + const opal_datatype_t *oldType, + opal_datatype_t **newType); +static int32_t opal_datatype_create_hvector(int count, int bLength, ptrdiff_t stride, + const opal_datatype_t *oldType, + opal_datatype_t **newType); /** * Cache cleanup. */ -#define CACHE_SIZE (4*1024*1024) -void cache_trash( void ) +#define CACHE_SIZE (4 * 1024 * 1024) +void cache_trash(void) { - char* buffer; + char *buffer; - buffer = (char*)malloc( sizeof(char) * CACHE_SIZE ); - memset( buffer, 1, CACHE_SIZE ); - memset( buffer, 0xff, CACHE_SIZE ); - free( buffer ); + buffer = (char *) malloc(sizeof(char) * CACHE_SIZE); + memset(buffer, 1, CACHE_SIZE); + memset(buffer, 0xff, CACHE_SIZE); + free(buffer); } -opal_datatype_t* test_create_twice_two_doubles( void ) +opal_datatype_t *test_create_twice_two_doubles(void) { - opal_datatype_t* pdt; + opal_datatype_t *pdt; - opal_datatype_create_vector( 2, 2, 5, &opal_datatype_float8, &pdt ); - opal_datatype_commit( pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + opal_datatype_create_vector(2, 2, 5, &opal_datatype_float8, &pdt); + opal_datatype_commit(pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } return pdt; } - /* Datatype 0x832cf28 size 0 align 1 id 0 length 4 used 0 true_lb 0 true_ub 0 (true_extent 0) lb 0 ub 0 (extent 0) @@ -91,70 +92,68 @@ opal_datatype_t* test_create_twice_two_doubles( void ) --C-----D*-[ C ][INT] MPI_INT count 2 disp 0xa24 (2596) extent 4 --C-----D*-[ C ][INT] MPI_INT count 1 disp 0xa80 (2688) extent 4 */ -static int blacs_length[] = { 13, 13, 13, 13, 13, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }; -static int blacs_indices[] = { 1144/4, 1232/4, 1320/4, 1408/4, 1496/4, 1584/4, 1676/4, 1768/4, - 1860/4, 1952/4, 2044/4, 2136/4, 2228/4, 2320/4, 2412/4, 2504/4, - 2596/4, 2688/4 }; -opal_datatype_t* test_create_blacs_type( void ) +static int blacs_length[] = {13, 13, 13, 13, 13, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1}; +static int blacs_indices[] = {1144 / 4, 1232 / 4, 1320 / 4, 1408 / 4, 1496 / 4, 1584 / 4, + 1676 / 4, 1768 / 4, 1860 / 4, 1952 / 4, 2044 / 4, 2136 / 4, + 2228 / 4, 2320 / 4, 2412 / 4, 2504 / 4, 2596 / 4, 2688 / 4}; +opal_datatype_t *test_create_blacs_type(void) { opal_datatype_t *pdt; - opal_datatype_create_indexed( 18, blacs_length, blacs_indices, &opal_datatype_int4, &pdt ); - opal_datatype_commit( pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + opal_datatype_create_indexed(18, blacs_length, blacs_indices, &opal_datatype_int4, &pdt); + opal_datatype_commit(pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } return pdt; } -opal_datatype_t* test_create_blacs_type1( opal_datatype_t const * const base_type ) +opal_datatype_t *test_create_blacs_type1(opal_datatype_t const *const base_type) { opal_datatype_t *pdt; - opal_datatype_create_vector( 7, 1, 3, base_type, &pdt ); - opal_datatype_commit( pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + opal_datatype_create_vector(7, 1, 3, base_type, &pdt); + opal_datatype_commit(pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } return pdt; } -opal_datatype_t* test_create_blacs_type2( opal_datatype_t const * const base_type ) +opal_datatype_t *test_create_blacs_type2(opal_datatype_t const *const base_type) { opal_datatype_t *pdt; - opal_datatype_create_vector( 7, 1, 2, base_type, &pdt ); - opal_datatype_commit( pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + opal_datatype_create_vector(7, 1, 2, base_type, &pdt); + opal_datatype_commit(pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } return pdt; } - -opal_datatype_t* test_struct( void ) +opal_datatype_t *test_struct(void) { - opal_datatype_t* types[] = { (opal_datatype_t*)&opal_datatype_float4, - NULL, - (opal_datatype_t*)&opal_datatype_int1 }; - int lengths[] = { 2, 1, 3 }; - ptrdiff_t disp[] = { 0, 16, 26 }; - opal_datatype_t* pdt, *pdt1; - - printf( "test struct\n" ); + opal_datatype_t *types[] = {(opal_datatype_t *) &opal_datatype_float4, NULL, + (opal_datatype_t *) &opal_datatype_int1}; + int lengths[] = {2, 1, 3}; + ptrdiff_t disp[] = {0, 16, 26}; + opal_datatype_t *pdt, *pdt1; + + printf("test struct\n"); opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt1); - opal_datatype_add( pdt1, &opal_datatype_float8, 1, 0, -1 ); - opal_datatype_add( pdt1, &opal_datatype_int1, 1, 8, -1 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt1 ); + opal_datatype_add(pdt1, &opal_datatype_float8, 1, 0, -1); + opal_datatype_add(pdt1, &opal_datatype_int1, 1, 8, -1); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt1); } types[1] = pdt1; - opal_datatype_create_struct( 3, lengths, disp, types, &pdt ); - OBJ_RELEASE( pdt1 ); /*assert( pdt1 == NULL );*/ - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + opal_datatype_create_struct(3, lengths, disp, types, &pdt); + OBJ_RELEASE(pdt1); /*assert( pdt1 == NULL );*/ + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } return pdt; } @@ -164,22 +163,22 @@ typedef struct __struct_char_double { double d; } char_double_t; -opal_datatype_t* test_struct_char_double( void ) +opal_datatype_t *test_struct_char_double(void) { char_double_t data; int lengths[] = {1, 1}; ptrdiff_t displ[] = {0, 0}; opal_datatype_t *pdt; - opal_datatype_t* types[] = { (opal_datatype_t*)&opal_datatype_int1, - (opal_datatype_t*)&opal_datatype_float8}; + opal_datatype_t *types[] = {(opal_datatype_t *) &opal_datatype_int1, + (opal_datatype_t *) &opal_datatype_float8}; - displ[0] = (char*)&(data.c) - (char*)&(data); - displ[1] = (char*)&(data.d) - (char*)&(data); + displ[0] = (char *) &(data.c) - (char *) &(data); + displ[1] = (char *) &(data.d) - (char *) &(data); - opal_datatype_create_struct( 2, lengths, displ, types, &pdt ); - opal_datatype_commit( pdt ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + opal_datatype_create_struct(2, lengths, displ, types, &pdt); + opal_datatype_commit(pdt); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } return pdt; } @@ -199,57 +198,56 @@ typedef struct { #define SSTRANGE_CNT 10 #define USE_RESIZED -opal_datatype_t* create_strange_dt( void ) +opal_datatype_t *create_strange_dt(void) { sdata_intern v[2]; ptrdiff_t displ[3]; opal_datatype_t *pdt, *pdt1; opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt1); - opal_datatype_add( pdt1, &opal_datatype_float8, 1, 0, -1 ); - opal_datatype_add( pdt1, &opal_datatype_int1, 1, 8, -1 ); + opal_datatype_add(pdt1, &opal_datatype_float8, 1, 0, -1); + opal_datatype_add(pdt1, &opal_datatype_int1, 1, 8, -1); #ifdef USE_RESIZED /* optional */ displ[0] = 0; - displ[1] = (char*)&(v[1]) - (char*)&(v[0]); - opal_datatype_resize( pdt1, displ[0], displ[1]); -#endif /* USE_RESIZED */ + displ[1] = (char *) &(v[1]) - (char *) &(v[0]); + opal_datatype_resize(pdt1, displ[0], displ[1]); +#endif /* USE_RESIZED */ - opal_datatype_create_contiguous( SSTRANGE_CNT, pdt1, &pdt ); + opal_datatype_create_contiguous(SSTRANGE_CNT, pdt1, &pdt); - OBJ_RELEASE( pdt1 ); - printf( "\nStrange datatype BEFORE COMMIT\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + OBJ_RELEASE(pdt1); + printf("\nStrange datatype BEFORE COMMIT\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } - opal_datatype_commit( pdt ); - printf( "\nStrange datatype AFTER COMMIT\n" ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + opal_datatype_commit(pdt); + printf("\nStrange datatype AFTER COMMIT\n"); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } return pdt; } -opal_datatype_t* create_vector_type( const opal_datatype_t* data, int count, int length, int stride ) +opal_datatype_t *create_vector_type(const opal_datatype_t *data, int count, int length, int stride) { - opal_datatype_t* vector; + opal_datatype_t *vector; - opal_datatype_create_vector( count, length, stride, data, &vector ); - opal_datatype_commit( vector ); + opal_datatype_create_vector(count, length, stride, data, &vector); + opal_datatype_commit(vector); return vector; } - -opal_datatype_t* create_contiguous_type( const opal_datatype_t* type, int length ) +opal_datatype_t *create_contiguous_type(const opal_datatype_t *type, int length) { - opal_datatype_t* newtype; + opal_datatype_t *newtype; - opal_datatype_create_contiguous( length, type, &newtype ); - opal_datatype_commit( newtype ); + opal_datatype_create_contiguous(length, type, &newtype); + opal_datatype_commit(newtype); - return newtype; + return newtype; } /* Create a non-contiguous resized datatype */ @@ -259,13 +257,13 @@ struct structure { double transfered_2; }; -opal_datatype_t* create_struct_constant_gap_resized_ddt( const opal_datatype_t* type ) +opal_datatype_t *create_struct_constant_gap_resized_ddt(const opal_datatype_t *type) { opal_datatype_t *struct_type; opal_datatype_create_contiguous(0, &opal_datatype_empty, &struct_type); - opal_datatype_add( struct_type, &opal_datatype_float8, 1, 8, -1 ); - opal_datatype_add( struct_type, &opal_datatype_float8, 1, 16, -1 ); + opal_datatype_add(struct_type, &opal_datatype_float8, 1, 8, -1); + opal_datatype_add(struct_type, &opal_datatype_float8, 1, 16, -1); opal_datatype_resize(struct_type, 0, sizeof(struct structure)); opal_datatype_commit(struct_type); @@ -273,126 +271,128 @@ opal_datatype_t* create_struct_constant_gap_resized_ddt( const opal_datatype_t* return struct_type; } - /*****************************************************************************/ /* Copied Function to get test to work */ /*****************************************************************************/ -static int32_t opal_datatype_create_indexed( int count, const int* pBlockLength, const int* pDisp, - const opal_datatype_t* oldType, opal_datatype_t** newType ) +static int32_t opal_datatype_create_indexed(int count, const int *pBlockLength, const int *pDisp, + const opal_datatype_t *oldType, + opal_datatype_t **newType) { - opal_datatype_t* pdt; + opal_datatype_t *pdt; int i, dLength, endat, disp; ptrdiff_t extent; - if( 0 == count ) { - *newType = opal_datatype_create( 0 ); - opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0); + if (0 == count) { + *newType = opal_datatype_create(0); + opal_datatype_add(*newType, &opal_datatype_empty, 0, 0, 0); return OPAL_SUCCESS; } disp = pDisp[0]; dLength = pBlockLength[0]; endat = disp + dLength; - opal_datatype_type_extent( oldType, &extent ); - if( 1 >= count ) { - pdt = opal_datatype_create( oldType->desc.used + 2 ); + opal_datatype_type_extent(oldType, &extent); + if (1 >= count) { + pdt = opal_datatype_create(oldType->desc.used + 2); /* multiply by count to make it zero if count is zero */ - opal_datatype_add( pdt, oldType, count * dLength, disp * extent, extent ); + opal_datatype_add(pdt, oldType, count * dLength, disp * extent, extent); } else { - pdt = opal_datatype_create( count * (2 + oldType->desc.used) ); - for( i = 1; i < count; i++ ) { - if( endat == pDisp[i] ) { + pdt = opal_datatype_create(count * (2 + oldType->desc.used)); + for (i = 1; i < count; i++) { + if (endat == pDisp[i]) { /* contiguous with the previsious */ dLength += pBlockLength[i]; endat += pBlockLength[i]; } else { - opal_datatype_add( pdt, oldType, dLength, disp * extent, extent ); + opal_datatype_add(pdt, oldType, dLength, disp * extent, extent); disp = pDisp[i]; dLength = pBlockLength[i]; endat = disp + pBlockLength[i]; } } - opal_datatype_add( pdt, oldType, dLength, disp * extent, extent ); + opal_datatype_add(pdt, oldType, dLength, disp * extent, extent); } *newType = pdt; return OPAL_SUCCESS; } -static int32_t opal_datatype_create_hindexed( int count, const int* pBlockLength, const ptrdiff_t* pDisp, - const opal_datatype_t* oldType, opal_datatype_t** newType ) +static int32_t opal_datatype_create_hindexed(int count, const int *pBlockLength, + const ptrdiff_t *pDisp, const opal_datatype_t *oldType, + opal_datatype_t **newType) { - opal_datatype_t* pdt; + opal_datatype_t *pdt; int i, dLength; ptrdiff_t extent, disp, endat; - if( 0 == count ) { - *newType = opal_datatype_create( 0 ); - opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0); + if (0 == count) { + *newType = opal_datatype_create(0); + opal_datatype_add(*newType, &opal_datatype_empty, 0, 0, 0); return OPAL_SUCCESS; } - opal_datatype_type_extent( oldType, &extent ); + opal_datatype_type_extent(oldType, &extent); - pdt = opal_datatype_create( count * (2 + oldType->desc.used) ); + pdt = opal_datatype_create(count * (2 + oldType->desc.used)); disp = pDisp[0]; dLength = pBlockLength[0]; endat = disp + dLength * extent; - if( 1 >= count ) { - pdt = opal_datatype_create( oldType->desc.used + 2 ); + if (1 >= count) { + pdt = opal_datatype_create(oldType->desc.used + 2); /* multiply by count to make it zero if count is zero */ - opal_datatype_add( pdt, oldType, count * dLength, disp, extent ); + opal_datatype_add(pdt, oldType, count * dLength, disp, extent); } else { - for( i = 1; i < count; i++ ) { - if( endat == pDisp[i] ) { + for (i = 1; i < count; i++) { + if (endat == pDisp[i]) { /* contiguous with the previsious */ dLength += pBlockLength[i]; endat += pBlockLength[i] * extent; } else { - opal_datatype_add( pdt, oldType, dLength, disp, extent ); + opal_datatype_add(pdt, oldType, dLength, disp, extent); disp = pDisp[i]; dLength = pBlockLength[i]; endat = disp + pBlockLength[i] * extent; } } - opal_datatype_add( pdt, oldType, dLength, disp, extent ); + opal_datatype_add(pdt, oldType, dLength, disp, extent); } *newType = pdt; return OPAL_SUCCESS; } - -static int32_t opal_datatype_create_struct( int count, const int* pBlockLength, const ptrdiff_t* pDisp, - opal_datatype_t** pTypes, opal_datatype_t** newType ) +static int32_t opal_datatype_create_struct(int count, const int *pBlockLength, + const ptrdiff_t *pDisp, opal_datatype_t **pTypes, + opal_datatype_t **newType) { int i; ptrdiff_t disp = 0, endto, lastExtent, lastDisp; int lastBlock; opal_datatype_t *pdt, *lastType; - if( 0 == count ) { - *newType = opal_datatype_create( 0 ); - opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0); + if (0 == count) { + *newType = opal_datatype_create(0); + opal_datatype_add(*newType, &opal_datatype_empty, 0, 0, 0); return OPAL_SUCCESS; } /* if we compute the total number of elements before we can * avoid increasing the size of the desc array often. */ - lastType = (opal_datatype_t*)pTypes[0]; + lastType = (opal_datatype_t *) pTypes[0]; lastBlock = pBlockLength[0]; lastExtent = lastType->ub - lastType->lb; lastDisp = pDisp[0]; endto = pDisp[0] + lastExtent * lastBlock; - for( i = 1; i < count; i++ ) { - if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) { + for (i = 1; i < count; i++) { + if ((pTypes[i] == lastType) && (pDisp[i] == endto)) { lastBlock += pBlockLength[i]; endto = lastDisp + lastBlock * lastExtent; } else { disp += lastType->desc.used; - if( lastBlock > 1 ) disp += 2; - lastType = (opal_datatype_t*)pTypes[i]; + if (lastBlock > 1) + disp += 2; + lastType = (opal_datatype_t *) pTypes[i]; lastExtent = lastType->ub - lastType->lb; lastBlock = pBlockLength[i]; lastDisp = pDisp[i]; @@ -400,94 +400,94 @@ static int32_t opal_datatype_create_struct( int count, const int* pBlockLength, } } disp += lastType->desc.used; - if( lastBlock != 1 ) disp += 2; + if (lastBlock != 1) + disp += 2; - lastType = (opal_datatype_t*)pTypes[0]; + lastType = (opal_datatype_t *) pTypes[0]; lastBlock = pBlockLength[0]; lastExtent = lastType->ub - lastType->lb; lastDisp = pDisp[0]; endto = pDisp[0] + lastExtent * lastBlock; - pdt = opal_datatype_create( (int32_t)disp ); + pdt = opal_datatype_create((int32_t) disp); /* Do again the same loop but now add the elements */ - for( i = 1; i < count; i++ ) { - if( (pTypes[i] == lastType) && (pDisp[i] == endto) ) { + for (i = 1; i < count; i++) { + if ((pTypes[i] == lastType) && (pDisp[i] == endto)) { lastBlock += pBlockLength[i]; endto = lastDisp + lastBlock * lastExtent; } else { - opal_datatype_add( pdt, lastType, lastBlock, lastDisp, lastExtent ); - lastType = (opal_datatype_t*)pTypes[i]; + opal_datatype_add(pdt, lastType, lastBlock, lastDisp, lastExtent); + lastType = (opal_datatype_t *) pTypes[i]; lastExtent = lastType->ub - lastType->lb; lastBlock = pBlockLength[i]; lastDisp = pDisp[i]; endto = lastDisp + lastExtent * lastBlock; } } - opal_datatype_add( pdt, lastType, lastBlock, lastDisp, lastExtent ); + opal_datatype_add(pdt, lastType, lastBlock, lastDisp, lastExtent); - *newType = pdt; + *newType = pdt; return OPAL_SUCCESS; } - -static int32_t opal_datatype_create_vector( int count, int bLength, int stride, - const opal_datatype_t* oldType, opal_datatype_t** newType ) +static int32_t opal_datatype_create_vector(int count, int bLength, int stride, + const opal_datatype_t *oldType, + opal_datatype_t **newType) { opal_datatype_t *pTempData, *pData; ptrdiff_t extent = oldType->ub - oldType->lb; - - if( 0 == count ) { - *newType = opal_datatype_create( 0 ); - opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0); + if (0 == count) { + *newType = opal_datatype_create(0); + opal_datatype_add(*newType, &opal_datatype_empty, 0, 0, 0); return OPAL_SUCCESS; } - pData = opal_datatype_create( oldType->desc.used + 2 ); - if( (bLength == stride) || (1 == count) ) { /* the elements are contiguous */ - opal_datatype_add( pData, oldType, count * bLength, 0, extent ); + pData = opal_datatype_create(oldType->desc.used + 2); + if ((bLength == stride) || (1 == count)) { /* the elements are contiguous */ + opal_datatype_add(pData, oldType, count * bLength, 0, extent); } else { - if( 1 == bLength ) { - opal_datatype_add( pData, oldType, count, 0, extent * stride ); + if (1 == bLength) { + opal_datatype_add(pData, oldType, count, 0, extent * stride); } else { - opal_datatype_add( pData, oldType, bLength, 0, extent ); + opal_datatype_add(pData, oldType, bLength, 0, extent); pTempData = pData; - pData = opal_datatype_create( oldType->desc.used + 2 + 2 ); - opal_datatype_add( pData, pTempData, count, 0, extent * stride ); - OBJ_RELEASE( pTempData ); + pData = opal_datatype_create(oldType->desc.used + 2 + 2); + opal_datatype_add(pData, pTempData, count, 0, extent * stride); + OBJ_RELEASE(pTempData); } } *newType = pData; return OPAL_SUCCESS; } - -static int32_t opal_datatype_create_hvector( int count, int bLength, ptrdiff_t stride, - const opal_datatype_t* oldType, opal_datatype_t** newType ) +static int32_t opal_datatype_create_hvector(int count, int bLength, ptrdiff_t stride, + const opal_datatype_t *oldType, + opal_datatype_t **newType) { opal_datatype_t *pTempData, *pData; ptrdiff_t extent = oldType->ub - oldType->lb; - if( 0 == count ) { - *newType = opal_datatype_create( 0 ); - opal_datatype_add( *newType, &opal_datatype_empty, 0, 0, 0); + if (0 == count) { + *newType = opal_datatype_create(0); + opal_datatype_add(*newType, &opal_datatype_empty, 0, 0, 0); return OPAL_SUCCESS; } - pTempData = opal_datatype_create( oldType->desc.used + 2 ); - if( ((extent * bLength) == stride) || (1 == count) ) { /* contiguous */ + pTempData = opal_datatype_create(oldType->desc.used + 2); + if (((extent * bLength) == stride) || (1 == count)) { /* contiguous */ pData = pTempData; - opal_datatype_add( pData, oldType, count * bLength, 0, extent ); + opal_datatype_add(pData, oldType, count * bLength, 0, extent); } else { - if( 1 == bLength ) { + if (1 == bLength) { pData = pTempData; - opal_datatype_add( pData, oldType, count, 0, stride ); + opal_datatype_add(pData, oldType, count, 0, stride); } else { - opal_datatype_add( pTempData, oldType, bLength, 0, extent ); - pData = opal_datatype_create( oldType->desc.used + 2 + 2 ); - opal_datatype_add( pData, pTempData, count, 0, stride ); - OBJ_RELEASE( pTempData ); + opal_datatype_add(pTempData, oldType, bLength, 0, extent); + pData = opal_datatype_create(oldType->desc.used + 2 + 2); + opal_datatype_add(pData, pTempData, count, 0, stride); + OBJ_RELEASE(pTempData); } } *newType = pData; @@ -495,143 +495,132 @@ static int32_t opal_datatype_create_hvector( int count, int bLength, ptrdiff_t s } /*****************************************************************************/ -int init_random_upper_matrix( unsigned int N, double* mat ) +int init_random_upper_matrix(unsigned int N, double *mat) { unsigned int i, j; - srand( time(NULL) ); - for( i = 0; i < N; i++ ) { + srand(time(NULL)); + for (i = 0; i < N; i++) { mat += i; - for( j = i; j < N; j++ ) { - *mat = (double)random(); + for (j = i; j < N; j++) { + *mat = (double) random(); mat++; } } return OPAL_SUCCESS; } -int check_diag_matrix( unsigned int N, double* mat1, double* mat2 ) +int check_diag_matrix(unsigned int N, double *mat1, double *mat2) { - unsigned int i, j; - - for( i = 0; i < N; i++ ) { - mat1 += i; - mat2 += i; - for( j = i; j < N; j++ ) { - if( *mat1 != *mat2 ) { - printf( "error in position (%d, %d) expect %f and find %f\n", - i, j, *mat1, *mat2 ); - printf( "hex %lx != %lx\n", *(long*)mat1, *(long*)mat2 ); - return OPAL_ERROR; - } - mat1++; mat2++; - } - } - return OPAL_SUCCESS; -} + unsigned int i, j; + for (i = 0; i < N; i++) { + mat1 += i; + mat2 += i; + for (j = i; j < N; j++) { + if (*mat1 != *mat2) { + printf("error in position (%d, %d) expect %f and find %f\n", i, j, *mat1, *mat2); + printf("hex %lx != %lx\n", *(long *) mat1, *(long *) mat2); + return OPAL_ERROR; + } + mat1++; + mat2++; + } + } + return OPAL_SUCCESS; +} -opal_datatype_t* upper_matrix( unsigned int mat_size ) +opal_datatype_t *upper_matrix(unsigned int mat_size) { int *disp, *blocklen; unsigned int i; - opal_datatype_t* upper; + opal_datatype_t *upper; - disp = (int*)malloc( sizeof(int) * mat_size ); - blocklen = (int*)malloc( sizeof(int) * mat_size ); + disp = (int *) malloc(sizeof(int) * mat_size); + blocklen = (int *) malloc(sizeof(int) * mat_size); - for( i = 0; i < mat_size; i++ ) { + for (i = 0; i < mat_size; i++) { disp[i] = i * mat_size + i; blocklen[i] = mat_size - i; } #if SIZEOF_DOUBLE == 4 - opal_datatype_create_indexed( mat_size, blocklen, disp, - &opal_datatype_float4, - &upper ); + opal_datatype_create_indexed(mat_size, blocklen, disp, &opal_datatype_float4, &upper); #else - opal_datatype_create_indexed( mat_size, blocklen, disp, - &opal_datatype_float8, - &upper ); + opal_datatype_create_indexed(mat_size, blocklen, disp, &opal_datatype_float8, &upper); #endif - opal_datatype_commit( upper ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( upper ); + opal_datatype_commit(upper); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(upper); } - free( disp ); - free( blocklen ); + free(disp); + free(blocklen); return upper; } -opal_datatype_t* lower_matrix( unsigned int mat_size ) +opal_datatype_t *lower_matrix(unsigned int mat_size) { int *disp, *blocklen; unsigned int i; - opal_datatype_t* upper; + opal_datatype_t *upper; - disp = (int*)malloc( sizeof(int) * mat_size ); - blocklen = (int*)malloc( sizeof(int) * mat_size ); + disp = (int *) malloc(sizeof(int) * mat_size); + blocklen = (int *) malloc(sizeof(int) * mat_size); - for( i = 0; i < mat_size; i++ ) { + for (i = 0; i < mat_size; i++) { disp[i] = i * mat_size; blocklen[i] = i; } #if SIZEOF_DOUBLE == 4 - opal_datatype_create_indexed( mat_size, blocklen, disp, &opal_datatype_float4, - &upper ); + opal_datatype_create_indexed(mat_size, blocklen, disp, &opal_datatype_float4, &upper); #else - opal_datatype_create_indexed( mat_size, blocklen, disp, &opal_datatype_float8, - &upper ); + opal_datatype_create_indexed(mat_size, blocklen, disp, &opal_datatype_float8, &upper); #endif - free( disp ); - free( blocklen ); + free(disp); + free(blocklen); return upper; } -opal_datatype_t* test_matrix_borders( unsigned int size, unsigned int width ) +opal_datatype_t *test_matrix_borders(unsigned int size, unsigned int width) { - opal_datatype_t *pdt, *pdt_line; - int disp[2]; - int blocklen[2]; - - disp[0] = 0; - blocklen[0] = width; - disp[1] = (size - width) * sizeof(double); - blocklen[1] = width; - - opal_datatype_create_indexed( 2, blocklen, disp, &opal_datatype_float8, - &pdt_line ); - opal_datatype_create_contiguous( size, pdt_line, &pdt ); - OBJ_RELEASE( pdt_line ); /*assert( pdt_line == NULL );*/ - return pdt; + opal_datatype_t *pdt, *pdt_line; + int disp[2]; + int blocklen[2]; + + disp[0] = 0; + blocklen[0] = width; + disp[1] = (size - width) * sizeof(double); + blocklen[1] = width; + + opal_datatype_create_indexed(2, blocklen, disp, &opal_datatype_float8, &pdt_line); + opal_datatype_create_contiguous(size, pdt_line, &pdt); + OBJ_RELEASE(pdt_line); /*assert( pdt_line == NULL );*/ + return pdt; } - -opal_datatype_t* test_contiguous( void ) +opal_datatype_t *test_contiguous(void) { opal_datatype_t *pdt, *pdt1, *pdt2; - printf( "test contiguous (alignment)\n" ); + printf("test contiguous (alignment)\n"); opal_datatype_create_contiguous(0, &opal_datatype_empty, &pdt1); - opal_datatype_add( pdt1, &opal_datatype_float8, 1, 0, -1 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt1 ); + opal_datatype_add(pdt1, &opal_datatype_float8, 1, 0, -1); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt1); } - opal_datatype_add( pdt1, &opal_datatype_int1, 1, 8, -1 ); - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt1 ); + opal_datatype_add(pdt1, &opal_datatype_int1, 1, 8, -1); + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt1); } - opal_datatype_create_contiguous( 4, pdt1, &pdt2 ); - OBJ_RELEASE( pdt1 ); /*assert( pdt1 == NULL );*/ - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt2 ); + opal_datatype_create_contiguous(4, pdt1, &pdt2); + OBJ_RELEASE(pdt1); /*assert( pdt1 == NULL );*/ + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt2); } - opal_datatype_create_contiguous( 2, pdt2, &pdt ); - OBJ_RELEASE( pdt2 ); /*assert( pdt2 == NULL );*/ - if( outputFlags & DUMP_DATA_AFTER_COMMIT ) { - opal_datatype_dump( pdt ); + opal_datatype_create_contiguous(2, pdt2, &pdt); + OBJ_RELEASE(pdt2); /*assert( pdt2 == NULL );*/ + if (outputFlags & DUMP_DATA_AFTER_COMMIT) { + opal_datatype_dump(pdt); } return pdt; } - - diff --git a/test/datatype/opal_ddt_lib.h b/test/datatype/opal_ddt_lib.h index ca7e84ab5b..f32437825a 100644 --- a/test/datatype/opal_ddt_lib.h +++ b/test/datatype/opal_ddt_lib.h @@ -18,10 +18,10 @@ #include "opal/datatype/opal_datatype.h" - #define TIMER_DATA_TYPE struct timeval -#define GET_TIME(TV) gettimeofday( &(TV), NULL ) -#define ELAPSED_TIME(TSTART, TEND) (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) +#define GET_TIME(TV) gettimeofday(&(TV), NULL) +#define ELAPSED_TIME(TSTART, TEND) \ + (((TEND).tv_sec - (TSTART).tv_sec) * 1000000 + ((TEND).tv_usec - (TSTART).tv_usec)) #define DUMP_DATA_AFTER_COMMIT 0x00000001 #define CHECK_PACK_UNPACK 0x00000002 @@ -31,23 +31,24 @@ extern uint32_t outputFlags; -extern void cache_trash( void ); -extern opal_datatype_t* create_contiguous_type( opal_datatype_t const * const type, int length ); -extern opal_datatype_t* create_vector_type( opal_datatype_t const* const data, int count, int length, int stride ); -extern opal_datatype_t* create_strange_dt( void ); -extern opal_datatype_t* upper_matrix( unsigned int mat_size ); -extern opal_datatype_t* lower_matrix( unsigned int mat_size ); -extern opal_datatype_t* test_matrix_borders( unsigned int size, unsigned int width ); -extern int init_random_upper_matrix( unsigned int N, double* mat ); -extern int check_diag_matrix( unsigned int N, double* mat1, double* mat2 ); -extern opal_datatype_t* test_contiguous( void ); -extern opal_datatype_t* test_struct_char_double( void ); -extern opal_datatype_t* test_create_twice_two_doubles( void ); -extern opal_datatype_t* test_struct( void ); -extern opal_datatype_t* test_create_blacs_type( void ); -extern opal_datatype_t* test_create_blacs_type1( opal_datatype_t const * const base_type ); -extern opal_datatype_t* test_create_blacs_type2( opal_datatype_t const * const base_type ); - -extern opal_datatype_t* create_struct_constant_gap_resized_ddt( const opal_datatype_t* type ); +extern void cache_trash(void); +extern opal_datatype_t *create_contiguous_type(opal_datatype_t const *const type, int length); +extern opal_datatype_t *create_vector_type(opal_datatype_t const *const data, int count, int length, + int stride); +extern opal_datatype_t *create_strange_dt(void); +extern opal_datatype_t *upper_matrix(unsigned int mat_size); +extern opal_datatype_t *lower_matrix(unsigned int mat_size); +extern opal_datatype_t *test_matrix_borders(unsigned int size, unsigned int width); +extern int init_random_upper_matrix(unsigned int N, double *mat); +extern int check_diag_matrix(unsigned int N, double *mat1, double *mat2); +extern opal_datatype_t *test_contiguous(void); +extern opal_datatype_t *test_struct_char_double(void); +extern opal_datatype_t *test_create_twice_two_doubles(void); +extern opal_datatype_t *test_struct(void); +extern opal_datatype_t *test_create_blacs_type(void); +extern opal_datatype_t *test_create_blacs_type1(opal_datatype_t const *const base_type); +extern opal_datatype_t *test_create_blacs_type2(opal_datatype_t const *const base_type); + +extern opal_datatype_t *create_struct_constant_gap_resized_ddt(const opal_datatype_t *type); #endif /* TEST_OPAL_DDT_LIB_H */ diff --git a/test/datatype/partial.c b/test/datatype/partial.c index c064db7193..bfb1c5d59d 100644 --- a/test/datatype/partial.c +++ b/test/datatype/partial.c @@ -13,8 +13,8 @@ */ #include "ompi_config.h" -#include "opal/datatype/opal_convertor.h" #include "ompi/datatype/ompi_datatype.h" +#include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype_checksum.h" #include "opal/runtime/opal.h" @@ -22,41 +22,44 @@ #include <stdlib.h> #include <time.h> -#define TYPE_COUNT 3 -#define TYPE_BLEN 2 -#define TYPE_STRIDE 4 +#define TYPE_COUNT 3 +#define TYPE_BLEN 2 +#define TYPE_STRIDE 4 -#define CONT_COUNT 2 +#define CONT_COUNT 2 -#define COUNT 3 +#define COUNT 3 -#define CHUNK ((TYPE_BLEN*8)*2-4) +#define CHUNK ((TYPE_BLEN * 8) * 2 - 4) /** * Print how many elements on both sides of ptr. */ -static void show_neighborhood(double* ptr, int how_many, bool show_hex) +static void show_neighborhood(double *ptr, int how_many, bool show_hex) { int i; - printf("%12p: ", (void*)ptr); - for( i = -how_many; i < how_many; i++ ) { - if( 0 == i ) { + printf("%12p: ", (void *) ptr); + for (i = -how_many; i < how_many; i++) { + if (0 == i) { printf(" <%g> ", ptr[i]); } else { printf(" %g ", ptr[i]); } } - if( show_hex ) { - char* cptr = (char*)ptr; + if (show_hex) { + char *cptr = (char *) ptr; printf("\n : "); - for( i = -how_many; i < how_many; i++ ) { - if( 0 == i ) printf(" <"); - for( int j = 0; j < sizeof(double); j++ ) { - printf("%02x", cptr[i * sizeof(double)+j]); + for (i = -how_many; i < how_many; i++) { + if (0 == i) + printf(" <"); + for (int j = 0; j < sizeof(double); j++) { + printf("%02x", cptr[i * sizeof(double) + j]); } - if( 0 == i ) printf("> "); - else printf(" "); + if (0 == i) + printf("> "); + else + printf(" "); } } printf("\n\n"); @@ -65,30 +68,32 @@ static void show_neighborhood(double* ptr, int how_many, bool show_hex) /** * -------G---[---][---] OPAL_LOOP_S 19 times the next 2 elements extent 18432 * -cC---P-DB-[---][---] OPAL_FLOAT8 count 72 disp 0x80 (128) blen 16 extent 256 (size 9216) - * -------G---[---][---] OPAL_LOOP_E prev 2 elements first elem displacement 128 size of data 9216 - * -------G---[---][---] OPAL_LOOP_E prev 3 elements first elem displacement 128 size of data 175104 + * -------G---[---][---] OPAL_LOOP_E prev 2 elements first elem displacement 128 size of data + * 9216 + * -------G---[---][---] OPAL_LOOP_E prev 3 elements first elem displacement 128 size of data + * 175104 */ -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { - opal_datatype_t* vector; - ompi_datatype_t* base; + opal_datatype_t *vector; + ompi_datatype_t *base; uint32_t iov_count; size_t max_data, size, length; struct iovec iov[2]; - opal_convertor_t* convertor; + opal_convertor_t *convertor; ptrdiff_t extent, base_extent; double *array, *packed; - char* bpacked; + char *bpacked; int i, j; - opal_init_util (NULL, NULL); + opal_init_util(NULL, NULL); ompi_datatype_init(); ompi_datatype_create_vector(TYPE_COUNT, TYPE_BLEN, TYPE_STRIDE, MPI_DOUBLE, &base); ompi_datatype_create_contiguous(CONT_COUNT, base, &vector); - opal_datatype_commit( vector ); + opal_datatype_commit(vector); ompi_datatype_dump(vector); @@ -96,15 +101,15 @@ int main( int argc, char* argv[] ) opal_datatype_type_extent(vector, &extent); opal_datatype_type_extent(base, &base_extent); - array = (double*)malloc( extent * COUNT ); - packed = (double*)malloc( size * COUNT ); - bpacked = (char*)packed; + array = (double *) malloc(extent * COUNT); + packed = (double *) malloc(size * COUNT); + bpacked = (char *) packed; /** * Initialize the sparse data using the index. */ - for( i = 0; i < (TYPE_BLEN * TYPE_COUNT * CONT_COUNT * COUNT); i++ ) { - packed[i] = (double)(i % TYPE_BLEN); + for (i = 0; i < (TYPE_BLEN * TYPE_COUNT * CONT_COUNT * COUNT); i++) { + packed[i] = (double) (i % TYPE_BLEN); } memset(array, extent * COUNT, TYPE_BLEN + 1); @@ -112,34 +117,38 @@ int main( int argc, char* argv[] ) * Pack the sparse data into the packed array. This simulate the first step * of the buffered operation. */ - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_prepare_for_recv( convertor, vector, COUNT, array ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_prepare_for_recv(convertor, vector, COUNT, array); - for( length = 0; length < (size * COUNT); ) { + for (length = 0; length < (size * COUNT);) { iov[0].iov_base = bpacked + length; iov[0].iov_len = CHUNK; max_data = iov[0].iov_len; iov_count = 1; - opal_convertor_unpack( convertor, iov, &iov_count, &max_data ); + opal_convertor_unpack(convertor, iov, &iov_count, &max_data); length += max_data; int idx = 0, checked = 0; - for( int m = 0; m < COUNT; m++ ) { - char* mptr = (char*)array + m * extent; - for( int k = 0; k < CONT_COUNT; k++ ) { - char* kptr = mptr + k * base_extent; - for( j = 0; j < TYPE_COUNT; j++ ) { - double* jarray = (double*)kptr + j * TYPE_STRIDE; - for( i = 0; i < TYPE_BLEN; i++ ) { + for (int m = 0; m < COUNT; m++) { + char *mptr = (char *) array + m * extent; + for (int k = 0; k < CONT_COUNT; k++) { + char *kptr = mptr + k * base_extent; + for (j = 0; j < TYPE_COUNT; j++) { + double *jarray = (double *) kptr + j * TYPE_STRIDE; + for (i = 0; i < TYPE_BLEN; i++) { checked += sizeof(double); - if( checked > length ) + if (checked > length) goto next_iteration; - if( jarray[i] != (double)(idx % TYPE_BLEN) ) { - fprintf(stderr, "\n\n\nError during check for the %d element, length %" PRIsize_t " (chunk %d)\n", - idx, length, CHUNK); - fprintf(stderr, "Error at position %d [%d:%d:%d:%d] found %g expected %g\n\n\n", - idx, m, k, j, i, jarray[i], (double)(idx % TYPE_BLEN)); + if (jarray[i] != (double) (idx % TYPE_BLEN)) { + fprintf( + stderr, + "\n\n\nError during check for the %d element, length %" PRIsize_t + " (chunk %d)\n", + idx, length, CHUNK); + fprintf(stderr, + "Error at position %d [%d:%d:%d:%d] found %g expected %g\n\n\n", + idx, m, k, j, i, jarray[i], (double) (idx % TYPE_BLEN)); show_neighborhood(jarray + i, 4, true); exit(-1); } @@ -148,7 +157,7 @@ int main( int argc, char* argv[] ) } } } -next_iteration: + next_iteration: /* nothing special to do here, just move to the next conversion */ continue; } @@ -165,7 +174,7 @@ next_iteration: /* clean-ups all data allocations */ ompi_datatype_finalize(); - opal_finalize_util (); + opal_finalize_util(); return 0; } diff --git a/test/datatype/position.c b/test/datatype/position.c index c92adebcba..d4ec8ccab5 100644 --- a/test/datatype/position.c +++ b/test/datatype/position.c @@ -18,10 +18,10 @@ #include <stdio.h> #include <string.h> -#include "opal/datatype/opal_convertor.h" #include "ompi/datatype/ompi_datatype.h" -#include "opal/util/output.h" +#include "opal/datatype/opal_convertor.h" #include "opal/runtime/opal.h" +#include "opal/util/output.h" /** * The purpose of this test is to simulate the multi-network packing and @@ -36,63 +36,60 @@ static int data_count = 2048; typedef struct { size_t position; size_t size; - void* buffer; + void *buffer; } ddt_segment_t; -static int -create_segments( ompi_datatype_t* datatype, int count, - size_t segment_length, - ddt_segment_t** segments, int* seg_count ) +static int create_segments(ompi_datatype_t *datatype, int count, size_t segment_length, + ddt_segment_t **segments, int *seg_count) { size_t data_size, total_length, position; - opal_convertor_t* convertor; + opal_convertor_t *convertor; int i; - ddt_segment_t* segment; + ddt_segment_t *segment; - ompi_datatype_type_size( datatype, &data_size ); + ompi_datatype_type_size(datatype, &data_size); data_size *= count; *seg_count = data_size / segment_length; - if( ((*seg_count) * segment_length) != data_size ) + if (((*seg_count) * segment_length) != data_size) *seg_count += 1; - allocate_segments: - *segments = (ddt_segment_t*)malloc( (*seg_count) * sizeof(ddt_segment_t) ); +allocate_segments: + *segments = (ddt_segment_t *) malloc((*seg_count) * sizeof(ddt_segment_t)); - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_prepare_for_send( convertor, &(datatype->super), count, NULL ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_prepare_for_send(convertor, &(datatype->super), count, NULL); position = 0; total_length = 0; - for( i = 0; i < (*seg_count); i++ ) { + for (i = 0; i < (*seg_count); i++) { segment = &((*segments)[i]); segment->buffer = malloc(segment_length); segment->position = position; /* Find the end of the segment */ position += segment_length; - opal_convertor_set_position( convertor, &position ); + opal_convertor_set_position(convertor, &position); segment->size = position - segment->position; total_length += segment->size; } OBJ_RELEASE(convertor); - if( total_length != data_size ) { - for( i = 0; i < (*seg_count); i++ ) { + if (total_length != data_size) { + for (i = 0; i < (*seg_count); i++) { segment = &((*segments)[i]); free(segment->buffer); } - free( *segments ); + free(*segments); (*seg_count) += 1; goto allocate_segments; } return 0; } -static int -shuffle_segments( ddt_segment_t* segments, int seg_count ) +static int shuffle_segments(ddt_segment_t *segments, int seg_count) { ddt_segment_t temporary; int i; - for( i = 0; i < (seg_count/2); i += 2 ) { + for (i = 0; i < (seg_count / 2); i += 2) { temporary = segments[i]; segments[i] = segments[seg_count - i - 1]; segments[seg_count - i - 1] = temporary; @@ -100,81 +97,75 @@ shuffle_segments( ddt_segment_t* segments, int seg_count ) return 0; } -static int -pack_segments( ompi_datatype_t* datatype, int count, - size_t segment_size, - ddt_segment_t* segments, int seg_count, - void* buffer ) +static int pack_segments(ompi_datatype_t *datatype, int count, size_t segment_size, + ddt_segment_t *segments, int seg_count, void *buffer) { size_t max_size, position; - opal_convertor_t* convertor; + opal_convertor_t *convertor; struct iovec iov; int i; uint32_t iov_count; - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_prepare_for_send( convertor, &(datatype->super), count, buffer ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_prepare_for_send(convertor, &(datatype->super), count, buffer); - for( i = 0; i < seg_count; i++ ) { - iov.iov_len = segments[i].size; + for (i = 0; i < seg_count; i++) { + iov.iov_len = segments[i].size; iov.iov_base = segments[i].buffer; max_size = iov.iov_len; position = segments[i].position; - opal_convertor_set_position( convertor, &position ); - if( position != segments[i].position ) { - opal_output( 0, "Setting position failed (%lu != %lu)\n", - (unsigned long)segments[i].position, (unsigned long)position ); + opal_convertor_set_position(convertor, &position); + if (position != segments[i].position) { + opal_output(0, "Setting position failed (%lu != %lu)\n", + (unsigned long) segments[i].position, (unsigned long) position); break; } iov_count = 1; - opal_convertor_pack( convertor, &iov, &iov_count, &max_size ); - if( max_size != segments[i].size ) { - opal_output( 0, "Amount of packed data do not match (%lu != %lu)\n", - (unsigned long)max_size, (unsigned long)segments[i].size ); - opal_output( 0, "Segment %d position %lu size %lu\n", i, - (unsigned long)segments[i].position, segments[i].size ); + opal_convertor_pack(convertor, &iov, &iov_count, &max_size); + if (max_size != segments[i].size) { + opal_output(0, "Amount of packed data do not match (%lu != %lu)\n", + (unsigned long) max_size, (unsigned long) segments[i].size); + opal_output(0, "Segment %d position %lu size %lu\n", i, + (unsigned long) segments[i].position, segments[i].size); } } OBJ_RELEASE(convertor); return i; } -static int -unpack_segments( ompi_datatype_t* datatype, int count, - size_t segment_size, - ddt_segment_t* segments, int seg_count, - void* buffer ) +static int unpack_segments(ompi_datatype_t *datatype, int count, size_t segment_size, + ddt_segment_t *segments, int seg_count, void *buffer) { - opal_convertor_t* convertor; + opal_convertor_t *convertor; size_t max_size, position; int i; uint32_t iov_count; struct iovec iov; - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_prepare_for_recv( convertor, &(datatype->super), count, buffer ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_prepare_for_recv(convertor, &(datatype->super), count, buffer); - for( i = 0; i < seg_count; i++ ) { + for (i = 0; i < seg_count; i++) { iov.iov_len = segments[i].size; iov.iov_base = segments[i].buffer; max_size = iov.iov_len; position = segments[i].position; - opal_convertor_set_position( convertor, &position ); - if( position != segments[i].position ) { - opal_output( 0, "Setting position failed (%lu != %lu)\n", - (unsigned long)segments[i].position, (unsigned long)position ); + opal_convertor_set_position(convertor, &position); + if (position != segments[i].position) { + opal_output(0, "Setting position failed (%lu != %lu)\n", + (unsigned long) segments[i].position, (unsigned long) position); break; } iov_count = 1; - opal_convertor_unpack( convertor, &iov, &iov_count, &max_size ); - if( max_size != segments[i].size ) { - opal_output( 0, "Amount of unpacked data do not match (%lu != %lu)\n", - (unsigned long)max_size, (unsigned long)segments[i].size ); - opal_output( 0, "Segment %d position %lu size %lu\n", i, - (unsigned long)segments[i].position, segments[i].size ); + opal_convertor_unpack(convertor, &iov, &iov_count, &max_size); + if (max_size != segments[i].size) { + opal_output(0, "Amount of unpacked data do not match (%lu != %lu)\n", + (unsigned long) max_size, (unsigned long) segments[i].size); + opal_output(0, "Segment %d position %lu size %lu\n", i, + (unsigned long) segments[i].position, segments[i].size); } } OBJ_RELEASE(convertor); @@ -183,7 +174,7 @@ unpack_segments( ompi_datatype_t* datatype, int count, typedef struct { long double ld; - int i; + int i; } ddt_ldi_t; #if 0 @@ -202,86 +193,82 @@ static void dump_ldi( ddt_ldi_t* buffer, int start_pos, int end_pos ) #if (OPAL_ENABLE_DEBUG == 1) && (OPAL_C_HAVE_VISIBILITY == 0) extern bool opal_ddt_unpack_debug; extern bool opal_ddt_pack_debug; -extern bool opal_ddt_position_debug ; -#endif /* OPAL_ENABLE_DEBUG */ +extern bool opal_ddt_position_debug; +#endif /* OPAL_ENABLE_DEBUG */ -static char* bytes_dump( void* src, size_t cnt ) +static char *bytes_dump(void *src, size_t cnt) { static char text[1024]; int index, i; - index = sprintf( text, "0x" ); - for( i = 0; i < (int)cnt; i++ ) - index += sprintf( text + index, "%x", (int)(((char*)src)[i]) ); + index = sprintf(text, "0x"); + for (i = 0; i < (int) cnt; i++) + index += sprintf(text + index, "%x", (int) (((char *) src)[i])); *(text + index) = '\0'; return text; } -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { - ddt_segment_t* segments; + ddt_segment_t *segments; ddt_ldi_t *send_buffer, *recv_buffer; int i, seg_count, errors; int show_only_first_error = 1; - ompi_datatype_t* datatype = MPI_LONG_DOUBLE_INT; + ompi_datatype_t *datatype = MPI_LONG_DOUBLE_INT; - send_buffer = malloc( sizeof(ddt_ldi_t) * data_count ); - recv_buffer = malloc( sizeof(ddt_ldi_t) * data_count ); + send_buffer = malloc(sizeof(ddt_ldi_t) * data_count); + recv_buffer = malloc(sizeof(ddt_ldi_t) * data_count); - for( i = 0; i < data_count; i++ ) { - send_buffer[i].ld = (long double)i + (long double)i / 100000.0; - send_buffer[i].i = i; + for (i = 0; i < data_count; i++) { + send_buffer[i].ld = (long double) i + (long double) i / 100000.0; + send_buffer[i].i = i; } - memcpy(recv_buffer, send_buffer, sizeof(ddt_ldi_t) * data_count ); + memcpy(recv_buffer, send_buffer, sizeof(ddt_ldi_t) * data_count); - opal_init_util (NULL, NULL); + opal_init_util(NULL, NULL); ompi_datatype_init(); #if (OPAL_ENABLE_DEBUG == 1) && (OPAL_C_HAVE_VISIBILITY == 0) - opal_ddt_unpack_debug = false; - opal_ddt_pack_debug = false; + opal_ddt_unpack_debug = false; + opal_ddt_pack_debug = false; opal_ddt_position_debug = false; -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ - create_segments( datatype, data_count, fragment_size, - &segments, &seg_count ); + create_segments(datatype, data_count, fragment_size, &segments, &seg_count); /* shuffle the segments */ - shuffle_segments( segments, seg_count ); + shuffle_segments(segments, seg_count); /* pack the data */ - pack_segments( datatype, data_count, fragment_size, segments, seg_count, - send_buffer ); + pack_segments(datatype, data_count, fragment_size, segments, seg_count, send_buffer); /* unpack the data back in the user space (recv buffer) */ - unpack_segments( datatype, data_count, fragment_size, segments, seg_count, - recv_buffer ); + unpack_segments(datatype, data_count, fragment_size, segments, seg_count, recv_buffer); /* And now check the data */ - for( errors = i = 0; i < data_count; i++ ) { + for (errors = i = 0; i < data_count; i++) { /*if( !bytes_equal(&send_buffer[i].ld, &recv_buffer[i].ld, sizeof(long double)) ||*/ - if( (send_buffer[i].ld != recv_buffer[i].ld) || - (send_buffer[i].i != recv_buffer[i].i) ) { - if( (show_only_first_error && (0 == errors)) || - !show_only_first_error ) { - printf( "error at %4d [*(%s,%d)\n" - " != (%s,%d)\n", i, - bytes_dump( &send_buffer[i].ld, sizeof(long double)), send_buffer[i].i, - bytes_dump( &recv_buffer[i].ld, sizeof(long double)), recv_buffer[i].i ); + if ((send_buffer[i].ld != recv_buffer[i].ld) || (send_buffer[i].i != recv_buffer[i].i)) { + if ((show_only_first_error && (0 == errors)) || !show_only_first_error) { + printf("error at %4d [*(%s,%d)\n" + " != (%s,%d)\n", + i, bytes_dump(&send_buffer[i].ld, sizeof(long double)), send_buffer[i].i, + bytes_dump(&recv_buffer[i].ld, sizeof(long double)), recv_buffer[i].i); } errors++; } } - printf( "Found %d errors\n", errors ); - free(send_buffer); free(recv_buffer); + printf("Found %d errors\n", errors); + free(send_buffer); + free(recv_buffer); - for( i = 0; i < seg_count; i++ ) { - free( segments[i].buffer ); + for (i = 0; i < seg_count; i++) { + free(segments[i].buffer); } free(segments); ompi_datatype_finalize(); - opal_finalize_util (); + opal_finalize_util(); return (0 == errors ? 0 : -1); } diff --git a/test/datatype/position_noncontig.c b/test/datatype/position_noncontig.c index 65a7a16e11..87412c2c77 100644 --- a/test/datatype/position_noncontig.c +++ b/test/datatype/position_noncontig.c @@ -18,10 +18,10 @@ #include <stdio.h> #include <string.h> -#include "opal/datatype/opal_convertor.h" #include "ompi/datatype/ompi_datatype.h" -#include "opal/util/output.h" +#include "opal/datatype/opal_convertor.h" #include "opal/runtime/opal.h" +#include "opal/util/output.h" /** * The purpose of this test is to simulate the multi-network packing and @@ -35,63 +35,60 @@ static int fragment_size = 113; typedef struct { size_t position; size_t size; - void* buffer; + void *buffer; } ddt_segment_t; -static int -create_segments( ompi_datatype_t* datatype, int count, - size_t segment_length, - ddt_segment_t** segments, int* seg_count ) +static int create_segments(ompi_datatype_t *datatype, int count, size_t segment_length, + ddt_segment_t **segments, int *seg_count) { size_t data_size, total_length, position; - opal_convertor_t* convertor; + opal_convertor_t *convertor; int i; - ddt_segment_t* segment; + ddt_segment_t *segment; - ompi_datatype_type_size( datatype, &data_size ); + ompi_datatype_type_size(datatype, &data_size); data_size *= count; *seg_count = data_size / segment_length; - if( ((*seg_count) * segment_length) != data_size ) + if (((*seg_count) * segment_length) != data_size) *seg_count += 1; - allocate_segments: - *segments = (ddt_segment_t*)malloc( (*seg_count) * sizeof(ddt_segment_t) ); +allocate_segments: + *segments = (ddt_segment_t *) malloc((*seg_count) * sizeof(ddt_segment_t)); - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_prepare_for_send( convertor, &(datatype->super), count, NULL ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_prepare_for_send(convertor, &(datatype->super), count, NULL); position = 0; total_length = 0; - for( i = 0; i < (*seg_count); i++ ) { + for (i = 0; i < (*seg_count); i++) { segment = &((*segments)[i]); segment->buffer = malloc(segment_length); segment->position = position; /* Find the end of the segment */ position += segment_length; - opal_convertor_set_position( convertor, &position ); + opal_convertor_set_position(convertor, &position); segment->size = position - segment->position; total_length += segment->size; } OBJ_RELEASE(convertor); - if( total_length != data_size ) { - for( i = 0; i < (*seg_count); i++ ) { + if (total_length != data_size) { + for (i = 0; i < (*seg_count); i++) { segment = &((*segments)[i]); free(segment->buffer); } - free( *segments ); + free(*segments); (*seg_count) += 1; goto allocate_segments; } return 0; } -static int -shuffle_segments( ddt_segment_t* segments, int seg_count ) +static int shuffle_segments(ddt_segment_t *segments, int seg_count) { ddt_segment_t temporary; int i; - for( i = 0; i < (seg_count/2); i += 2 ) { + for (i = 0; i < (seg_count / 2); i += 2) { temporary = segments[i]; segments[i] = segments[seg_count - i - 1]; segments[seg_count - i - 1] = temporary; @@ -99,81 +96,75 @@ shuffle_segments( ddt_segment_t* segments, int seg_count ) return 0; } -static int -pack_segments( ompi_datatype_t* datatype, int count, - size_t segment_size, - ddt_segment_t* segments, int seg_count, - void* buffer ) +static int pack_segments(ompi_datatype_t *datatype, int count, size_t segment_size, + ddt_segment_t *segments, int seg_count, void *buffer) { size_t max_size, position; - opal_convertor_t* convertor; + opal_convertor_t *convertor; struct iovec iov; int i; uint32_t iov_count; - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_prepare_for_send( convertor, &(datatype->super), count, buffer ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_prepare_for_send(convertor, &(datatype->super), count, buffer); - for( i = 0; i < seg_count; i++ ) { - iov.iov_len = segments[i].size; + for (i = 0; i < seg_count; i++) { + iov.iov_len = segments[i].size; iov.iov_base = segments[i].buffer; max_size = iov.iov_len; position = segments[i].position; - opal_convertor_set_position( convertor, &position ); - if( position != segments[i].position ) { - opal_output( 0, "Setting position failed (%lu != %lu)\n", - (unsigned long)segments[i].position, (unsigned long)position ); + opal_convertor_set_position(convertor, &position); + if (position != segments[i].position) { + opal_output(0, "Setting position failed (%lu != %lu)\n", + (unsigned long) segments[i].position, (unsigned long) position); break; } iov_count = 1; - opal_convertor_pack( convertor, &iov, &iov_count, &max_size ); - if( max_size != segments[i].size ) { - opal_output( 0, "Amount of packed data do not match (%lu != %lu)\n", - (unsigned long)max_size, (unsigned long)segments[i].size ); - opal_output( 0, "Segment %d position %lu size %lu\n", i, - (unsigned long)segments[i].position, segments[i].size ); + opal_convertor_pack(convertor, &iov, &iov_count, &max_size); + if (max_size != segments[i].size) { + opal_output(0, "Amount of packed data do not match (%lu != %lu)\n", + (unsigned long) max_size, (unsigned long) segments[i].size); + opal_output(0, "Segment %d position %lu size %lu\n", i, + (unsigned long) segments[i].position, segments[i].size); } } OBJ_RELEASE(convertor); return i; } -static int -unpack_segments( ompi_datatype_t* datatype, int count, - size_t segment_size, - ddt_segment_t* segments, int seg_count, - void* buffer ) +static int unpack_segments(ompi_datatype_t *datatype, int count, size_t segment_size, + ddt_segment_t *segments, int seg_count, void *buffer) { - opal_convertor_t* convertor; + opal_convertor_t *convertor; size_t max_size, position; int i; uint32_t iov_count; struct iovec iov; - convertor = opal_convertor_create( opal_local_arch, 0 ); - opal_convertor_prepare_for_recv( convertor, &(datatype->super), count, buffer ); + convertor = opal_convertor_create(opal_local_arch, 0); + opal_convertor_prepare_for_recv(convertor, &(datatype->super), count, buffer); - for( i = 0; i < seg_count; i++ ) { + for (i = 0; i < seg_count; i++) { iov.iov_len = segments[i].size; iov.iov_base = segments[i].buffer; max_size = iov.iov_len; position = segments[i].position; - opal_convertor_set_position( convertor, &position ); - if( position != segments[i].position ) { - opal_output( 0, "Setting position failed (%lu != %lu)\n", - (unsigned long)segments[i].position, (unsigned long)position ); + opal_convertor_set_position(convertor, &position); + if (position != segments[i].position) { + opal_output(0, "Setting position failed (%lu != %lu)\n", + (unsigned long) segments[i].position, (unsigned long) position); break; } iov_count = 1; - opal_convertor_unpack( convertor, &iov, &iov_count, &max_size ); - if( max_size != segments[i].size ) { - opal_output( 0, "Amount of unpacked data do not match (%lu != %lu)\n", - (unsigned long)max_size, (unsigned long)segments[i].size ); - opal_output( 0, "Segment %d position %lu size %lu\n", i, - (unsigned long)segments[i].position, segments[i].size ); + opal_convertor_unpack(convertor, &iov, &iov_count, &max_size); + if (max_size != segments[i].size) { + opal_output(0, "Amount of unpacked data do not match (%lu != %lu)\n", + (unsigned long) max_size, (unsigned long) segments[i].size); + opal_output(0, "Segment %d position %lu size %lu\n", i, + (unsigned long) segments[i].position, segments[i].size); } } OBJ_RELEASE(convertor); @@ -183,72 +174,69 @@ unpack_segments( ompi_datatype_t* datatype, int count, #if (OPAL_ENABLE_DEBUG == 1) && (OPAL_C_HAVE_VISIBILITY == 0) extern bool opal_ddt_unpack_debug; extern bool opal_ddt_pack_debug; -extern bool opal_ddt_position_debug ; -#endif /* OPAL_ENABLE_DEBUG */ +extern bool opal_ddt_position_debug; +#endif /* OPAL_ENABLE_DEBUG */ -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { - ddt_segment_t* segments; + ddt_segment_t *segments; int *send_buffer, *recv_buffer; int i, seg_count, errors; int show_only_first_error = 1; - ompi_datatype_t* datatype = MPI_DATATYPE_NULL; + ompi_datatype_t *datatype = MPI_DATATYPE_NULL; #define NELT (300) - send_buffer = malloc(NELT*sizeof(int)); - recv_buffer = malloc(NELT*sizeof(int)); + send_buffer = malloc(NELT * sizeof(int)); + recv_buffer = malloc(NELT * sizeof(int)); for (i = 0; i < NELT; ++i) { send_buffer[i] = i; recv_buffer[i] = 0xdeadbeef; } - opal_init_util (NULL, NULL); + opal_init_util(NULL, NULL); ompi_datatype_init(); - ompi_datatype_create_vector(NELT/2, 1, 2, MPI_INT, &datatype); + ompi_datatype_create_vector(NELT / 2, 1, 2, MPI_INT, &datatype); ompi_datatype_commit(&datatype); #if (OPAL_ENABLE_DEBUG == 1) && (OPAL_C_HAVE_VISIBILITY == 0) - opal_ddt_unpack_debug = false; - opal_ddt_pack_debug = false; + opal_ddt_unpack_debug = false; + opal_ddt_pack_debug = false; opal_ddt_position_debug = false; -#endif /* OPAL_ENABLE_DEBUG */ +#endif /* OPAL_ENABLE_DEBUG */ - create_segments( datatype, 1, fragment_size, - &segments, &seg_count ); + create_segments(datatype, 1, fragment_size, &segments, &seg_count); /* shuffle the segments */ - shuffle_segments( segments, seg_count ); + shuffle_segments(segments, seg_count); /* pack the data */ - pack_segments( datatype, 1, fragment_size, segments, seg_count, - send_buffer ); + pack_segments(datatype, 1, fragment_size, segments, seg_count, send_buffer); /* unpack the data back in the user space (recv buffer) */ - unpack_segments( datatype, 1, fragment_size, segments, seg_count, - recv_buffer ); + unpack_segments(datatype, 1, fragment_size, segments, seg_count, recv_buffer); /* And now check the data */ - for( errors = i = 0; i < NELT; i++ ) { - int expected = ((i % 2) ? (int)0xdeadbeef : i); + for (errors = i = 0; i < NELT; i++) { + int expected = ((i % 2) ? (int) 0xdeadbeef : i); if (recv_buffer[i] != expected) { - if( (show_only_first_error && (0 == errors)) || - !show_only_first_error ) { + if ((show_only_first_error && (0 == errors)) || !show_only_first_error) { printf("error at index %4d: 0x%08x != 0x%08x\n", i, recv_buffer[i], expected); } errors++; } } - printf( "Found %d errors\n", errors ); - free(send_buffer); free(recv_buffer); + printf("Found %d errors\n", errors); + free(send_buffer); + free(recv_buffer); - for( i = 0; i < seg_count; i++ ) { - free( segments[i].buffer ); + for (i = 0; i < seg_count; i++) { + free(segments[i].buffer); } free(segments); ompi_datatype_finalize(); - opal_finalize_util (); + opal_finalize_util(); return (0 == errors ? 0 : -1); } diff --git a/test/datatype/reduce_local.c b/test/datatype/reduce_local.c index f227439b71..1fbc12c170 100644 --- a/test/datatype/reduce_local.c +++ b/test/datatype/reduce_local.c @@ -12,103 +12,108 @@ * $HEADER$ */ +#include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/time.h> -#include <stdbool.h> -#include <stdint.h> #include <unistd.h> #include "mpi.h" #include "ompi/communicator/communicator.h" -#include "ompi/runtime/mpiruntime.h" #include "ompi/datatype/ompi_datatype.h" +#include "ompi/runtime/mpiruntime.h" typedef struct op_name_s { - char* name; - char* mpi_op_name; + char *name; + char *mpi_op_name; MPI_Op op; } op_name_t; -static op_name_t array_of_ops [] = { - { "max", "MPI_MAX", MPI_MAX }, - { "min", "MPI_MIN", MPI_MIN }, - { "sum", "MPI_SUM", MPI_SUM }, - { "prod", "MPI_PROD", MPI_PROD }, - { "land", "MPI_LAND", MPI_LAND }, - { "band", "MPI_BAND", MPI_BAND }, - { "lor", "MPI_LOR", MPI_LOR }, - { "bor", "MPI_BOR", MPI_BOR }, - { "lxor", "MPI_LXOR", MPI_LXOR }, - { "bxor", "MPI_BXOR", MPI_BXOR }, - { "replace", "MPI_REPLACE", MPI_REPLACE }, - { NULL, "MPI_OP_NULL", MPI_OP_NULL } +static op_name_t array_of_ops[] = { + {"max", "MPI_MAX", MPI_MAX}, + {"min", "MPI_MIN", MPI_MIN}, + {"sum", "MPI_SUM", MPI_SUM}, + {"prod", "MPI_PROD", MPI_PROD}, + {"land", "MPI_LAND", MPI_LAND}, + {"band", "MPI_BAND", MPI_BAND}, + {"lor", "MPI_LOR", MPI_LOR}, + {"bor", "MPI_BOR", MPI_BOR}, + {"lxor", "MPI_LXOR", MPI_LXOR}, + {"bxor", "MPI_BXOR", MPI_BXOR}, + {"replace", "MPI_REPLACE", MPI_REPLACE}, + {NULL, "MPI_OP_NULL", MPI_OP_NULL}, }; -static int do_ops[12] = { -1, }; /* index of the ops to do. Size +1 larger than the array_of_ops */ +static int do_ops[12] = { + -1, +}; /* index of the ops to do. Size +1 larger than the array_of_ops */ static int verbose = 0; static int total_errors = 0; -#define max(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a > _b ? _a : _b; }) - -#define min(a,b) \ - ({ __typeof__ (a) _a = (a); \ - __typeof__ (b) _b = (b); \ - _a < _b ? _a : _b; }) - -static void print_status(char* op, char* type, int type_size, - int count, int max_shift, double *duration, int repeats, - int correct ) +#define max(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a > _b ? _a : _b; \ + }) + +#define min(a, b) \ + ({ \ + __typeof__(a) _a = (a); \ + __typeof__(b) _b = (b); \ + _a < _b ? _a : _b; \ + }) + +static void print_status(char *op, char *type, int type_size, int count, int max_shift, + double *duration, int repeats, int correct) { - if(correct) { - printf("%-10s %s %-10d%s ", op, type, type_size, (verbose ? " [\033[1;32msuccess\033[0m]" : "")); + if (correct) { + printf("%-10s %s %-10d%s ", op, type, type_size, + (verbose ? " [\033[1;32msuccess\033[0m]" : "")); } else { printf("%-10s %s [\033[1;31mfail\033[0m]", op, type); total_errors++; } - if( 1 == max_shift ) { + if (1 == max_shift) { printf(" count %-10d time (seconds) %.8f seconds\n", count, duration[0] / repeats); } else { printf(" count %-10d time (seconds / shifts) ", count); - for( int i = 0; i < max_shift; i++ ) { - printf("%.8f ", duration[i] / repeats ); + for (int i = 0; i < max_shift; i++) { + printf("%.8f ", duration[i] / repeats); } printf("\n"); } } static int do_ops_built = 0; -static int -build_do_ops( char* optarg, int* do_ops) +static int build_do_ops(char *optarg, int *do_ops) { int i; - if( 0 == strcmp(optarg, "all") ) { - for( i = 0; NULL != array_of_ops[i].name; i++ ) { + if (0 == strcmp(optarg, "all")) { + for (i = 0; NULL != array_of_ops[i].name; i++) { do_ops[i] = i; } - do_ops[i] = -1; /* stop */ + do_ops[i] = -1; /* stop */ } else { int n, idx = 0; - char* token, *arg = optarg; + char *token, *arg = optarg; while ((token = strsep(&arg, ",")) != NULL) { - for( i = 0; NULL != array_of_ops[i].name; i++ ) { /* find the op */ - if( 0 == strcmp(array_of_ops[i].name, token) ) { + for (i = 0; NULL != array_of_ops[i].name; i++) { /* find the op */ + if (0 == strcmp(array_of_ops[i].name, token)) { /* check if the op was not already selected */ - for(n = 0; n < idx; n++ ) { - if( i == do_ops[n] ) { + for (n = 0; n < idx; n++) { + if (i == do_ops[n]) { break; } } - if( n >= idx ) { + if (n >= idx) { do_ops[idx++] = i; - do_ops[idx] = -1; + do_ops[idx] = -1; } break; } } - if( NULL == array_of_ops[i].name ) { + if (NULL == array_of_ops[i].name) { fprintf(stderr, "Unknown op %s. Ignored.\n", token); } } @@ -117,7 +122,7 @@ build_do_ops( char* optarg, int* do_ops) return 0; } - +/* clang-format off */ #define MPI_OP_TEST(OPNAME, MPIOP, MPITYPE, TYPE, INBUF, INOUT_BUF, CHECK_BUF, COUNT, TYPE_PREFIX) \ do { \ const TYPE *_p1 = ((TYPE*)(INBUF)), *_p3 = ((TYPE*)(CHECK_BUF)); \ @@ -174,6 +179,7 @@ do { \ } \ goto check_and_continue; \ } while (0) +/* clang-format on */ int main(int argc, char **argv) { @@ -187,25 +193,25 @@ int main(int argc, char **argv) int lower = 1, upper = 1000000, skip_op_type; MPI_Op mpi_op; - while( -1 != (c = getopt(argc, argv, "l:u:r:t:o:i:s:n:1:2:vfh")) ) { - switch(c) { + while (-1 != (c = getopt(argc, argv, "l:u:r:t:o:i:s:n:1:2:vfh"))) { + switch (c) { case 'l': lower = atoi(optarg); - if( lower <= 0 ) { + if (lower <= 0) { fprintf(stderr, "The lower number of elements must be positive\n"); exit(-1); } break; case 'u': upper = atoi(optarg); - if( lower <= 0 ) { + if (lower <= 0) { fprintf(stderr, "The upper number of elements must be positive\n"); exit(-1); } break; case 'i': max_shift = atoi(optarg); - if( max_shift <= 0 ) { + if (max_shift <= 0) { fprintf(stderr, "The max shift must be positive\n"); exit(-1); } @@ -218,27 +224,30 @@ int main(int argc, char **argv) break; case 'r': repeats = atoi(optarg); - if( repeats <= 0 ) { + if (repeats <= 0) { fprintf(stderr, "The number of repetitions (%d) must be positive\n", repeats); exit(-1); } break; case 't': - for( i = 0; i < (int)strlen(optarg); i++ ) { - if( ! (('i' == optarg[i]) || ('u' == optarg[i]) || - ('f' == optarg[i]) || ('d' == optarg[i])) ) { - fprintf(stderr, "type must be i (signed int), u (unsigned int), f (float) or d (double)\n"); + for (i = 0; i < (int) strlen(optarg); i++) { + if (!(('i' == optarg[i]) || ('u' == optarg[i]) || ('f' == optarg[i]) + || ('d' == optarg[i]))) { + fprintf( + stderr, + "type must be i (signed int), u (unsigned int), f (float) or d (double)\n"); exit(-1); } } strncpy(type, optarg, 4); break; case 'o': - build_do_ops( optarg, do_ops); + build_do_ops(optarg, do_ops); break; case 's': type_size = atoi(optarg); - if( ! ((8 == type_size) || (16 == type_size) || (32 == type_size) || (64 == type_size)) ) { + if (!((8 == type_size) || (16 == type_size) || (32 == type_size) + || (64 == type_size))) { fprintf(stderr, "type_size must be 8, 16, 32 or 64. %d is an invalid value\n", type_size); exit(-1); @@ -246,20 +255,21 @@ int main(int argc, char **argv) break; case '1': op1_alignment = atoi(optarg); - if( op1_alignment < 0 ) { + if (op1_alignment < 0) { fprintf(stderr, "alignment for the first operand must be positive\n"); exit(-1); } break; case '2': res_alignment = atoi(optarg); - if( res_alignment < 0 ) { + if (res_alignment < 0) { fprintf(stderr, "alignment for the result must be positive\n"); exit(-1); } break; case 'h': - fprintf(stdout, "%s options are:\n" + fprintf(stdout, + "%s options are:\n" " -l <number> : lower number of elements\n" " -u <number> : upper number of elements\n" " -s <type_size> : 8, 16, 32 or 64 bits elements\n" @@ -271,476 +281,434 @@ int main(int argc, char **argv) " -1 <number> : (mis)alignment in elements for the first op\n" " -2 <number> : (mis)alignment in elements for the result\n" " -v: increase the verbosity level\n" - " -h: this help message\n", argv[0]); + " -h: this help message\n", + argv[0]); exit(0); } } - if( !do_ops_built ) { /* not yet done, take the default */ - build_do_ops( "all", do_ops); + if (!do_ops_built) { /* not yet done, take the default */ + build_do_ops("all", do_ops); } - posix_memalign( &in_buf, 64, (upper + op1_alignment) * sizeof(double)); - posix_memalign( &inout_buf, 64, (upper + res_alignment) * sizeof(double)); - posix_memalign( &inout_check_buf, 64, upper * sizeof(double)); - duration = (double*)malloc(max_shift * sizeof(double)); + posix_memalign(&in_buf, 64, (upper + op1_alignment) * sizeof(double)); + posix_memalign(&inout_buf, 64, (upper + res_alignment) * sizeof(double)); + posix_memalign(&inout_check_buf, 64, upper * sizeof(double)); + duration = (double *) malloc(max_shift * sizeof(double)); ompi_mpi_init(argc, argv, MPI_THREAD_SERIALIZED, &provided, false); - rank = ompi_comm_rank(MPI_COMM_WORLD); (void)rank; - size = ompi_comm_size(MPI_COMM_WORLD); (void)size; + rank = ompi_comm_rank(MPI_COMM_WORLD); + (void) rank; + size = ompi_comm_size(MPI_COMM_WORLD); + (void) size; - for(uint32_t type_idx = 0; type_idx < strlen(type); type_idx++ ) { - for(uint32_t op_idx = 0; do_ops[op_idx] >= 0; op_idx++ ) { - op = array_of_ops[do_ops[op_idx]].name; + for (uint32_t type_idx = 0; type_idx < strlen(type); type_idx++) { + for (uint32_t op_idx = 0; do_ops[op_idx] >= 0; op_idx++) { + op = array_of_ops[do_ops[op_idx]].name; mpi_op = array_of_ops[do_ops[op_idx]].op; skip_op_type = 1; - for( count = lower; count <= upper; count += count ) { + for (count = lower; count <= upper; count += count) { mpi_type = NULL; correctness = 1; - if('i' == type[type_idx]) { - if( 8 == type_size ) { - int8_t *in_int8 = (int8_t*)((char*)in_buf + op1_alignment * sizeof(int8_t)), - *inout_int8 = (int8_t*)((char*)inout_buf + res_alignment * sizeof(int8_t)), - *inout_int8_for_check = (int8_t*)inout_check_buf; - for( i = 0; i < count; i++ ) { + if ('i' == type[type_idx]) { + if (8 == type_size) { + int8_t *in_int8 = (int8_t *) ((char *) in_buf + + op1_alignment * sizeof(int8_t)), + *inout_int8 = (int8_t *) ((char *) inout_buf + + res_alignment * sizeof(int8_t)), + *inout_int8_for_check = (int8_t *) inout_check_buf; + for (i = 0; i < count; i++) { in_int8[i] = 5; inout_int8[i] = inout_int8_for_check[i] = -3; } mpi_type = "MPI_INT8_T"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_INT8_T, int8_t, - in_int8, inout_int8, inout_int8_for_check, - count, PRId8); - } - if( 0 == strcmp(op, "bor") ) { - MPI_OP_TEST( |, mpi_op, MPI_INT8_T, int8_t, - in_int8, inout_int8, inout_int8_for_check, - count, PRId8); - } - if( 0 == strcmp(op, "bxor") ) { - MPI_OP_TEST( ^, mpi_op, MPI_INT8_T, int8_t, - in_int8, inout_int8, inout_int8_for_check, - count, PRId8); - } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_INT8_T, int8_t, - in_int8, inout_int8, inout_int8_for_check, - count, PRId8); - } - if( 0 == strcmp(op, "band") ) { - MPI_OP_TEST( &, mpi_op, MPI_INT8_T, int8_t, - in_int8, inout_int8, inout_int8_for_check, - count, PRId8); - } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_INT8_T, int8_t, - in_int8, inout_int8, inout_int8_for_check, - count, PRId8); - } - if( 0 == strcmp(op, "min") ) { //intentionly reversed in and out - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_INT8_T, int8_t, - in_int8, inout_int8, inout_int8_for_check, - count, PRId8); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_INT8_T, int8_t, in_int8, inout_int8, + inout_int8_for_check, count, PRId8); + } + if (0 == strcmp(op, "bor")) { + MPI_OP_TEST(|, mpi_op, MPI_INT8_T, int8_t, in_int8, inout_int8, + inout_int8_for_check, count, PRId8); + } + if (0 == strcmp(op, "bxor")) { + MPI_OP_TEST(^, mpi_op, MPI_INT8_T, int8_t, in_int8, inout_int8, + inout_int8_for_check, count, PRId8); + } + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_INT8_T, int8_t, in_int8, inout_int8, + inout_int8_for_check, count, PRId8); + } + if (0 == strcmp(op, "band")) { + MPI_OP_TEST(&, mpi_op, MPI_INT8_T, int8_t, in_int8, inout_int8, + inout_int8_for_check, count, PRId8); + } + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_INT8_T, int8_t, in_int8, inout_int8, + inout_int8_for_check, count, PRId8); + } + if (0 == strcmp(op, "min")) { // intentionly reversed in and out + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_INT8_T, int8_t, in_int8, inout_int8, + inout_int8_for_check, count, PRId8); } } - if( 16 == type_size ) { - int16_t *in_int16 = (int16_t*)((char*)in_buf + op1_alignment * sizeof(int16_t)), - *inout_int16 = (int16_t*)((char*)inout_buf + res_alignment * sizeof(int16_t)), - *inout_int16_for_check = (int16_t*)inout_check_buf; - for( i = 0; i < count; i++ ) { + if (16 == type_size) { + int16_t *in_int16 = (int16_t *) ((char *) in_buf + + op1_alignment * sizeof(int16_t)), + *inout_int16 = (int16_t *) ((char *) inout_buf + + res_alignment * sizeof(int16_t)), + *inout_int16_for_check = (int16_t *) inout_check_buf; + for (i = 0; i < count; i++) { in_int16[i] = 5; inout_int16[i] = inout_int16_for_check[i] = -3; } mpi_type = "MPI_INT16_T"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_INT16_T, int16_t, - in_int16, inout_int16, inout_int16_for_check, - count, PRId16); - } - if( 0 == strcmp(op, "bor") ) { - MPI_OP_TEST( |, mpi_op, MPI_INT16_T, int16_t, - in_int16, inout_int16, inout_int16_for_check, - count, PRId16); - } - if( 0 == strcmp(op, "bxor") ) { - MPI_OP_TEST( ^, mpi_op, MPI_INT16_T, int16_t, - in_int16, inout_int16, inout_int16_for_check, - count, PRId16); - } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_INT16_T, int16_t, - in_int16, inout_int16, inout_int16_for_check, - count, PRId16); - } - if( 0 == strcmp(op, "band") ) { - MPI_OP_TEST( &, mpi_op, MPI_INT16_T, int16_t, - in_int16, inout_int16, inout_int16_for_check, - count, PRId16); - } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_INT16_T, int16_t, - in_int16, inout_int16, inout_int16_for_check, - count, PRId16); - } - if( 0 == strcmp(op, "min") ) { //intentionly reversed in and out - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_INT16_T, int16_t, - in_int16, inout_int16, inout_int16_for_check, - count, PRId16); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_INT16_T, int16_t, in_int16, inout_int16, + inout_int16_for_check, count, PRId16); + } + if (0 == strcmp(op, "bor")) { + MPI_OP_TEST(|, mpi_op, MPI_INT16_T, int16_t, in_int16, inout_int16, + inout_int16_for_check, count, PRId16); + } + if (0 == strcmp(op, "bxor")) { + MPI_OP_TEST(^, mpi_op, MPI_INT16_T, int16_t, in_int16, inout_int16, + inout_int16_for_check, count, PRId16); + } + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_INT16_T, int16_t, in_int16, inout_int16, + inout_int16_for_check, count, PRId16); + } + if (0 == strcmp(op, "band")) { + MPI_OP_TEST(&, mpi_op, MPI_INT16_T, int16_t, in_int16, inout_int16, + inout_int16_for_check, count, PRId16); + } + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_INT16_T, int16_t, in_int16, + inout_int16, inout_int16_for_check, count, PRId16); + } + if (0 == strcmp(op, "min")) { // intentionly reversed in and out + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_INT16_T, int16_t, in_int16, + inout_int16, inout_int16_for_check, count, PRId16); } } - if( 32 == type_size ) { - int32_t *in_int32 = (int32_t*)((char*)in_buf + op1_alignment * sizeof(int32_t)), - *inout_int32 = (int32_t*)((char*)inout_buf + res_alignment * sizeof(int32_t)), - *inout_int32_for_check = (int32_t*)inout_check_buf; - for( i = 0; i < count; i++ ) { + if (32 == type_size) { + int32_t *in_int32 = (int32_t *) ((char *) in_buf + + op1_alignment * sizeof(int32_t)), + *inout_int32 = (int32_t *) ((char *) inout_buf + + res_alignment * sizeof(int32_t)), + *inout_int32_for_check = (int32_t *) inout_check_buf; + for (i = 0; i < count; i++) { in_int32[i] = 5; inout_int32[i] = inout_int32_for_check[i] = 3; } mpi_type = "MPI_INT32_T"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_INT32_T, int32_t, - in_int32, inout_int32, inout_int32_for_check, - count, PRId32); - } - if( 0 == strcmp(op, "bor") ) { - MPI_OP_TEST( |, mpi_op, MPI_INT32_T, int32_t, - in_int32, inout_int32, inout_int32_for_check, - count, PRId32); - } - if( 0 == strcmp(op, "bxor") ) { - MPI_OP_TEST( ^, mpi_op, MPI_INT32_T, int32_t, - in_int32, inout_int32, inout_int32_for_check, - count, PRId32); - } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_INT32_T, int32_t, - in_int32, inout_int32, inout_int32_for_check, - count, PRId32); - } - if( 0 == strcmp(op, "band") ) { - MPI_OP_TEST( &, mpi_op, MPI_INT32_T, int32_t, - in_int32, inout_int32, inout_int32_for_check, - count, PRId32); - } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_INT32_T, int32_t, - in_int32, inout_int32, inout_int32_for_check, - count, PRId32); - } - if( 0 == strcmp(op, "min") ) { //intentionly reversed in and out - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_INT32_T, int32_t, - in_int32, inout_int32, inout_int32_for_check, - count, PRId32); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_INT32_T, int32_t, in_int32, inout_int32, + inout_int32_for_check, count, PRId32); + } + if (0 == strcmp(op, "bor")) { + MPI_OP_TEST(|, mpi_op, MPI_INT32_T, int32_t, in_int32, inout_int32, + inout_int32_for_check, count, PRId32); + } + if (0 == strcmp(op, "bxor")) { + MPI_OP_TEST(^, mpi_op, MPI_INT32_T, int32_t, in_int32, inout_int32, + inout_int32_for_check, count, PRId32); + } + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_INT32_T, int32_t, in_int32, inout_int32, + inout_int32_for_check, count, PRId32); + } + if (0 == strcmp(op, "band")) { + MPI_OP_TEST(&, mpi_op, MPI_INT32_T, int32_t, in_int32, inout_int32, + inout_int32_for_check, count, PRId32); + } + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_INT32_T, int32_t, in_int32, + inout_int32, inout_int32_for_check, count, PRId32); + } + if (0 == strcmp(op, "min")) { // intentionly reversed in and out + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_INT32_T, int32_t, in_int32, + inout_int32, inout_int32_for_check, count, PRId32); } } - if( 64 == type_size ) { - int64_t *in_int64 = (int64_t*)((char*)in_buf + op1_alignment * sizeof(int64_t)), - *inout_int64 = (int64_t*)((char*)inout_buf + res_alignment * sizeof(int64_t)), - *inout_int64_for_check = (int64_t*)inout_check_buf; - for( i = 0; i < count; i++ ) { + if (64 == type_size) { + int64_t *in_int64 = (int64_t *) ((char *) in_buf + + op1_alignment * sizeof(int64_t)), + *inout_int64 = (int64_t *) ((char *) inout_buf + + res_alignment * sizeof(int64_t)), + *inout_int64_for_check = (int64_t *) inout_check_buf; + for (i = 0; i < count; i++) { in_int64[i] = 5; inout_int64[i] = inout_int64_for_check[i] = 3; } mpi_type = "MPI_INT64_T"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_INT64_T, int64_t, - in_int64, inout_int64, inout_int64_for_check, - count, PRId64); - } - if( 0 == strcmp(op, "bor") ) { - MPI_OP_TEST( |, mpi_op, MPI_INT64_T, int64_t, - in_int64, inout_int64, inout_int64_for_check, - count, PRId64); - } - if( 0 == strcmp(op, "bxor") ) { - MPI_OP_TEST( ^, mpi_op, MPI_INT64_T, int64_t, - in_int64, inout_int64, inout_int64_for_check, - count, PRId64); - } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_INT64_T, int64_t, - in_int64, inout_int64, inout_int64_for_check, - count, PRId64); - } - if( 0 == strcmp(op, "band") ) { - MPI_OP_TEST( &, mpi_op, MPI_INT64_T, int64_t, - in_int64, inout_int64, inout_int64_for_check, - count, PRId64); - } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_INT64_T, int64_t, - in_int64, inout_int64, inout_int64_for_check, - count, PRId64); - } - if( 0 == strcmp(op, "min") ) { //intentionly reversed in and out - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_INT64_T, int64_t, - in_int64, inout_int64, inout_int64_for_check, - count, PRId64); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_INT64_T, int64_t, in_int64, inout_int64, + inout_int64_for_check, count, PRId64); + } + if (0 == strcmp(op, "bor")) { + MPI_OP_TEST(|, mpi_op, MPI_INT64_T, int64_t, in_int64, inout_int64, + inout_int64_for_check, count, PRId64); + } + if (0 == strcmp(op, "bxor")) { + MPI_OP_TEST(^, mpi_op, MPI_INT64_T, int64_t, in_int64, inout_int64, + inout_int64_for_check, count, PRId64); + } + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_INT64_T, int64_t, in_int64, inout_int64, + inout_int64_for_check, count, PRId64); + } + if (0 == strcmp(op, "band")) { + MPI_OP_TEST(&, mpi_op, MPI_INT64_T, int64_t, in_int64, inout_int64, + inout_int64_for_check, count, PRId64); + } + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_INT64_T, int64_t, in_int64, + inout_int64, inout_int64_for_check, count, PRId64); + } + if (0 == strcmp(op, "min")) { // intentionly reversed in and out + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_INT64_T, int64_t, in_int64, + inout_int64, inout_int64_for_check, count, PRId64); } } } - if( 'u' == type[type_idx] ) { - if( 8 == type_size ) { - uint8_t *in_uint8 = (uint8_t*)((char*)in_buf + op1_alignment * sizeof(uint8_t)), - *inout_uint8 = (uint8_t*)((char*)inout_buf + res_alignment * sizeof(uint8_t)), - *inout_uint8_for_check = (uint8_t*)inout_check_buf; - for( i = 0; i < count; i++ ) { + if ('u' == type[type_idx]) { + if (8 == type_size) { + uint8_t *in_uint8 = (uint8_t *) ((char *) in_buf + + op1_alignment * sizeof(uint8_t)), + *inout_uint8 = (uint8_t *) ((char *) inout_buf + + res_alignment * sizeof(uint8_t)), + *inout_uint8_for_check = (uint8_t *) inout_check_buf; + for (i = 0; i < count; i++) { in_uint8[i] = 5; inout_uint8[i] = inout_uint8_for_check[i] = 2; } mpi_type = "MPI_UINT8_T"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_UINT8_T, uint8_t, - in_uint8, inout_uint8, inout_uint8_for_check, - count, PRIu8); - } - if( 0 == strcmp(op, "bor") ) { - MPI_OP_TEST( |, mpi_op, MPI_UINT8_T, uint8_t, - in_uint8, inout_uint8, inout_uint8_for_check, - count, PRIu8); - } - if( 0 == strcmp(op, "bxor") ) { - MPI_OP_TEST( ^, mpi_op, MPI_UINT8_T, uint8_t, - in_uint8, inout_uint8, inout_uint8_for_check, - count, PRIu8); - } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_UINT8_T, uint8_t, - in_uint8, inout_uint8, inout_uint8_for_check, - count, PRIu8); - } - if( 0 == strcmp(op, "band") ) { - MPI_OP_TEST( &, mpi_op, MPI_UINT8_T, uint8_t, - in_uint8, inout_uint8, inout_uint8_for_check, - count, PRIu8); - } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_UINT8_T, uint8_t, - in_uint8, inout_uint8, inout_uint8_for_check, - count, PRIu8); - } - if( 0 == strcmp(op, "min") ) { //intentionly reversed in and out - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_UINT8_T, uint8_t, - in_uint8, inout_uint8, inout_uint8_for_check, - count, PRIu8); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_UINT8_T, uint8_t, in_uint8, inout_uint8, + inout_uint8_for_check, count, PRIu8); + } + if (0 == strcmp(op, "bor")) { + MPI_OP_TEST(|, mpi_op, MPI_UINT8_T, uint8_t, in_uint8, inout_uint8, + inout_uint8_for_check, count, PRIu8); + } + if (0 == strcmp(op, "bxor")) { + MPI_OP_TEST(^, mpi_op, MPI_UINT8_T, uint8_t, in_uint8, inout_uint8, + inout_uint8_for_check, count, PRIu8); + } + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_UINT8_T, uint8_t, in_uint8, inout_uint8, + inout_uint8_for_check, count, PRIu8); + } + if (0 == strcmp(op, "band")) { + MPI_OP_TEST(&, mpi_op, MPI_UINT8_T, uint8_t, in_uint8, inout_uint8, + inout_uint8_for_check, count, PRIu8); + } + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_UINT8_T, uint8_t, in_uint8, + inout_uint8, inout_uint8_for_check, count, PRIu8); + } + if (0 == strcmp(op, "min")) { // intentionly reversed in and out + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_UINT8_T, uint8_t, in_uint8, + inout_uint8, inout_uint8_for_check, count, PRIu8); } } - if( 16 == type_size ) { - uint16_t *in_uint16 = (uint16_t*)((char*)in_buf + op1_alignment * sizeof(uint16_t)), - *inout_uint16 = (uint16_t*)((char*)inout_buf + res_alignment * sizeof(uint16_t)), - *inout_uint16_for_check = (uint16_t*)inout_check_buf; - for( i = 0; i < count; i++ ) { + if (16 == type_size) { + uint16_t *in_uint16 = (uint16_t *) ((char *) in_buf + + op1_alignment * sizeof(uint16_t)), + *inout_uint16 = (uint16_t *) ((char *) inout_buf + + res_alignment * sizeof(uint16_t)), + *inout_uint16_for_check = (uint16_t *) inout_check_buf; + for (i = 0; i < count; i++) { in_uint16[i] = 5; inout_uint16[i] = inout_uint16_for_check[i] = 1234; } mpi_type = "MPI_UINT16_T"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_UINT16_T, uint16_t, - in_uint16, inout_uint16, inout_uint16_for_check, - count, PRIu16); - } - if( 0 == strcmp(op, "bor") ) { - MPI_OP_TEST( |, mpi_op, MPI_UINT16_T, uint16_t, - in_uint16, inout_uint16, inout_uint16_for_check, - count, PRIu16); - } - if( 0 == strcmp(op, "bxor") ) { - MPI_OP_TEST( ^, mpi_op, MPI_UINT16_T, uint16_t, - in_uint16, inout_uint16, inout_uint16_for_check, - count, PRIu16); - } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_UINT16_T, uint16_t, - in_uint16, inout_uint16, inout_uint16_for_check, - count, PRIu16); - } - if( 0 == strcmp(op, "band") ) { - MPI_OP_TEST( &, mpi_op, MPI_UINT16_T, uint16_t, - in_uint16, inout_uint16, inout_uint16_for_check, - count, PRIu16); - } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_UINT16_T, uint16_t, - in_uint16, inout_uint16, inout_uint16_for_check, - count, PRIu16); - } - if( 0 == strcmp(op, "min") ) { //intentionly reversed in and out - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_UINT16_T, uint16_t, - in_uint16, inout_uint16, inout_uint16_for_check, - count, PRIu16); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_UINT16_T, uint16_t, in_uint16, inout_uint16, + inout_uint16_for_check, count, PRIu16); + } + if (0 == strcmp(op, "bor")) { + MPI_OP_TEST(|, mpi_op, MPI_UINT16_T, uint16_t, in_uint16, inout_uint16, + inout_uint16_for_check, count, PRIu16); + } + if (0 == strcmp(op, "bxor")) { + MPI_OP_TEST(^, mpi_op, MPI_UINT16_T, uint16_t, in_uint16, inout_uint16, + inout_uint16_for_check, count, PRIu16); + } + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_UINT16_T, uint16_t, in_uint16, inout_uint16, + inout_uint16_for_check, count, PRIu16); + } + if (0 == strcmp(op, "band")) { + MPI_OP_TEST(&, mpi_op, MPI_UINT16_T, uint16_t, in_uint16, inout_uint16, + inout_uint16_for_check, count, PRIu16); + } + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_UINT16_T, uint16_t, in_uint16, + inout_uint16, inout_uint16_for_check, count, PRIu16); + } + if (0 == strcmp(op, "min")) { // intentionly reversed in and out + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_UINT16_T, uint16_t, in_uint16, + inout_uint16, inout_uint16_for_check, count, PRIu16); } } - if( 32 == type_size ) { - uint32_t *in_uint32 = (uint32_t*)((char*)in_buf + op1_alignment * sizeof(uint32_t)), - *inout_uint32 = (uint32_t*)((char*)inout_buf + res_alignment * sizeof(uint32_t)), - *inout_uint32_for_check = (uint32_t*)inout_check_buf; - for( i = 0; i < count; i++ ) { + if (32 == type_size) { + uint32_t *in_uint32 = (uint32_t *) ((char *) in_buf + + op1_alignment * sizeof(uint32_t)), + *inout_uint32 = (uint32_t *) ((char *) inout_buf + + res_alignment * sizeof(uint32_t)), + *inout_uint32_for_check = (uint32_t *) inout_check_buf; + for (i = 0; i < count; i++) { in_uint32[i] = 5; inout_uint32[i] = inout_uint32_for_check[i] = 3; } mpi_type = "MPI_UINT32_T"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_UINT32_T, uint32_t, - in_uint32, inout_uint32, inout_uint32_for_check, - count, PRIu32); - } - if( 0 == strcmp(op, "bor") ) { - MPI_OP_TEST( |, mpi_op, MPI_UINT32_T, uint32_t, - in_uint32, inout_uint32, inout_uint32_for_check, - count, PRIu32); - } - if( 0 == strcmp(op, "bxor") ) { - MPI_OP_TEST( ^, mpi_op, MPI_UINT32_T, uint32_t, - in_uint32, inout_uint32, inout_uint32_for_check, - count, PRIu32); - } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_UINT32_T, uint32_t, - in_uint32, inout_uint32, inout_uint32_for_check, - count, PRIu32); - } - if( 0 == strcmp(op, "band") ) { - MPI_OP_TEST( &, mpi_op, MPI_UINT32_T, uint32_t, - in_uint32, inout_uint32, inout_uint32_for_check, - count, PRIu32); - } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_UINT32_T, uint32_t, - in_uint32, inout_uint32, inout_uint32_for_check, - count, PRIu32); - } - if( 0 == strcmp(op, "min") ) { //intentionly reversed in and out - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_UINT32_T, uint32_t, - in_uint32, inout_uint32, inout_uint32_for_check, - count, PRIu32); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_UINT32_T, uint32_t, in_uint32, inout_uint32, + inout_uint32_for_check, count, PRIu32); + } + if (0 == strcmp(op, "bor")) { + MPI_OP_TEST(|, mpi_op, MPI_UINT32_T, uint32_t, in_uint32, inout_uint32, + inout_uint32_for_check, count, PRIu32); + } + if (0 == strcmp(op, "bxor")) { + MPI_OP_TEST(^, mpi_op, MPI_UINT32_T, uint32_t, in_uint32, inout_uint32, + inout_uint32_for_check, count, PRIu32); + } + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_UINT32_T, uint32_t, in_uint32, inout_uint32, + inout_uint32_for_check, count, PRIu32); + } + if (0 == strcmp(op, "band")) { + MPI_OP_TEST(&, mpi_op, MPI_UINT32_T, uint32_t, in_uint32, inout_uint32, + inout_uint32_for_check, count, PRIu32); + } + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_UINT32_T, uint32_t, in_uint32, + inout_uint32, inout_uint32_for_check, count, PRIu32); + } + if (0 == strcmp(op, "min")) { // intentionly reversed in and out + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_UINT32_T, uint32_t, in_uint32, + inout_uint32, inout_uint32_for_check, count, PRIu32); } } - if( 64 == type_size ) { - uint64_t *in_uint64 = (uint64_t*)((char*)in_buf + op1_alignment * sizeof(uint64_t)), - *inout_uint64 = (uint64_t*)((char*)inout_buf + res_alignment * sizeof(uint64_t)), - *inout_uint64_for_check = (uint64_t*)inout_check_buf; - for( i = 0; i < count; i++ ) { + if (64 == type_size) { + uint64_t *in_uint64 = (uint64_t *) ((char *) in_buf + + op1_alignment * sizeof(uint64_t)), + *inout_uint64 = (uint64_t *) ((char *) inout_buf + + res_alignment * sizeof(uint64_t)), + *inout_uint64_for_check = (uint64_t *) inout_check_buf; + for (i = 0; i < count; i++) { in_uint64[i] = 5; inout_uint64[i] = inout_uint64_for_check[i] = 32433; } mpi_type = "MPI_UINT64_T"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_UINT64_T, uint64_t, - in_uint64, inout_uint64, inout_uint64_for_check, - count, PRIu64); - } - if( 0 == strcmp(op, "bor") ) { - MPI_OP_TEST( |, mpi_op, MPI_UINT64_T, uint64_t, - in_uint64, inout_uint64, inout_uint64_for_check, - count, PRIu64); - } - if( 0 == strcmp(op, "bxor") ) { - MPI_OP_TEST( ^, mpi_op, MPI_UINT64_T, uint64_t, - in_uint64, inout_uint64, inout_uint64_for_check, - count, PRIu64); - } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_UINT64_T, uint64_t, - in_uint64, inout_uint64, inout_uint64_for_check, - count, PRIu64); - } - if( 0 == strcmp(op, "band") ) { - MPI_OP_TEST( &, mpi_op, MPI_UINT64_T, uint64_t, - in_uint64, inout_uint64, inout_uint64_for_check, - count, PRIu64); - } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_UINT64_T, uint64_t, - in_uint64, inout_uint64, inout_uint64_for_check, - count, PRIu64); - } - if( 0 == strcmp(op, "min") ) { - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_UINT64_T, uint64_t, - in_uint64, inout_uint64, inout_uint64_for_check, - count, PRIu64); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_UINT64_T, uint64_t, in_uint64, inout_uint64, + inout_uint64_for_check, count, PRIu64); + } + if (0 == strcmp(op, "bor")) { + MPI_OP_TEST(|, mpi_op, MPI_UINT64_T, uint64_t, in_uint64, inout_uint64, + inout_uint64_for_check, count, PRIu64); + } + if (0 == strcmp(op, "bxor")) { + MPI_OP_TEST(^, mpi_op, MPI_UINT64_T, uint64_t, in_uint64, inout_uint64, + inout_uint64_for_check, count, PRIu64); + } + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_UINT64_T, uint64_t, in_uint64, inout_uint64, + inout_uint64_for_check, count, PRIu64); + } + if (0 == strcmp(op, "band")) { + MPI_OP_TEST(&, mpi_op, MPI_UINT64_T, uint64_t, in_uint64, inout_uint64, + inout_uint64_for_check, count, PRIu64); + } + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_UINT64_T, uint64_t, in_uint64, + inout_uint64, inout_uint64_for_check, count, PRIu64); + } + if (0 == strcmp(op, "min")) { + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_UINT64_T, uint64_t, in_uint64, + inout_uint64, inout_uint64_for_check, count, PRIu64); } } } - if( 'f' == type[type_idx] ) { - float *in_float = (float*)((char*)in_buf + op1_alignment * sizeof(float)), - *inout_float = (float*)((char*)inout_buf + res_alignment * sizeof(float)), - *inout_float_for_check = (float*)inout_check_buf; - for( i = 0; i < count; i++ ) { - in_float[i] = 1000.0+1; - inout_float[i] = inout_float_for_check[i] = 100.0+2; + if ('f' == type[type_idx]) { + float *in_float = (float *) ((char *) in_buf + op1_alignment * sizeof(float)), + *inout_float = (float *) ((char *) inout_buf + + res_alignment * sizeof(float)), + *inout_float_for_check = (float *) inout_check_buf; + for (i = 0; i < count; i++) { + in_float[i] = 1000.0 + 1; + inout_float[i] = inout_float_for_check[i] = 100.0 + 2; } mpi_type = "MPI_FLOAT"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_FLOAT, float, - in_float, inout_float, inout_float_for_check, - count, "f"); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_FLOAT, float, in_float, inout_float, + inout_float_for_check, count, "f"); } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_FLOAT, float, - in_float, inout_float, inout_float_for_check, - count, "f"); + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_FLOAT, float, in_float, inout_float, + inout_float_for_check, count, "f"); } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_FLOAT, float, - in_float, inout_float, inout_float_for_check, - count, "f"); + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_FLOAT, float, in_float, inout_float, + inout_float_for_check, count, "f"); } - if( 0 == strcmp(op, "min") ) { - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_FLOAT, float, - in_float, inout_float, inout_float_for_check, - count, "f"); + if (0 == strcmp(op, "min")) { + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_FLOAT, float, in_float, inout_float, + inout_float_for_check, count, "f"); } } - if( 'd' == type[type_idx] ) { - double *in_double = (double*)((char*)in_buf + op1_alignment * sizeof(double)), - *inout_double = (double*)((char*)inout_buf + res_alignment * sizeof(double)), - *inout_double_for_check = (double*)inout_check_buf; - for( i = 0; i < count; i++ ) { - in_double[i] = 10.0+1; - inout_double[i] = inout_double_for_check[i] = 1.0+2; + if ('d' == type[type_idx]) { + double *in_double = (double *) ((char *) in_buf + + op1_alignment * sizeof(double)), + *inout_double = (double *) ((char *) inout_buf + + res_alignment * sizeof(double)), + *inout_double_for_check = (double *) inout_check_buf; + for (i = 0; i < count; i++) { + in_double[i] = 10.0 + 1; + inout_double[i] = inout_double_for_check[i] = 1.0 + 2; } mpi_type = "MPI_DOUBLE"; - if( 0 == strcmp(op, "sum") ) { - MPI_OP_TEST( +, mpi_op, MPI_DOUBLE, double, - in_double, inout_double, inout_double_for_check, - count, "g"); + if (0 == strcmp(op, "sum")) { + MPI_OP_TEST(+, mpi_op, MPI_DOUBLE, double, in_double, inout_double, + inout_double_for_check, count, "g"); } - if( 0 == strcmp(op, "prod") ) { - MPI_OP_TEST( *, mpi_op, MPI_DOUBLE, double, - in_double, inout_double, inout_double_for_check, - count, "f"); + if (0 == strcmp(op, "prod")) { + MPI_OP_TEST(*, mpi_op, MPI_DOUBLE, double, in_double, inout_double, + inout_double_for_check, count, "f"); } - if( 0 == strcmp(op, "max") ) { - MPI_OP_MINMAX_TEST(max, mpi_op, MPI_DOUBLE, double, - in_double, inout_double, inout_double_for_check, - count, "f"); + if (0 == strcmp(op, "max")) { + MPI_OP_MINMAX_TEST(max, mpi_op, MPI_DOUBLE, double, in_double, inout_double, + inout_double_for_check, count, "f"); } - if( 0 == strcmp(op, "min") ) { - MPI_OP_MINMAX_TEST(min, mpi_op, MPI_DOUBLE, double, - in_double, inout_double, inout_double_for_check, - count, "f"); + if (0 == strcmp(op, "min")) { + MPI_OP_MINMAX_TEST(min, mpi_op, MPI_DOUBLE, double, in_double, inout_double, + inout_double_for_check, count, "f"); } } - check_and_continue: - if( !skip_op_type ) - print_status(array_of_ops[do_ops[op_idx]].mpi_op_name, - mpi_type, type_size, count, max_shift, duration, repeats, correctness); + check_and_continue: + if (!skip_op_type) + print_status(array_of_ops[do_ops[op_idx]].mpi_op_name, mpi_type, type_size, + count, max_shift, duration, repeats, correctness); } - if( !skip_op_type ) + if (!skip_op_type) printf("\n"); } } @@ -752,4 +720,3 @@ int main(int argc, char **argv) return (0 == total_errors) ? 0 : -1; } - diff --git a/test/datatype/to_self.c b/test/datatype/to_self.c index 8b614759a9..e7158bb756 100644 --- a/test/datatype/to_self.c +++ b/test/datatype/to_self.c @@ -12,35 +12,32 @@ #include "mpi.h" +#include <math.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <math.h> #if 0 && OPEN_MPI extern void ompi_datatype_dump( MPI_Datatype ddt ); -#define MPI_DDT_DUMP(ddt) ompi_datatype_dump( (ddt) ) +# define MPI_DDT_DUMP(ddt) ompi_datatype_dump((ddt)) #else -#define MPI_DDT_DUMP(ddt) -#endif /* OPEN_MPI */ +# define MPI_DDT_DUMP(ddt) +#endif /* OPEN_MPI */ -static MPI_Datatype -create_merged_contig_with_gaps(int count) /* count of the basic datatype */ +static MPI_Datatype create_merged_contig_with_gaps(int count) /* count of the basic datatype */ { int array_of_blocklengths[] = {1, 1, 1}; MPI_Aint array_of_displacements[] = {0, 8, 16}; MPI_Datatype array_of_types[] = {MPI_DOUBLE, MPI_LONG, MPI_CHAR}; MPI_Datatype type; - MPI_Type_create_struct(3, array_of_blocklengths, - array_of_displacements, array_of_types, - &type); - if( 1 < count ) { + MPI_Type_create_struct(3, array_of_blocklengths, array_of_displacements, array_of_types, &type); + if (1 < count) { MPI_Datatype temp = type; MPI_Type_contiguous(count, temp, &type); } MPI_Type_commit(&type); - MPI_DDT_DUMP( type ); + MPI_DDT_DUMP(type); return type; } @@ -51,10 +48,10 @@ struct structure { double transfered_2; }; -static MPI_Datatype -create_struct_constant_gap_resized_ddt( int number, /* IGNORED: number of repetitions */ - int contig_size, /* IGNORED: number of elements in a contiguous chunk */ - int gap_size ) /* IGNORED: number of elements in a gap */ +static MPI_Datatype create_struct_constant_gap_resized_ddt( + int number, /* IGNORED: number of repetitions */ + int contig_size, /* IGNORED: number of elements in a contiguous chunk */ + int gap_size) /* IGNORED: number of elements in a gap */ { struct structure data[1]; MPI_Datatype struct_type, temp_type; @@ -72,111 +69,109 @@ create_struct_constant_gap_resized_ddt( int number, /* IGNORED: number of repet MPI_Type_create_resized(temp_type, 0, sizeof(data[0]), &struct_type); MPI_Type_commit(&struct_type); MPI_Type_free(&temp_type); - MPI_DDT_DUMP( struct_type ); + MPI_DDT_DUMP(struct_type); return struct_type; } /* Create a datatype similar to the one use by HPL */ static MPI_Datatype -create_indexed_constant_gap_ddt( int number, /* number of repetitions */ - int contig_size, /* number of elements in a contiguous chunk */ - int gap_size ) /* number of elements in a gap */ +create_indexed_constant_gap_ddt(int number, /* number of repetitions */ + int contig_size, /* number of elements in a contiguous chunk */ + int gap_size) /* number of elements in a gap */ { MPI_Datatype dt, *types; int i, *bLength; - MPI_Aint* displ; + MPI_Aint *displ; - types = (MPI_Datatype*)malloc( sizeof(MPI_Datatype) * number ); - bLength = (int*)malloc( sizeof(int) * number ); - displ = (MPI_Aint*)malloc( sizeof(MPI_Aint) * number ); + types = (MPI_Datatype *) malloc(sizeof(MPI_Datatype) * number); + bLength = (int *) malloc(sizeof(int) * number); + displ = (MPI_Aint *) malloc(sizeof(MPI_Aint) * number); types[0] = MPI_DOUBLE; bLength[0] = contig_size; displ[0] = 0; - for( i = 1; i < number; i++ ) { + for (i = 1; i < number; i++) { types[i] = MPI_DOUBLE; bLength[i] = contig_size; - displ[i] = displ[i-1] + sizeof(double) * (contig_size + gap_size); + displ[i] = displ[i - 1] + sizeof(double) * (contig_size + gap_size); } - MPI_Type_create_struct( number, bLength, displ, types, &dt ); - MPI_DDT_DUMP( dt ); + MPI_Type_create_struct(number, bLength, displ, types, &dt); + MPI_DDT_DUMP(dt); free(types); free(bLength); free(displ); - MPI_Type_commit( &dt ); + MPI_Type_commit(&dt); return dt; } -static MPI_Datatype -create_optimized_indexed_constant_gap_ddt( int number, /* number of repetitions */ - int contig_size, /* number of elements in a contiguous chunk */ - int gap_size ) /* number of elements in a gap */ +static MPI_Datatype create_optimized_indexed_constant_gap_ddt( + int number, /* number of repetitions */ + int contig_size, /* number of elements in a contiguous chunk */ + int gap_size) /* number of elements in a gap */ { MPI_Datatype dt; - MPI_Type_vector( number, contig_size, (contig_size + gap_size), MPI_DOUBLE, &dt ); - MPI_Type_commit( &dt ); - MPI_DDT_DUMP( dt ); + MPI_Type_vector(number, contig_size, (contig_size + gap_size), MPI_DOUBLE, &dt); + MPI_Type_commit(&dt); + MPI_DDT_DUMP(dt); return dt; } typedef struct { - int i[2]; - float f; + int i[2]; + float f; } internal_struct; typedef struct { - int v1; - int gap1; - internal_struct is[3]; + int v1; + int gap1; + internal_struct is[3]; } ddt_gap; -static MPI_Datatype -create_indexed_gap_ddt( void ) +static MPI_Datatype create_indexed_gap_ddt(void) { ddt_gap dt[2]; MPI_Datatype dt1, dt2, dt3; - int bLength[2] = { 2, 1 }; - MPI_Datatype types[2] = { MPI_INT, MPI_FLOAT }; + int bLength[2] = {2, 1}; + MPI_Datatype types[2] = {MPI_INT, MPI_FLOAT}; MPI_Aint displ[2]; - MPI_Get_address( &(dt[0].is[0].i[0]), &(displ[0]) ); - MPI_Get_address( &(dt[0].is[0].f), &(displ[1]) ); + MPI_Get_address(&(dt[0].is[0].i[0]), &(displ[0])); + MPI_Get_address(&(dt[0].is[0].f), &(displ[1])); displ[1] -= displ[0]; displ[0] -= displ[0]; - MPI_Type_create_struct( 2, bLength, displ, types, &dt1 ); + MPI_Type_create_struct(2, bLength, displ, types, &dt1); /*MPI_DDT_DUMP( dt1 );*/ - MPI_Type_contiguous( 3, dt1, &dt2 ); + MPI_Type_contiguous(3, dt1, &dt2); /*MPI_DDT_DUMP( dt2 );*/ bLength[0] = 1; bLength[1] = 1; - MPI_Get_address( &(dt[0].v1), &(displ[0]) ); - MPI_Get_address( &(dt[0].is[0]), &(displ[1]) ); + MPI_Get_address(&(dt[0].v1), &(displ[0])); + MPI_Get_address(&(dt[0].is[0]), &(displ[1])); displ[1] -= displ[0]; displ[0] -= displ[0]; types[0] = MPI_INT; types[1] = dt2; - MPI_Type_create_struct( 2, bLength, displ, types, &dt3 ); + MPI_Type_create_struct(2, bLength, displ, types, &dt3); /*MPI_DDT_DUMP( dt3 );*/ - MPI_Type_free( &dt1 ); - MPI_Type_free( &dt2 ); - MPI_Type_contiguous( 10, dt3, &dt1 ); - MPI_DDT_DUMP( dt1 ); - MPI_Type_free( &dt3 ); - MPI_Type_commit( &dt1 ); + MPI_Type_free(&dt1); + MPI_Type_free(&dt2); + MPI_Type_contiguous(10, dt3, &dt1); + MPI_DDT_DUMP(dt1); + MPI_Type_free(&dt3); + MPI_Type_commit(&dt1); return dt1; } -static MPI_Datatype -create_indexed_gap_optimized_ddt( void ) +static MPI_Datatype create_indexed_gap_optimized_ddt(void) { MPI_Datatype dt1, dt2, dt3; int bLength[3]; MPI_Datatype types[3]; MPI_Aint displ[3]; - MPI_Type_contiguous( 40, MPI_BYTE, &dt1 ); - MPI_Type_create_resized( dt1, 0, 44, &dt2 ); + MPI_Type_contiguous(40, MPI_BYTE, &dt1); + MPI_Type_create_resized(dt1, 0, 44, &dt2); bLength[0] = 4; bLength[1] = 9; @@ -190,16 +185,15 @@ create_indexed_gap_optimized_ddt( void ) displ[1] = 8; displ[2] = 44 * 9 + 8; - MPI_Type_create_struct( 3, bLength, displ, types, &dt3 ); + MPI_Type_create_struct(3, bLength, displ, types, &dt3); - MPI_Type_free( &dt1 ); - MPI_Type_free( &dt2 ); - MPI_DDT_DUMP( dt3 ); - MPI_Type_commit( &dt3 ); + MPI_Type_free(&dt1); + MPI_Type_free(&dt2); + MPI_DDT_DUMP(dt3); + MPI_Type_commit(&dt3); return dt3; } - /******************************************************************** *******************************************************************/ @@ -210,370 +204,365 @@ create_indexed_gap_optimized_ddt( void ) #define DO_STRUCT_CONSTANT_GAP_RESIZED 0x00000010 #define DO_STRUCT_MERGED_WITH_GAP_RESIZED 0x00000020 -#define DO_PACK 0x01000000 -#define DO_UNPACK 0x02000000 -#define DO_ISEND_RECV 0x04000000 -#define DO_ISEND_IRECV 0x08000000 -#define DO_IRECV_SEND 0x10000000 -#define DO_IRECV_ISEND 0x20000000 +#define DO_PACK 0x01000000 +#define DO_UNPACK 0x02000000 +#define DO_ISEND_RECV 0x04000000 +#define DO_ISEND_IRECV 0x08000000 +#define DO_IRECV_SEND 0x10000000 +#define DO_IRECV_ISEND 0x20000000 -#define MIN_LENGTH 1024 -#define MAX_LENGTH (1024*1024) +#define MIN_LENGTH 1024 +#define MAX_LENGTH (1024 * 1024) -static int cycles = 100; -static int trials = 20; +static int cycles = 100; +static int trials = 20; static int warmups = 2; -static void print_result( int length, int trials, double* timers ) +static void print_result(int length, int trials, double *timers) { double bandwidth, clock_prec, temp; double min_time, max_time, average, std_dev = 0.0; double ordered[trials]; int t, pos, quartile_start, quartile_end; - for( t = 0; t < trials; ordered[t] = timers[t], t++ ); - for( t = 0; t < trials-1; t++ ) { + for (t = 0; t < trials; ordered[t] = timers[t], t++) + ; + for (t = 0; t < trials - 1; t++) { temp = ordered[t]; pos = t; - for( int i = t+1; i < trials; i++ ) { - if( temp > ordered[i] ) { + for (int i = t + 1; i < trials; i++) { + if (temp > ordered[i]) { temp = ordered[i]; pos = i; } } - if( pos != t ) { + if (pos != t) { temp = ordered[t]; ordered[t] = ordered[pos]; ordered[pos] = temp; } } quartile_start = trials - (3 * trials) / 4; - quartile_end = trials - (1 * trials) / 4; + quartile_end = trials - (1 * trials) / 4; clock_prec = MPI_Wtick(); min_time = ordered[quartile_start]; max_time = ordered[quartile_start]; average = ordered[quartile_start]; - for( t = quartile_start + 1; t < quartile_end; t++ ) { - if( min_time > ordered[t] ) min_time = ordered[t]; - if( max_time < ordered[t] ) max_time = ordered[t]; + for (t = quartile_start + 1; t < quartile_end; t++) { + if (min_time > ordered[t]) + min_time = ordered[t]; + if (max_time < ordered[t]) + max_time = ordered[t]; average += ordered[t]; } average /= (quartile_end - quartile_start); - for( t = quartile_start; t < quartile_end; t++ ) { + for (t = quartile_start; t < quartile_end; t++) { std_dev += (ordered[t] - average) * (ordered[t] - average); } - std_dev = sqrt( std_dev/(quartile_end - quartile_start) ); - + std_dev = sqrt(std_dev / (quartile_end - quartile_start)); + bandwidth = (length * clock_prec) / (1024.0 * 1024.0) / (average * clock_prec); - printf( "%8d\t%15g\t%10.4f MB/s [min %10g max %10g std %2.2f%%]\n", length, average, bandwidth, - min_time, max_time, (100.0 * std_dev) / average ); + printf("%8d\t%15g\t%10.4f MB/s [min %10g max %10g std %2.2f%%]\n", length, average, bandwidth, + min_time, max_time, (100.0 * std_dev) / average); } -static int pack( int cycles, - MPI_Datatype sdt, int scount, void* sbuf, - void* packed_buf ) +static int pack(int cycles, MPI_Datatype sdt, int scount, void *sbuf, void *packed_buf) { int position, myself, c, t, outsize; double timers[trials]; - MPI_Type_size( sdt, &outsize ); + MPI_Type_size(sdt, &outsize); outsize *= scount; - MPI_Comm_rank( MPI_COMM_WORLD, &myself ); + MPI_Comm_rank(MPI_COMM_WORLD, &myself); - for( t = 0; t < warmups; t++ ) { - for( c = 0; c < cycles; c++ ) { + for (t = 0; t < warmups; t++) { + for (c = 0; c < cycles; c++) { position = 0; MPI_Pack(sbuf, scount, sdt, packed_buf, outsize, &position, MPI_COMM_WORLD); } } - - for( t = 0; t < trials; t++ ) { + + for (t = 0; t < trials; t++) { timers[t] = MPI_Wtime(); - for( c = 0; c < cycles; c++ ) { + for (c = 0; c < cycles; c++) { position = 0; MPI_Pack(sbuf, scount, sdt, packed_buf, outsize, &position, MPI_COMM_WORLD); } timers[t] = (MPI_Wtime() - timers[t]) / cycles; } - print_result( outsize, trials, timers ); + print_result(outsize, trials, timers); return 0; } -static int unpack( int cycles, - void* packed_buf, - MPI_Datatype rdt, int rcount, void* rbuf ) +static int unpack(int cycles, void *packed_buf, MPI_Datatype rdt, int rcount, void *rbuf) { int position, myself, c, t, insize; double timers[trials]; - MPI_Type_size( rdt, &insize ); + MPI_Type_size(rdt, &insize); insize *= rcount; - MPI_Comm_rank( MPI_COMM_WORLD, &myself ); + MPI_Comm_rank(MPI_COMM_WORLD, &myself); - for( t = 0; t < warmups; t++ ) { - for( c = 0; c < cycles; c++ ) { + for (t = 0; t < warmups; t++) { + for (c = 0; c < cycles; c++) { position = 0; MPI_Unpack(packed_buf, insize, &position, rbuf, rcount, rdt, MPI_COMM_WORLD); } } - for( t = 0; t < trials; t++ ) { + for (t = 0; t < trials; t++) { timers[t] = MPI_Wtime(); - for( c = 0; c < cycles; c++ ) { + for (c = 0; c < cycles; c++) { position = 0; MPI_Unpack(packed_buf, insize, &position, rbuf, rcount, rdt, MPI_COMM_WORLD); } timers[t] = (MPI_Wtime() - timers[t]) / cycles; } - print_result( insize, trials, timers ); + print_result(insize, trials, timers); return 0; } -static int isend_recv( int cycles, - MPI_Datatype sdt, int scount, void* sbuf, - MPI_Datatype rdt, int rcount, void* rbuf ) +static int isend_recv(int cycles, MPI_Datatype sdt, int scount, void *sbuf, MPI_Datatype rdt, + int rcount, void *rbuf) { int myself, tag = 0, c, t, slength, rlength; MPI_Status status; MPI_Request req; double timers[trials]; - MPI_Type_size( sdt, &slength ); + MPI_Type_size(sdt, &slength); slength *= scount; - MPI_Type_size( rdt, &rlength ); + MPI_Type_size(rdt, &rlength); rlength *= rcount; - MPI_Comm_rank( MPI_COMM_WORLD, &myself ); + MPI_Comm_rank(MPI_COMM_WORLD, &myself); - for( t = 0; t < trials; t++ ) { + for (t = 0; t < trials; t++) { timers[t] = MPI_Wtime(); - for( c = 0; c < cycles; c++ ) { - MPI_Isend( sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD, &req ); - MPI_Recv( rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &status ); - MPI_Wait( &req, &status ); + for (c = 0; c < cycles; c++) { + MPI_Isend(sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD, &req); + MPI_Recv(rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &status); + MPI_Wait(&req, &status); } timers[t] = (MPI_Wtime() - timers[t]) / cycles; } - print_result( rlength, trials, timers ); + print_result(rlength, trials, timers); return 0; } -static int irecv_send( int cycles, - MPI_Datatype sdt, int scount, void* sbuf, - MPI_Datatype rdt, int rcount, void* rbuf ) +static int irecv_send(int cycles, MPI_Datatype sdt, int scount, void *sbuf, MPI_Datatype rdt, + int rcount, void *rbuf) { int myself, tag = 0, c, t, slength, rlength; MPI_Request req; MPI_Status status; double timers[trials]; - MPI_Type_size( sdt, &slength ); + MPI_Type_size(sdt, &slength); slength *= scount; - MPI_Type_size( rdt, &rlength ); + MPI_Type_size(rdt, &rlength); rlength *= rcount; - MPI_Comm_rank( MPI_COMM_WORLD, &myself ); + MPI_Comm_rank(MPI_COMM_WORLD, &myself); - for( t = 0; t < trials; t++ ) { + for (t = 0; t < trials; t++) { timers[t] = MPI_Wtime(); - for( c = 0; c < cycles; c++ ) { - MPI_Irecv( rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &req ); - MPI_Send( sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD ); - MPI_Wait( &req, &status ); + for (c = 0; c < cycles; c++) { + MPI_Irecv(rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &req); + MPI_Send(sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD); + MPI_Wait(&req, &status); } timers[t] = (MPI_Wtime() - timers[t]) / cycles; } - print_result( rlength, trials, timers ); + print_result(rlength, trials, timers); return 0; } -static int isend_irecv_wait( int cycles, - MPI_Datatype sdt, int scount, void* sbuf, - MPI_Datatype rdt, int rcount, void* rbuf ) +static int isend_irecv_wait(int cycles, MPI_Datatype sdt, int scount, void *sbuf, MPI_Datatype rdt, + int rcount, void *rbuf) { int myself, tag = 0, c, t, slength, rlength; MPI_Request requests[2]; MPI_Status statuses[2]; double timers[trials]; - MPI_Type_size( sdt, &slength ); + MPI_Type_size(sdt, &slength); slength *= scount; - MPI_Type_size( rdt, &rlength ); + MPI_Type_size(rdt, &rlength); rlength *= rcount; - MPI_Comm_rank( MPI_COMM_WORLD, &myself ); + MPI_Comm_rank(MPI_COMM_WORLD, &myself); - for( t = 0; t < trials; t++ ) { + for (t = 0; t < trials; t++) { timers[t] = MPI_Wtime(); - for( c = 0; c < cycles; c++ ) { - MPI_Isend( sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD, &requests[0] ); - MPI_Irecv( rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &requests[1] ); - MPI_Waitall( 2, requests, statuses ); + for (c = 0; c < cycles; c++) { + MPI_Isend(sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD, &requests[0]); + MPI_Irecv(rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &requests[1]); + MPI_Waitall(2, requests, statuses); } timers[t] = (MPI_Wtime() - timers[t]) / cycles; } - print_result( rlength, trials, timers ); + print_result(rlength, trials, timers); return 0; } -static int irecv_isend_wait( int cycles, - MPI_Datatype sdt, int scount, void* sbuf, - MPI_Datatype rdt, int rcount, void* rbuf ) +static int irecv_isend_wait(int cycles, MPI_Datatype sdt, int scount, void *sbuf, MPI_Datatype rdt, + int rcount, void *rbuf) { int myself, tag = 0, c, t, slength, rlength; MPI_Request requests[2]; MPI_Status statuses[2]; double timers[trials]; - MPI_Type_size( sdt, &slength ); + MPI_Type_size(sdt, &slength); slength *= scount; - MPI_Type_size( rdt, &rlength ); + MPI_Type_size(rdt, &rlength); rlength *= rcount; - MPI_Comm_rank( MPI_COMM_WORLD, &myself ); + MPI_Comm_rank(MPI_COMM_WORLD, &myself); - for( t = 0; t < trials; t++ ) { + for (t = 0; t < trials; t++) { timers[t] = MPI_Wtime(); - for( c = 0; c < cycles; c++ ) { - MPI_Irecv( rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &requests[0] ); - MPI_Isend( sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD, &requests[1] ); - MPI_Waitall( 2, requests, statuses ); + for (c = 0; c < cycles; c++) { + MPI_Irecv(rbuf, rcount, rdt, myself, tag, MPI_COMM_WORLD, &requests[0]); + MPI_Isend(sbuf, scount, sdt, myself, tag, MPI_COMM_WORLD, &requests[1]); + MPI_Waitall(2, requests, statuses); } timers[t] = (MPI_Wtime() - timers[t]) / cycles; } - print_result( rlength, trials, timers); + print_result(rlength, trials, timers); return 0; } -static int do_test_for_ddt( int doop, MPI_Datatype sddt, MPI_Datatype rddt, int length ) +static int do_test_for_ddt(int doop, MPI_Datatype sddt, MPI_Datatype rddt, int length) { MPI_Aint lb, extent; char *sbuf, *rbuf; int i; - MPI_Type_get_extent( sddt, &lb, &extent ); - sbuf = (char*)malloc( length ); - rbuf = (char*)malloc( length ); - if( doop & DO_PACK ) { + MPI_Type_get_extent(sddt, &lb, &extent); + sbuf = (char *) malloc(length); + rbuf = (char *) malloc(length); + if (doop & DO_PACK) { printf("# Pack (max length %d)\n", length); - for( i = 1; i <= (length/extent); i *= 2 ) { - pack( cycles, sddt, i, sbuf, rbuf ); + for (i = 1; i <= (length / extent); i *= 2) { + pack(cycles, sddt, i, sbuf, rbuf); } } - if( doop & DO_UNPACK ) { + if (doop & DO_UNPACK) { printf("# Unpack (length %d)\n", length); - for( i = 1; i <= (length/extent); i *= 2 ) { - unpack( cycles, sbuf, rddt, i, rbuf ); + for (i = 1; i <= (length / extent); i *= 2) { + unpack(cycles, sbuf, rddt, i, rbuf); } } - if( doop & DO_ISEND_RECV ) { - printf( "# Isend recv (length %d)\n", length ); - for( i = 1; i <= (length/extent); i *= 2 ) { - isend_recv( cycles, sddt, i, sbuf, rddt, i, rbuf ); + if (doop & DO_ISEND_RECV) { + printf("# Isend recv (length %d)\n", length); + for (i = 1; i <= (length / extent); i *= 2) { + isend_recv(cycles, sddt, i, sbuf, rddt, i, rbuf); } } - if( doop & DO_ISEND_IRECV ) { - printf( "# Isend Irecv Wait (length %d)\n", length ); - for( i = 1; i <= (length/extent); i *= 2 ) { - isend_irecv_wait( cycles, sddt, i, sbuf, rddt, i, rbuf ); + if (doop & DO_ISEND_IRECV) { + printf("# Isend Irecv Wait (length %d)\n", length); + for (i = 1; i <= (length / extent); i *= 2) { + isend_irecv_wait(cycles, sddt, i, sbuf, rddt, i, rbuf); } } - if( doop & DO_IRECV_SEND ) { - printf( "# Irecv send (length %d)\n", length ); - for( i = 1; i <= (length/extent); i *= 2 ) { - irecv_send( cycles, sddt, i, sbuf, rddt, i, rbuf ); + if (doop & DO_IRECV_SEND) { + printf("# Irecv send (length %d)\n", length); + for (i = 1; i <= (length / extent); i *= 2) { + irecv_send(cycles, sddt, i, sbuf, rddt, i, rbuf); } } - if( doop & DO_IRECV_SEND ) { - printf( "# Irecv Isend Wait (length %d)\n", length ); - for( i = 1; i <= (length/extent); i *= 2 ) { - irecv_isend_wait( cycles, sddt, i, sbuf, rddt, i, rbuf ); + if (doop & DO_IRECV_SEND) { + printf("# Irecv Isend Wait (length %d)\n", length); + for (i = 1; i <= (length / extent); i *= 2) { + irecv_isend_wait(cycles, sddt, i, sbuf, rddt, i, rbuf); } } - free( sbuf ); - free( rbuf ); + free(sbuf); + free(rbuf); return 0; } -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { - int run_tests = 0xffff; /* do all datatype tests by default */ + int run_tests = 0xffff; /* do all datatype tests by default */ int rank, size; MPI_Datatype ddt; run_tests |= DO_PACK | DO_UNPACK; - - MPI_Init (&argc, &argv); - MPI_Comm_rank (MPI_COMM_WORLD, &rank); - MPI_Comm_size (MPI_COMM_WORLD, &size); + MPI_Init(&argc, &argv); + + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); - if( rank != 0 ) { + if (rank != 0) { MPI_Finalize(); exit(0); } - if( run_tests & DO_CONTIG ) { - printf( "\ncontiguous datatype\n\n" ); - do_test_for_ddt( run_tests, MPI_INT, MPI_INT, MAX_LENGTH ); + if (run_tests & DO_CONTIG) { + printf("\ncontiguous datatype\n\n"); + do_test_for_ddt(run_tests, MPI_INT, MPI_INT, MAX_LENGTH); } - if( run_tests & DO_INDEXED_GAP ) { - printf( "\nindexed gap\n\n" ); + if (run_tests & DO_INDEXED_GAP) { + printf("\nindexed gap\n\n"); ddt = create_indexed_gap_ddt(); - MPI_DDT_DUMP( ddt ); - do_test_for_ddt( run_tests, ddt, ddt, MAX_LENGTH ); - MPI_Type_free( &ddt ); + MPI_DDT_DUMP(ddt); + do_test_for_ddt(run_tests, ddt, ddt, MAX_LENGTH); + MPI_Type_free(&ddt); } - if( run_tests & DO_OPTIMIZED_INDEXED_GAP ) { - printf( "\noptimized indexed gap\n\n" ); + if (run_tests & DO_OPTIMIZED_INDEXED_GAP) { + printf("\noptimized indexed gap\n\n"); ddt = create_indexed_gap_optimized_ddt(); - MPI_DDT_DUMP( ddt ); - do_test_for_ddt( run_tests, ddt, ddt, MAX_LENGTH ); - MPI_Type_free( &ddt ); + MPI_DDT_DUMP(ddt); + do_test_for_ddt(run_tests, ddt, ddt, MAX_LENGTH); + MPI_Type_free(&ddt); } - if( run_tests & DO_CONSTANT_GAP ) { - printf( "\nconstant indexed gap\n\n" ); - ddt = create_indexed_constant_gap_ddt( 80, 100, 1 ); - MPI_DDT_DUMP( ddt ); - do_test_for_ddt( run_tests, ddt, ddt, MAX_LENGTH ); - MPI_Type_free( &ddt ); + if (run_tests & DO_CONSTANT_GAP) { + printf("\nconstant indexed gap\n\n"); + ddt = create_indexed_constant_gap_ddt(80, 100, 1); + MPI_DDT_DUMP(ddt); + do_test_for_ddt(run_tests, ddt, ddt, MAX_LENGTH); + MPI_Type_free(&ddt); } - if( run_tests & DO_CONSTANT_GAP ) { - printf( "\noptimized constant indexed gap\n\n" ); - ddt = create_optimized_indexed_constant_gap_ddt( 80, 100, 1 ); - MPI_DDT_DUMP( ddt ); - do_test_for_ddt( run_tests, ddt, ddt, MAX_LENGTH ); - MPI_Type_free( &ddt ); + if (run_tests & DO_CONSTANT_GAP) { + printf("\noptimized constant indexed gap\n\n"); + ddt = create_optimized_indexed_constant_gap_ddt(80, 100, 1); + MPI_DDT_DUMP(ddt); + do_test_for_ddt(run_tests, ddt, ddt, MAX_LENGTH); + MPI_Type_free(&ddt); } - if( run_tests & DO_STRUCT_CONSTANT_GAP_RESIZED ) { - printf( "\nstruct constant gap resized\n\n" ); - ddt = create_struct_constant_gap_resized_ddt( 0 /* unused */, 0 /* unused */, 0 /* unused */ ); - MPI_DDT_DUMP( ddt ); - do_test_for_ddt( run_tests, ddt, ddt, MAX_LENGTH ); - MPI_Type_free( &ddt ); + if (run_tests & DO_STRUCT_CONSTANT_GAP_RESIZED) { + printf("\nstruct constant gap resized\n\n"); + ddt = create_struct_constant_gap_resized_ddt(0 /* unused */, 0 /* unused */, + 0 /* unused */); + MPI_DDT_DUMP(ddt); + do_test_for_ddt(run_tests, ddt, ddt, MAX_LENGTH); + MPI_Type_free(&ddt); } - if( run_tests & DO_STRUCT_MERGED_WITH_GAP_RESIZED ) { - printf( "\nstruct constant gap resized\n\n" ); - ddt = create_merged_contig_with_gaps( 1 ); - MPI_DDT_DUMP( ddt ); - do_test_for_ddt( run_tests, ddt, ddt, MAX_LENGTH ); - MPI_Type_free( &ddt ); + if (run_tests & DO_STRUCT_MERGED_WITH_GAP_RESIZED) { + printf("\nstruct constant gap resized\n\n"); + ddt = create_merged_contig_with_gaps(1); + MPI_DDT_DUMP(ddt); + do_test_for_ddt(run_tests, ddt, ddt, MAX_LENGTH); + MPI_Type_free(&ddt); } - MPI_Finalize (); + MPI_Finalize(); exit(0); } - diff --git a/test/datatype/unpack_hetero.c b/test/datatype/unpack_hetero.c index 49e31b006d..37d1b2cc62 100644 --- a/test/datatype/unpack_hetero.c +++ b/test/datatype/unpack_hetero.c @@ -10,22 +10,23 @@ */ #include "opal_config.h" -#include "opal/runtime/opal.h" +#include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype.h" #include "opal/datatype/opal_datatype_internal.h" -#include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype_prototypes.h" +#include "opal/runtime/opal.h" #include "opal/util/arch.h" -#include <time.h> #include <stdlib.h> +#include <time.h> #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #endif #include <stdio.h> #include <string.h> /* Compile with: -gcc -DHAVE_CONFIG_H -I. -I../../include -I../.. -I../../include -I../../../ompi-trunk/opal -I../../../ompi-trunk/orte -g opal_datatype_test.c -o opal_datatype_test +gcc -DHAVE_CONFIG_H -I. -I../../include -I../.. -I../../include -I../../../ompi-trunk/opal +-I../../../ompi-trunk/orte -g opal_datatype_test.c -o opal_datatype_test */ uint32_t remote_arch = 0xffffffff; @@ -37,63 +38,65 @@ uint32_t remote_arch = 0xffffffff; * on the data-type engine should first pass all the tests from this file, before going into other * tests. */ -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { - opal_init_util (NULL, NULL); + opal_init_util(NULL, NULL); /** * By default simulate homogeneous architectures. */ remote_arch = opal_local_arch ^ OPAL_ARCH_ISBIGENDIAN; - opal_convertor_t * pConv; + opal_convertor_t *pConv; int sbuf[2], rbuf[2]; size_t max_data; struct iovec a; uint32_t iov_count; - sbuf[0] = 0x01000000; sbuf[1] = 0x02000000; + sbuf[0] = 0x01000000; + sbuf[1] = 0x02000000; - printf( "\n\n#\n * TEST UNPACKING 1 int out of 1\n#\n\n" ); + printf("\n\n#\n * TEST UNPACKING 1 int out of 1\n#\n\n"); - pConv = opal_convertor_create( remote_arch, 0 ); - rbuf[0] = -1; rbuf[1] = -1; - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &opal_datatype_int4, 1, rbuf ) ) { - printf( "Cannot attach the datatype to a convertor\n" ); + pConv = opal_convertor_create(remote_arch, 0); + rbuf[0] = -1; + rbuf[1] = -1; + if (OPAL_SUCCESS != opal_convertor_prepare_for_recv(pConv, &opal_datatype_int4, 1, rbuf)) { + printf("Cannot attach the datatype to a convertor\n"); return OPAL_ERROR; } - + a.iov_base = sbuf; a.iov_len = 4; iov_count = 1; max_data = 4; - opal_unpack_general( pConv, &a, &iov_count, &max_data ); + opal_unpack_general(pConv, &a, &iov_count, &max_data); assert(1 == rbuf[0]); assert(-1 == rbuf[1]); OBJ_RELEASE(pConv); - printf( "\n\n#\n * TEST UNPACKING 1 int out of 2\n#\n\n" ); - pConv = opal_convertor_create( remote_arch, 0 ); - rbuf[0] = -1; rbuf[1] = -1; - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &opal_datatype_int4, 2, rbuf ) ) { - printf( "Cannot attach the datatype to a convertor\n" ); + printf("\n\n#\n * TEST UNPACKING 1 int out of 2\n#\n\n"); + pConv = opal_convertor_create(remote_arch, 0); + rbuf[0] = -1; + rbuf[1] = -1; + if (OPAL_SUCCESS != opal_convertor_prepare_for_recv(pConv, &opal_datatype_int4, 2, rbuf)) { + printf("Cannot attach the datatype to a convertor\n"); return OPAL_ERROR; } - a.iov_base = sbuf; a.iov_len = 4; iov_count = 1; max_data = 4; - opal_unpack_general( pConv, &a, &iov_count, &max_data ); + opal_unpack_general(pConv, &a, &iov_count, &max_data); assert(1 == rbuf[0]); assert(-1 == rbuf[1]); OBJ_RELEASE(pConv); /* clean-ups all data allocations */ - opal_finalize_util (); + opal_finalize_util(); return OPAL_SUCCESS; } diff --git a/test/datatype/unpack_ooo.c b/test/datatype/unpack_ooo.c index febc78bc92..ac51eedecc 100644 --- a/test/datatype/unpack_ooo.c +++ b/test/datatype/unpack_ooo.c @@ -15,13 +15,13 @@ #include "ompi_config.h" #include "ompi/datatype/ompi_datatype.h" -#include "opal/runtime/opal.h" #include "opal/datatype/opal_convertor.h" #include "opal/datatype/opal_datatype_internal.h" -#include <time.h> -#include <stdlib.h> +#include "opal/runtime/opal.h" #include <stdio.h> +#include <stdlib.h> #include <string.h> +#include <time.h> #include <unistd.h> #define N 331 @@ -39,16 +39,18 @@ struct pfoo_t { double d[2]; } pfoo = {0}, *pbar = NULL; -static void print_hex(void* ptr, int count, char* epilog, char* prolog) +static void print_hex(void *ptr, int count, char *epilog, char *prolog) { - if ( NULL != epilog) fprintf(stderr, "%s", epilog); - for ( int i = 0; i < count; i++ ) { - fprintf(stderr, "%02x", (unsigned int)(((unsigned char*)ptr)[i])); + if (NULL != epilog) + fprintf(stderr, "%s", epilog); + for (int i = 0; i < count; i++) { + fprintf(stderr, "%02x", (unsigned int) (((unsigned char *) ptr)[i])); } - if (NULL != prolog) fprintf(stderr, "%s", prolog); + if (NULL != prolog) + fprintf(stderr, "%s", prolog); } -static void print_bar_pbar(struct foo_t* _bar, struct pfoo_t* _pbar) +static void print_bar_pbar(struct foo_t *_bar, struct pfoo_t *_pbar) { print_hex(&_bar->i[0], sizeof(int), NULL, " "); print_hex(&_bar->i[1], sizeof(int), "[", "] "); @@ -63,31 +65,32 @@ static void print_bar_pbar(struct foo_t* _bar, struct pfoo_t* _pbar) print_hex(&_pbar->d[1], sizeof(double), NULL, "\n"); } -static void print_stack(opal_convertor_t* conv) +static void print_stack(opal_convertor_t *conv) { - printf("Stack pos %d [converted %" PRIsize_t "/%" PRIsize_t "]\n", - conv->stack_pos, conv->bConverted, conv->local_size); - for( uint32_t i = 0; i <= conv->stack_pos; i++ ) { - printf( "[%u] index %d, type %s count %" PRIsize_t " disp %p\n", - i, conv->pStack[i].index, opal_datatype_basicDatatypes[conv->pStack[i].type]->name, - conv->pStack[i].count, (void*)conv->pStack[i].disp); + printf("Stack pos %d [converted %" PRIsize_t "/%" PRIsize_t "]\n", conv->stack_pos, + conv->bConverted, conv->local_size); + for (uint32_t i = 0; i <= conv->stack_pos; i++) { + printf("[%u] index %d, type %s count %" PRIsize_t " disp %p\n", i, conv->pStack[i].index, + opal_datatype_basicDatatypes[conv->pStack[i].type]->name, conv->pStack[i].count, + (void *) conv->pStack[i].disp); } printf("\n"); } -static int testcase(ompi_datatype_t * newtype, size_t arr[][2]) { +static int testcase(ompi_datatype_t *newtype, size_t arr[][2]) +{ int i, j, errors = 0; struct iovec a; unsigned int iov_count; size_t max_data; size_t pos; - opal_convertor_t * pConv; + opal_convertor_t *pConv; for (j = 0; j < N; ++j) { - pbar[j].i[0] = 123+j; - pbar[j].i[1] = 789+j; - pbar[j].d[0] = 123.456+j; - pbar[j].d[1] = 789.123+j; + pbar[j].i[0] = 123 + j; + pbar[j].i[1] = 789 + j; + pbar[j].d[0] = 123.456 + j; + pbar[j].d[1] = 789.123 + j; memset(&bar[j].i[0], 0xFF, sizeof(int)); memset(&bar[j].i[2], 0xFF, sizeof(int)); bar[j].i[1] = 0; @@ -96,23 +99,23 @@ static int testcase(ompi_datatype_t * newtype, size_t arr[][2]) { bar[j].d[1] = 0.0; } - pConv = opal_convertor_create( remote_arch, 0 ); - if( OPAL_SUCCESS != opal_convertor_prepare_for_recv( pConv, &(newtype->super), N, bar ) ) { - printf( "Cannot attach the datatype to a convertor\n" ); + pConv = opal_convertor_create(remote_arch, 0); + if (OPAL_SUCCESS != opal_convertor_prepare_for_recv(pConv, &(newtype->super), N, bar)) { + printf("Cannot attach the datatype to a convertor\n"); return OMPI_ERROR; } - for ( i = 0; 0 != arr[i][0]; i++) { + for (i = 0; 0 != arr[i][0]; i++) { /* add some garbage before and after the source data */ - a.iov_base = malloc(arr[i][0]+2048); + a.iov_base = malloc(arr[i][0] + 2048); if (NULL == a.iov_base) { printf("cannot malloc iov_base\n"); return 1; } memset(a.iov_base, 0xAA, 1024); - memcpy((char*)a.iov_base+1024, (char *)pbar + arr[i][1], arr[i][0]); - memset((char*)a.iov_base+1024+arr[i][0], 0xAA, 1024); - a.iov_base = (char*)a.iov_base + 1024; + memcpy((char *) a.iov_base + 1024, (char *) pbar + arr[i][1], arr[i][0]); + memset((char *) a.iov_base + 1024 + arr[i][0], 0xAA, 1024); + a.iov_base = (char *) a.iov_base + 1024; a.iov_len = arr[i][0]; iov_count = 1; max_data = a.iov_len; @@ -120,76 +123,66 @@ static int testcase(ompi_datatype_t * newtype, size_t arr[][2]) { opal_convertor_set_position(pConv, &pos); print_stack(pConv); assert(arr[i][1] == pos); - opal_convertor_unpack( pConv, &a, &iov_count, &max_data ); - a.iov_base = (char*)a.iov_base - 1024; + opal_convertor_unpack(pConv, &a, &iov_count, &max_data); + a.iov_base = (char *) a.iov_base - 1024; free(a.iov_base); } for (j = 0; j < N; ++j) { - if (bar[j].i[0] != pbar[j].i[0] || - bar[j].i[1] != 0 || - bar[j].i[2] != pbar[j].i[1] || - bar[j].d[0] != pbar[j].d[0] || - bar[j].d[1] != 0.0 || - bar[j].d[2] != pbar[j].d[1]) { - if(0 == errors || report_all_errors) { + if (bar[j].i[0] != pbar[j].i[0] || bar[j].i[1] != 0 || bar[j].i[2] != pbar[j].i[1] + || bar[j].d[0] != pbar[j].d[0] || bar[j].d[1] != 0.0 || bar[j].d[2] != pbar[j].d[1]) { + if (0 == errors || report_all_errors) { ptrdiff_t displ; - char* error_location = "in gaps"; + char *error_location = "in gaps"; if (bar[j].i[0] != pbar[j].i[0]) { - displ = (char*)&bar[j].i[0] - (char*)&bar[0]; + displ = (char *) &bar[j].i[0] - (char *) &bar[0]; error_location = "i[0]"; } else if (bar[j].i[2] != pbar[j].i[1]) { - displ = (char*)&bar[j].i[1] - (char*)&bar[0]; + displ = (char *) &bar[j].i[1] - (char *) &bar[0]; error_location = "i[2]"; } else if (bar[j].d[0] != pbar[j].d[0]) { - displ = (char*)&bar[j].d[0] - (char*)&bar[0]; + displ = (char *) &bar[j].d[0] - (char *) &bar[0]; error_location = "d[0]"; } else if (bar[j].d[2] != pbar[j].d[1]) { - displ = (char*)&bar[j].d[1] - (char*)&bar[0]; + displ = (char *) &bar[j].d[1] - (char *) &bar[0]; error_location = "d[2]"; } else { - displ = (char*)&bar[j] - (char*)&bar[0]; + displ = (char *) &bar[j] - (char *) &bar[0]; } for (i = 0; 0 != arr[i][0]; i++) { - if( (displ >= arr[i][1]) && (displ <= (arr[i][1] + arr[i][0])) ) { - fprintf(stderr, "Problem encountered %li bytes into the %d unpack [%"PRIsize_t":%"PRIsize_t"]\n", + if ((displ >= arr[i][1]) && (displ <= (arr[i][1] + arr[i][0]))) { + fprintf(stderr, + "Problem encountered %li bytes into the %d unpack [%" PRIsize_t + ":%" PRIsize_t "]\n", displ - arr[i][1], i, arr[i][1], arr[i][0]); break; } } - (void)opal_datatype_dump(&newtype->super); - fprintf(stderr, "ERROR ! struct %d/%d in field %s, ptr = %p" + (void) opal_datatype_dump(&newtype->super); + fprintf(stderr, + "ERROR ! struct %d/%d in field %s, ptr = %p" " got (%d,%d,%d,%g,%g,%g) expected (%d,%d,%d,%g,%g,%g)\n", - j, N, error_location, (void*)&bar[j], - bar[j].i[0], - bar[j].i[1], - bar[j].i[2], - bar[j].d[0], - bar[j].d[1], - bar[j].d[2], - pbar[j].i[0], - 0, - pbar[j].i[1], - pbar[j].d[0], - 0.0, - pbar[j].d[1]); + j, N, error_location, (void *) &bar[j], bar[j].i[0], bar[j].i[1], + bar[j].i[2], bar[j].d[0], bar[j].d[1], bar[j].d[2], pbar[j].i[0], 0, + pbar[j].i[1], pbar[j].d[0], 0.0, pbar[j].d[1]); print_bar_pbar(&bar[j], &pbar[j]); - if( report_all_errors ) fprintf(stderr, "\n\n"); + if (report_all_errors) + fprintf(stderr, "\n\n"); } errors++; } } - OBJ_RELEASE( pConv ); + OBJ_RELEASE(pConv); return errors; } static int unpack_ooo(void) { - ompi_datatype_t * t1; - ompi_datatype_t * t2; - ompi_datatype_t * type[2]; - ompi_datatype_t * newtype; + ompi_datatype_t *t1; + ompi_datatype_t *t2; + ompi_datatype_t *type[2]; + ompi_datatype_t *newtype; MPI_Aint disp[2]; int len[2], rc; @@ -198,7 +191,7 @@ static int unpack_ooo(void) fprintf(stderr, "could not create vector t1\n"); return 1; } - rc = ompi_datatype_commit (&t1); + rc = ompi_datatype_commit(&t1); if (OMPI_SUCCESS != rc) { fprintf(stderr, "could not commit vector t1\n"); return 1; @@ -209,22 +202,22 @@ static int unpack_ooo(void) fprintf(stderr, "could not create vector t2\n"); return 1; } - rc = ompi_datatype_commit (&t2); + rc = ompi_datatype_commit(&t2); if (OMPI_SUCCESS != rc) { fprintf(stderr, "could not commit vector t2\n"); return 1; } -/* - * btl=0x7f7823672580 bytes_received=992 data_offset=0 - * btl=0x7f7823260420 bytes_received=1325 data_offset=992 - * btl=0x7f7823672580 bytes_received=992 data_offset=2317 - * btl=0x7f7823672580 bytes_received=992 data_offset=3309 - * btl=0x7f7823672580 bytes_received=992 data_offset=4301 - * btl=0x7f7823672580 bytes_received=992 data_offset=5293 - * btl=0x7f7823672580 bytes_received=992 data_offset=6285 - * btl=0x7f7823672580 bytes_received=667 data_offset=7277 - */ + /* + * btl=0x7f7823672580 bytes_received=992 data_offset=0 + * btl=0x7f7823260420 bytes_received=1325 data_offset=992 + * btl=0x7f7823672580 bytes_received=992 data_offset=2317 + * btl=0x7f7823672580 bytes_received=992 data_offset=3309 + * btl=0x7f7823672580 bytes_received=992 data_offset=4301 + * btl=0x7f7823672580 bytes_received=992 data_offset=5293 + * btl=0x7f7823672580 bytes_received=992 data_offset=6285 + * btl=0x7f7823672580 bytes_received=667 data_offset=7277 + */ size_t test1[9][2] = { {992, 0}, {1325, 0 + 992}, @@ -237,49 +230,33 @@ static int unpack_ooo(void) {0, -1}, }; -/* - * btl=0x7f80bc545580 bytes_received=992 data_offset=0 - * btl=0x7f80bc545580 bytes_received=992 data_offset=2317 - * btl=0x7f80bc545580 bytes_received=992 data_offset=3309 - * btl=0x7f80bc545580 bytes_received=992 data_offset=4301 - * btl=0x7f80bc545580 bytes_received=992 data_offset=5293 - * btl=0x7f80bc545580 bytes_received=992 data_offset=6285 - * btl=0x7f80bc133420 bytes_received=1325 data_offset=992 - * btl=0x7f80bc545580 bytes_received=667 data_offset=7277 - */ + /* + * btl=0x7f80bc545580 bytes_received=992 data_offset=0 + * btl=0x7f80bc545580 bytes_received=992 data_offset=2317 + * btl=0x7f80bc545580 bytes_received=992 data_offset=3309 + * btl=0x7f80bc545580 bytes_received=992 data_offset=4301 + * btl=0x7f80bc545580 bytes_received=992 data_offset=5293 + * btl=0x7f80bc545580 bytes_received=992 data_offset=6285 + * btl=0x7f80bc133420 bytes_received=1325 data_offset=992 + * btl=0x7f80bc545580 bytes_received=667 data_offset=7277 + */ size_t test2[9][2] = { - {992, 0}, - {992, 2317}, - {992, 3309}, - {992, 4301}, - {992, 5293}, - {992, 6285}, - {1325, 992}, - {667, 7277}, - {0, -1}, + {992, 0}, {992, 2317}, {992, 3309}, {992, 4301}, {992, 5293}, + {992, 6285}, {1325, 992}, {667, 7277}, {0, -1}, }; -/* trimmed version of test2 */ + /* trimmed version of test2 */ size_t test3[9][2] = { - {992, 0}, - {4960, 2317}, - {1325, 992}, - {667, 7277}, - {0, -1}, + {992, 0}, {4960, 2317}, {1325, 992}, {667, 7277}, {0, -1}, }; -/* an other test case */ + /* an other test case */ size_t test4[9][2] = { - {992, 0}, - {992, 2976}, - {992, 1984}, - {992, 992}, - {3976, 3968}, - {0, -1}, + {992, 0}, {992, 2976}, {992, 1984}, {992, 992}, {3976, 3968}, {0, -1}, }; - disp[0] = (long)(&foo.i[0]) - (long)&foo; - disp[1] = (long)(&foo.d[0]) - (long)&foo; + disp[0] = (long) (&foo.i[0]) - (long) &foo; + disp[1] = (long) (&foo.d[0]) - (long) &foo; type[0] = t1; type[1] = t2; @@ -292,51 +269,51 @@ static int unpack_ooo(void) fprintf(stderr, "could not create struct\n"); return 1; } - rc = ompi_datatype_commit (&newtype); + rc = ompi_datatype_commit(&newtype); if (OMPI_SUCCESS != rc) { fprintf(stderr, "could not create struct\n"); return 1; } - pbar = (struct pfoo_t *)malloc (N * sizeof(struct pfoo_t)); + pbar = (struct pfoo_t *) malloc(N * sizeof(struct pfoo_t)); if (NULL == pbar) { fprintf(stderr, "could not malloc pbar\n"); return 1; } - bar = (struct foo_t *)malloc (N * sizeof(struct foo_t)); + bar = (struct foo_t *) malloc(N * sizeof(struct foo_t)); if (NULL == bar) { fprintf(stderr, "could not malloc bar\n"); return 1; } if (0 != testcase(newtype, test1)) { - printf ("test1 failed\n"); + printf("test1 failed\n"); return 2; } if (0 != testcase(newtype, test2)) { - printf ("test2 failed\n"); + printf("test2 failed\n"); return 2; } if (0 != testcase(newtype, test3)) { - printf ("test3 failed\n"); + printf("test3 failed\n"); return 2; } if (0 != testcase(newtype, test4)) { - printf ("test4 failed\n"); + printf("test4 failed\n"); return 2; } - /* test the automatic destruction pf the data */ - ompi_datatype_destroy( &newtype ); assert( newtype == NULL ); + ompi_datatype_destroy(&newtype); + assert(newtype == NULL); return rc; } -int main( int argc, char* argv[] ) +int main(int argc, char *argv[]) { int rc; @@ -347,12 +324,12 @@ int main( int argc, char* argv[] ) */ remote_arch = opal_local_arch; - printf( "\n\n#\n * TEST UNPACK OUT OF ORDER\n #\n\n" ); + printf("\n\n#\n * TEST UNPACK OUT OF ORDER\n #\n\n"); rc = unpack_ooo(); - if( rc == 0 ) { - printf( "unpack out of order [PASSED]\n" ); + if (rc == 0) { + printf("unpack out of order [PASSED]\n"); return 0; } - printf( "unpack out of order [NOT PASSED]\n" ); + printf("unpack out of order [NOT PASSED]\n"); return -1; } diff --git a/test/event/event-test.c b/test/event/event-test.c index 5701dfe2ab..672f767123 100644 --- a/test/event/event-test.c +++ b/test/event/event-test.c @@ -4,142 +4,138 @@ */ #ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> +# include <sys/types.h> #endif #include <sys/stat.h> #ifndef WIN32 -#ifdef HAVE_SYS_QUEUE_H -#include <sys/queue.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif +# ifdef HAVE_SYS_QUEUE_H +# include <sys/queue.h> +# endif +# ifdef HAVE_UNISTD_H +# include <unistd.h> +# endif +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# endif #else -#include <windows.h> +# include <windows.h> #endif +#include <errno.h> #include <fcntl.h> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <errno.h> #include <unistd.h> -#include "opal/util/event.h" #include "opal/runtime/opal.h" +#include "opal/util/event.h" -static void -fifo_read(int fd, short event, void *arg) +static void fifo_read(int fd, short event, void *arg) { - char buf[255]; - int len; - opal_event_t *ev = arg; + char buf[255]; + int len; + opal_event_t *ev = arg; #ifdef WIN32 - DWORD dwBytesRead; + DWORD dwBytesRead; #endif - /* Reschedule this event */ - opal_event.add(ev, NULL); + /* Reschedule this event */ + opal_event.add(ev, NULL); - fprintf(stderr, "fifo_read called with fd: %d, event: %d, arg: %p\n", - fd, event, arg); + fprintf(stderr, "fifo_read called with fd: %d, event: %d, arg: %p\n", fd, event, arg); #ifdef WIN32 - len = ReadFile((HANDLE)fd, buf, sizeof(buf) - 1, &dwBytesRead, NULL); + len = ReadFile((HANDLE) fd, buf, sizeof(buf) - 1, &dwBytesRead, NULL); - /* Check for end of file. */ - if(len && dwBytesRead == 0) { - fprintf(stderr, "End Of File"); - opal_event.del(ev); - return; - } + /* Check for end of file. */ + if (len && dwBytesRead == 0) { + fprintf(stderr, "End Of File"); + opal_event.del(ev); + return; + } - buf[dwBytesRead + 1] = '\0'; + buf[dwBytesRead + 1] = '\0'; #else - len = read(fd, buf, sizeof(buf) - 1); + len = read(fd, buf, sizeof(buf) - 1); - if (len == -1) { - perror("read"); - return; - } else if (len == 0) { - fprintf(stderr, "Connection closed\n"); - return; - } + if (len == -1) { + perror("read"); + return; + } else if (len == 0) { + fprintf(stderr, "Connection closed\n"); + return; + } - buf[len] = '\0'; + buf[len] = '\0'; #endif - fprintf(stdout, "Read: %s\n", buf); + fprintf(stdout, "Read: %s\n", buf); } -int -main (int argc, char **argv) +int main(int argc, char **argv) { - opal_event_t evfifo; + opal_event_t evfifo; #ifdef WIN32 - HANDLE socket; - // Open a file. - socket = CreateFile("test.txt", // open File - GENERIC_READ, // open for reading - 0, // do not share - NULL, // no security - OPEN_EXISTING, // existing file only - FILE_ATTRIBUTE_NORMAL, // normal file - NULL); // no attr. template - - if(socket == INVALID_HANDLE_VALUE) - return 1; + HANDLE socket; + // Open a file. + socket = CreateFile("test.txt", // open File + GENERIC_READ, // open for reading + 0, // do not share + NULL, // no security + OPEN_EXISTING, // existing file only + FILE_ATTRIBUTE_NORMAL, // normal file + NULL); // no attr. template + + if (socket == INVALID_HANDLE_VALUE) + return 1; #else - struct stat st; - char *fifo = "event.fifo"; - int socket; - - if (lstat (fifo, &st) == 0) { - if ((st.st_mode & S_IFMT) == S_IFREG) { - errno = EEXIST; - perror("lstat"); - exit (1); - } - } - - unlink (fifo); - if (mkfifo (fifo, 0600) == -1) { - perror("mkfifo"); - exit (1); - } - - /* Linux pipes are broken, we need O_RDWR instead of O_RDONLY */ -#ifdef __linux - socket = open (fifo, O_RDWR | O_NONBLOCK, 0); -#else - socket = open (fifo, O_RDONLY | O_NONBLOCK, 0); + struct stat st; + char *fifo = "event.fifo"; + int socket; + + if (lstat(fifo, &st) == 0) { + if ((st.st_mode & S_IFMT) == S_IFREG) { + errno = EEXIST; + perror("lstat"); + exit(1); + } + } + + unlink(fifo); + if (mkfifo(fifo, 0600) == -1) { + perror("mkfifo"); + exit(1); + } + + /* Linux pipes are broken, we need O_RDWR instead of O_RDONLY */ +# ifdef __linux + socket = open(fifo, O_RDWR | O_NONBLOCK, 0); +# else + socket = open(fifo, O_RDONLY | O_NONBLOCK, 0); +# endif + + if (socket == -1) { + perror("open"); + exit(1); + } + + fprintf(stderr, "Write data to %s\n", fifo); #endif + /* Initialize the event library */ + opal_init(); - if (socket == -1) { - perror("open"); - exit (1); - } - - fprintf(stderr, "Write data to %s\n", fifo); -#endif - /* Initialize the event library */ - opal_init(); - - /* Initialize one event */ + /* Initialize one event */ #ifdef WIN32 - opal_event.set(opal_event_base, &evfifo, (int)socket, OPAL_EV_READ, fifo_read, &evfifo); + opal_event.set(opal_event_base, &evfifo, (int) socket, OPAL_EV_READ, fifo_read, &evfifo); #else - opal_event.set(opal_event_base, &evfifo, socket, OPAL_EV_READ, fifo_read, &evfifo); + opal_event.set(opal_event_base, &evfifo, socket, OPAL_EV_READ, fifo_read, &evfifo); #endif - /* Add it to the active events, without a timeout */ - opal_event.add(&evfifo, NULL); + /* Add it to the active events, without a timeout */ + opal_event.add(&evfifo, NULL); - opal_event.dispatch(opal_event_base); + opal_event.dispatch(opal_event_base); #ifdef WIN32 - CloseHandle(socket); + CloseHandle(socket); #endif - return (0); + return (0); } - diff --git a/test/event/signal-test.c b/test/event/signal-test.c index e16be7e991..a3ced9a09f 100644 --- a/test/event/signal-test.c +++ b/test/event/signal-test.c @@ -4,66 +4,63 @@ */ #ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> +# include <sys/types.h> #endif #include <sys/stat.h> #ifndef WIN32 -#ifdef HAVE_SYS_QUEUE_H -#include <sys/queue.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#endif +# ifdef HAVE_SYS_QUEUE_H +# include <sys/queue.h> +# endif +# ifdef HAVE_UNISTD_H +# include <unistd.h> +# endif +# ifdef HAVE_SYS_TIME_H +# include <sys/time.h> +# endif #else -#include <windows.h> +# include <windows.h> #endif -#include <signal.h> +#include <errno.h> #include <fcntl.h> -#include <stdlib.h> +#include <signal.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <errno.h> -#include "opal/util/event.h" #include "opal/runtime/opal.h" +#include "opal/util/event.h" int called = 0; -void -signal_cb(int fd, short event, void *arg) +void signal_cb(int fd, short event, void *arg) { - opal_event_t *signal = arg; + opal_event_t *signal = arg; - printf("%s: got signal %d\n", __func__, OPAL_EVENT_SIGNAL(signal)); + printf("%s: got signal %d\n", __func__, OPAL_EVENT_SIGNAL(signal)); - if (called >= 2) - opal_event.del(signal); + if (called >= 2) + opal_event.del(signal); - called++; + called++; } -int -main (int argc, char **argv) +int main(int argc, char **argv) { opal_event_t signal_int, signal_term; - /* Initialize the event library */ - opal_init(); + /* Initialize the event library */ + opal_init(); - /* Initialize one event */ - opal_event.set(opal_event_base, &signal_term, SIGUSR1, OPAL_EV_SIGNAL|OPAL_EV_PERSIST, signal_cb, - &signal_term); - opal_event.set(opal_event_base, &signal_int, SIGUSR2, OPAL_EV_SIGNAL|OPAL_EV_PERSIST, signal_cb, - &signal_int); + /* Initialize one event */ + opal_event.set(opal_event_base, &signal_term, SIGUSR1, OPAL_EV_SIGNAL | OPAL_EV_PERSIST, + signal_cb, &signal_term); + opal_event.set(opal_event_base, &signal_int, SIGUSR2, OPAL_EV_SIGNAL | OPAL_EV_PERSIST, + signal_cb, &signal_int); - opal_event.add(&signal_int, NULL); - opal_event.add(&signal_term, NULL); + opal_event.add(&signal_int, NULL); + opal_event.add(&signal_term, NULL); - opal_event.dispatch(opal_event_base); + opal_event.dispatch(opal_event_base); - return (0); + return (0); } - diff --git a/test/event/time-test.c b/test/event/time-test.c index 9f8086ca7a..e12ef98b25 100644 --- a/test/event/time-test.c +++ b/test/event/time-test.c @@ -4,68 +4,64 @@ */ #ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> +# include <sys/types.h> #endif #include <sys/stat.h> #ifndef WIN32 -#ifdef HAVE_SYS_QUEUE_H -#include <sys/queue.h> -#endif -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif +# ifdef HAVE_SYS_QUEUE_H +# include <sys/queue.h> +# endif +# ifdef HAVE_UNISTD_H +# include <unistd.h> +# endif #else -#include <time.h> +# include <time.h> #endif #ifdef HAVE_SYS_TIME_H -#include <sys/time.h> +# include <sys/time.h> #endif +#include <errno.h> #include <fcntl.h> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <errno.h> #include "opal/event/event.h" int lasttime; -void -timeout_cb(int fd, short event, void *arg) +void timeout_cb(int fd, short event, void *arg) { - struct timeval tv; - opal_event_t *timeout = arg; - int newtime = time(NULL); + struct timeval tv; + opal_event_t *timeout = arg; + int newtime = time(NULL); - printf("%s: called at %d: %d\n", __func__, newtime, - newtime - lasttime); - lasttime = newtime; + printf("%s: called at %d: %d\n", __func__, newtime, newtime - lasttime); + lasttime = newtime; - timerclear(&tv); - tv.tv_sec = 2; - opal_event_add(timeout, &tv); + timerclear(&tv); + tv.tv_sec = 2; + opal_event_add(timeout, &tv); } -int -main (int argc, char **argv) +int main(int argc, char **argv) { - opal_event_t timeout; - struct timeval tv; + opal_event_t timeout; + struct timeval tv; - /* Initialize the event library */ - opal_event_init(); + /* Initialize the event library */ + opal_event_init(); - /* Initialize one event */ - opal_evtimer_set(&timeout, timeout_cb, &timeout); + /* Initialize one event */ + opal_evtimer_set(&timeout, timeout_cb, &timeout); - timerclear(&tv); - tv.tv_sec = 2; - opal_event_add(&timeout, &tv); + timerclear(&tv); + tv.tv_sec = 2; + opal_event_add(&timeout, &tv); - lasttime = time(NULL); + lasttime = time(NULL); - opal_event_dispatch(); + opal_event_dispatch(); - return (0); + return (0); } - diff --git a/test/memchecker/irecv_init_check.c b/test/memchecker/irecv_init_check.c index 0fa7ecb2a4..7bc0ee8cd9 100644 --- a/test/memchecker/irecv_init_check.c +++ b/test/memchecker/irecv_init_check.c @@ -8,26 +8,26 @@ * $HEADER$ */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int rank, size; - int send_value[10],recv_value[10]; + int send_value[10], recv_value[10]; int i; MPI_Status status; MPI_Request send_request; MPI_Request recv_request; - MPI_Init( &argc, &argv ); + MPI_Init(&argc, &argv); - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - MPI_Comm_size( MPI_COMM_WORLD, &size ); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); - for(i=0; i < 10; i++) { + for (i = 0; i < 10; i++) { send_value[i] = i; - printf("\n%d:%d",i,send_value[i]); + printf("\n%d:%d", i, send_value[i]); } /* @@ -37,8 +37,8 @@ int main( int argc, char *argv[] ) recv_value[9] = 100; if (size != 2) { - fprintf (stderr, "Error: Need 2 processes\n"); - MPI_Finalize (); + fprintf(stderr, "Error: Need 2 processes\n"); + MPI_Finalize(); } /* @@ -46,20 +46,18 @@ int main( int argc, char *argv[] ) * Perfectly valid, but the receiver (in strict mode?) should not * depend on the data. */ - MPI_Isend (&send_value, 9, MPI_INT, - (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request); - MPI_Irecv (&recv_value, 10, MPI_INT, - (rank + size - 1) % size, 4711, MPI_COMM_WORLD, &recv_request); + MPI_Isend(&send_value, 9, MPI_INT, (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request); + MPI_Irecv(&recv_value, 10, MPI_INT, (rank + size - 1) % size, 4711, MPI_COMM_WORLD, + &recv_request); - MPI_Wait (&send_request, &status); - MPI_Wait (&recv_request, &status); + MPI_Wait(&send_request, &status); + MPI_Wait(&recv_request, &status); /* * In strict mode, this should return an error. */ printf("\nError in strict mode: buf[9]:%d", recv_value[9]); - MPI_Finalize (); + MPI_Finalize(); return 0; } - diff --git a/test/memchecker/irecv_uninit_check.c b/test/memchecker/irecv_uninit_check.c index 8dc411c766..451fa083c5 100644 --- a/test/memchecker/irecv_uninit_check.c +++ b/test/memchecker/irecv_uninit_check.c @@ -8,27 +8,26 @@ * $HEADER$ */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int rank, size; - int send_value[10],recv_value[10]; + int send_value[10], recv_value[10]; int i; MPI_Status status; MPI_Request send_request; MPI_Request recv_request; - MPI_Init( &argc, &argv ); + MPI_Init(&argc, &argv); - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - MPI_Comm_size( MPI_COMM_WORLD, &size ); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); - for(i=0;i<10;i++) - { + for (i = 0; i < 10; i++) { send_value[i] = i; - printf("\n%d:%d",i,send_value[i]); + printf("\n%d:%d", i, send_value[i]); } /* @@ -37,8 +36,8 @@ int main( int argc, char *argv[] ) */ if (size != 2) { - fprintf (stderr, "Error: Need 2 processes\n"); - MPI_Finalize (); + fprintf(stderr, "Error: Need 2 processes\n"); + MPI_Finalize(); } /* @@ -46,19 +45,18 @@ int main( int argc, char *argv[] ) * Perfectly valid, but the receiver (in strict mode?) should not * depend on the data. */ - MPI_Isend (&send_value, 9, MPI_INT, - (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request); - MPI_Irecv (&recv_value, 10, MPI_INT, - (rank + size - 1) % size, 4711, MPI_COMM_WORLD, &recv_request); + MPI_Isend(&send_value, 9, MPI_INT, (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request); + MPI_Irecv(&recv_value, 10, MPI_INT, (rank + size - 1) % size, 4711, MPI_COMM_WORLD, + &recv_request); - MPI_Wait (&send_request, &status); - MPI_Wait (&recv_request, &status); + MPI_Wait(&send_request, &status); + MPI_Wait(&recv_request, &status); /* * This should return an error in any mode. */ - printf("\nError: buf[9]:%d",recv_value[9]); + printf("\nError: buf[9]:%d", recv_value[9]); - MPI_Finalize (); + MPI_Finalize(); return 0; } diff --git a/test/memchecker/non_blocking_recv_test.c b/test/memchecker/non_blocking_recv_test.c index 793959f8a8..505c0acd33 100644 --- a/test/memchecker/non_blocking_recv_test.c +++ b/test/memchecker/non_blocking_recv_test.c @@ -8,52 +8,51 @@ * $HEADER$ */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int rank, size; - int send_value,recv_value; + int send_value, recv_value; MPI_Status status; MPI_Request send_request; MPI_Request recv_request; - MPI_Init( &argc, &argv ); + MPI_Init(&argc, &argv); - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - MPI_Comm_size( MPI_COMM_WORLD, &size ); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); send_value = 10; recv_value = 0; if (size != 2) { - fprintf (stderr, "Error: Need 2 processes\n"); - MPI_Finalize (); + fprintf(stderr, "Error: Need 2 processes\n"); + MPI_Finalize(); } - MPI_Isend (&send_value, 1, MPI_INT, - (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request); - MPI_Irecv (&recv_value, 1, MPI_INT, - (rank + size - 1) % size, 4711, MPI_COMM_WORLD, &recv_request); + MPI_Isend(&send_value, 1, MPI_INT, (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request); + MPI_Irecv(&recv_value, 1, MPI_INT, (rank + size - 1) % size, 4711, MPI_COMM_WORLD, + &recv_request); /* * Reading or writing of the receive buffer before * non blocking send finished will cause an error. */ - printf("\nsent: %d\n",recv_value); + printf("\nsent: %d\n", recv_value); recv_value = 12; - MPI_Wait (&send_request, &status); - MPI_Wait (&recv_request, &status); + MPI_Wait(&send_request, &status); + MPI_Wait(&recv_request, &status); /* * Using of receive buffer after non blocking send * is finished will be ok. */ - printf("\nsent: %d\n",recv_value); + printf("\nsent: %d\n", recv_value); recv_value = 16; - MPI_Finalize (); + MPI_Finalize(); return 0; } diff --git a/test/memchecker/non_blocking_send_test.c b/test/memchecker/non_blocking_send_test.c index 0a6b25d20a..09eb4b299c 100644 --- a/test/memchecker/non_blocking_send_test.c +++ b/test/memchecker/non_blocking_send_test.c @@ -8,54 +8,52 @@ * $HEADER$ */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { int rank, size; - int send_value,recv_value; + int send_value, recv_value; MPI_Status status; MPI_Request send_request; MPI_Request recv_request; - MPI_Init( &argc, &argv ); + MPI_Init(&argc, &argv); - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); - MPI_Comm_size( MPI_COMM_WORLD, &size ); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); send_value = 10; recv_value = 0; if (size != 2) { - fprintf (stderr, "Error: Need 2 processes\n"); - MPI_Finalize (); + fprintf(stderr, "Error: Need 2 processes\n"); + MPI_Finalize(); } - MPI_Isend (&send_value, 1, MPI_INT, - (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request); - MPI_Irecv (&recv_value, 1, MPI_INT, - (rank + size - 1) % size, 4711, MPI_COMM_WORLD, &recv_request); + MPI_Isend(&send_value, 1, MPI_INT, (rank + 1) % size, 4711, MPI_COMM_WORLD, &send_request); + MPI_Irecv(&recv_value, 1, MPI_INT, (rank + size - 1) % size, 4711, MPI_COMM_WORLD, + &recv_request); /* * Reading or writing of the send buffer before * non blocking send is finished will cause an error. */ - printf("\nsent: %d\n",send_value); + printf("\nsent: %d\n", send_value); send_value = 12; - MPI_Wait (&send_request, &status); - MPI_Wait (&recv_request, &status); + MPI_Wait(&send_request, &status); + MPI_Wait(&recv_request, &status); /* * Using of send buffer after non blocking send * is finished will be ok. */ - printf("\nsent: %d\n",send_value); + printf("\nsent: %d\n", send_value); send_value = 16; - MPI_Finalize (); + MPI_Finalize(); return 0; } - diff --git a/test/monitoring/check_monitoring.c b/test/monitoring/check_monitoring.c index ae7e73eb8d..800b854813 100644 --- a/test/monitoring/check_monitoring.c +++ b/test/monitoring/check_monitoring.c @@ -19,118 +19,128 @@ */ #include <mpi.h> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#define PVAR_GENERATE_VARIABLES(pvar_prefix, pvar_name, pvar_class) \ - /* Variables */ \ - static MPI_T_pvar_handle pvar_prefix ## _handle; \ - static const char pvar_prefix ## _pvar_name[] = pvar_name; \ - static int pvar_prefix ## _pvar_idx; \ - /* Functions */ \ - static inline int pvar_prefix ## _start(MPI_T_pvar_session session) \ - { \ - int MPIT_result; \ - MPIT_result = MPI_T_pvar_start(session, pvar_prefix ## _handle); \ - if( MPI_SUCCESS != MPIT_result ) { \ - fprintf(stderr, "Failed to start handle on \"%s\" pvar, check that you have " \ - "enabled the monitoring component.\n", pvar_prefix ## _pvar_name); \ - MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ - } \ - return MPIT_result; \ - } \ - static inline int pvar_prefix ## _init(MPI_T_pvar_session session) \ - { \ - int MPIT_result; \ - MPI_Comm comm = MPI_COMM_WORLD; \ - /* Get index */ \ - MPIT_result = MPI_T_pvar_get_index(pvar_prefix ## _pvar_name, \ - pvar_class, \ - &(pvar_prefix ## _pvar_idx)); \ - if( MPI_SUCCESS != MPIT_result ) { \ - fprintf(stderr, "Cannot find monitoring MPI_Tool \"%s\" pvar, check that you have " \ - "enabled the monitoring component.\n", pvar_prefix ## _pvar_name); \ - MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ - return MPIT_result; \ - } \ - /* Allocate handle */ \ - /* Allocating a new PVAR in a session will reset the counters */ \ - int count; \ - MPIT_result = MPI_T_pvar_handle_alloc(session, pvar_prefix ## _pvar_idx, \ - &comm, &(pvar_prefix ## _handle), \ - &count); \ - if( MPI_SUCCESS != MPIT_result ) { \ - fprintf(stderr, "Failed to allocate handle on \"%s\" pvar, check that you have " \ - "enabled the monitoring component.\n", pvar_prefix ## _pvar_name); \ - MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ - return MPIT_result; \ - } \ - /* Start PVAR */ \ - return pvar_prefix ## _start(session); \ - } \ - static inline int pvar_prefix ## _stop(MPI_T_pvar_session session) \ - { \ - int MPIT_result; \ - MPIT_result = MPI_T_pvar_stop(session, pvar_prefix ## _handle); \ - if( MPI_SUCCESS != MPIT_result ) { \ - fprintf(stderr, "Failed to stop handle on \"%s\" pvar, check that you have " \ - "enabled the monitoring component.\n", pvar_prefix ## _pvar_name); \ - MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ - } \ - return MPIT_result; \ - } \ - static inline int pvar_prefix ## _finalize(MPI_T_pvar_session session) \ - { \ - int MPIT_result; \ - /* Stop PVAR */ \ - MPIT_result = pvar_prefix ## _stop(session); \ - /* Free handle */ \ - MPIT_result = MPI_T_pvar_handle_free(session, &(pvar_prefix ## _handle)); \ - if( MPI_SUCCESS != MPIT_result ) { \ - fprintf(stderr, "Failed to allocate handle on \"%s\" pvar, check that you have " \ - "enabled the monitoring component.\n", pvar_prefix ## _pvar_name); \ - MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ - return MPIT_result; \ - } \ - return MPIT_result; \ - } \ - static inline int pvar_prefix ## _read(MPI_T_pvar_session session, void*values) \ - { \ - int MPIT_result; \ - /* Stop pvar */ \ - MPIT_result = pvar_prefix ## _stop(session); \ - /* Read values */ \ - MPIT_result = MPI_T_pvar_read(session, pvar_prefix ## _handle, values); \ - if( MPI_SUCCESS != MPIT_result ) { \ - fprintf(stderr, "Failed to read handle on \"%s\" pvar, check that you have " \ - "enabled the monitoring component.\n", pvar_prefix ## _pvar_name); \ - MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ - } \ - /* Start and return */ \ - return pvar_prefix ## _start(session); \ +#define PVAR_GENERATE_VARIABLES(pvar_prefix, pvar_name, pvar_class) \ + /* Variables */ \ + static MPI_T_pvar_handle pvar_prefix##_handle; \ + static const char pvar_prefix##_pvar_name[] = pvar_name; \ + static int pvar_prefix##_pvar_idx; \ + /* Functions */ \ + static inline int pvar_prefix##_start(MPI_T_pvar_session session) \ + { \ + int MPIT_result; \ + MPIT_result = MPI_T_pvar_start(session, pvar_prefix##_handle); \ + if (MPI_SUCCESS != MPIT_result) { \ + fprintf(stderr, \ + "Failed to start handle on \"%s\" pvar, check that you have " \ + "enabled the monitoring component.\n", \ + pvar_prefix##_pvar_name); \ + MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ + } \ + return MPIT_result; \ + } \ + static inline int pvar_prefix##_init(MPI_T_pvar_session session) \ + { \ + int MPIT_result; \ + MPI_Comm comm = MPI_COMM_WORLD; \ + /* Get index */ \ + MPIT_result = MPI_T_pvar_get_index(pvar_prefix##_pvar_name, pvar_class, \ + &(pvar_prefix##_pvar_idx)); \ + if (MPI_SUCCESS != MPIT_result) { \ + fprintf(stderr, \ + "Cannot find monitoring MPI_Tool \"%s\" pvar, check that you have " \ + "enabled the monitoring component.\n", \ + pvar_prefix##_pvar_name); \ + MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ + return MPIT_result; \ + } \ + /* Allocate handle */ \ + /* Allocating a new PVAR in a session will reset the counters */ \ + int count; \ + MPIT_result = MPI_T_pvar_handle_alloc(session, pvar_prefix##_pvar_idx, &comm, \ + &(pvar_prefix##_handle), &count); \ + if (MPI_SUCCESS != MPIT_result) { \ + fprintf(stderr, \ + "Failed to allocate handle on \"%s\" pvar, check that you have " \ + "enabled the monitoring component.\n", \ + pvar_prefix##_pvar_name); \ + MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ + return MPIT_result; \ + } \ + /* Start PVAR */ \ + return pvar_prefix##_start(session); \ + } \ + static inline int pvar_prefix##_stop(MPI_T_pvar_session session) \ + { \ + int MPIT_result; \ + MPIT_result = MPI_T_pvar_stop(session, pvar_prefix##_handle); \ + if (MPI_SUCCESS != MPIT_result) { \ + fprintf(stderr, \ + "Failed to stop handle on \"%s\" pvar, check that you have " \ + "enabled the monitoring component.\n", \ + pvar_prefix##_pvar_name); \ + MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ + } \ + return MPIT_result; \ + } \ + static inline int pvar_prefix##_finalize(MPI_T_pvar_session session) \ + { \ + int MPIT_result; \ + /* Stop PVAR */ \ + MPIT_result = pvar_prefix##_stop(session); \ + /* Free handle */ \ + MPIT_result = MPI_T_pvar_handle_free(session, &(pvar_prefix##_handle)); \ + if (MPI_SUCCESS != MPIT_result) { \ + fprintf(stderr, \ + "Failed to allocate handle on \"%s\" pvar, check that you have " \ + "enabled the monitoring component.\n", \ + pvar_prefix##_pvar_name); \ + MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ + return MPIT_result; \ + } \ + return MPIT_result; \ + } \ + static inline int pvar_prefix##_read(MPI_T_pvar_session session, void *values) \ + { \ + int MPIT_result; \ + /* Stop pvar */ \ + MPIT_result = pvar_prefix##_stop(session); \ + /* Read values */ \ + MPIT_result = MPI_T_pvar_read(session, pvar_prefix##_handle, values); \ + if (MPI_SUCCESS != MPIT_result) { \ + fprintf(stderr, \ + "Failed to read handle on \"%s\" pvar, check that you have " \ + "enabled the monitoring component.\n", \ + pvar_prefix##_pvar_name); \ + MPI_Abort(MPI_COMM_WORLD, MPIT_result); \ + } \ + /* Start and return */ \ + return pvar_prefix##_start(session); \ } -#define GENERATE_CS(prefix, pvar_name_prefix, pvar_class_c, pvar_class_s) \ - PVAR_GENERATE_VARIABLES(prefix ## _count, pvar_name_prefix "_count", pvar_class_c) \ - PVAR_GENERATE_VARIABLES(prefix ## _size, pvar_name_prefix "_size", pvar_class_s) \ - static inline int pvar_ ## prefix ## _init(MPI_T_pvar_session session) \ - { \ - prefix ## _count_init(session); \ - return prefix ## _size_init(session); \ - } \ - static inline int pvar_ ## prefix ## _finalize(MPI_T_pvar_session session) \ - { \ - prefix ## _count_finalize(session); \ - return prefix ## _size_finalize(session); \ - } \ - static inline void pvar_ ## prefix ## _read(MPI_T_pvar_session session, \ - size_t*cvalues, size_t*svalues) \ - { \ - /* Read count values */ \ - prefix ## _count_read(session, cvalues); \ - /* Read size values */ \ - prefix ## _size_read(session, svalues); \ +#define GENERATE_CS(prefix, pvar_name_prefix, pvar_class_c, pvar_class_s) \ + PVAR_GENERATE_VARIABLES(prefix##_count, pvar_name_prefix "_count", pvar_class_c) \ + PVAR_GENERATE_VARIABLES(prefix##_size, pvar_name_prefix "_size", pvar_class_s) \ + static inline int pvar_##prefix##_init(MPI_T_pvar_session session) \ + { \ + prefix##_count_init(session); \ + return prefix##_size_init(session); \ + } \ + static inline int pvar_##prefix##_finalize(MPI_T_pvar_session session) \ + { \ + prefix##_count_finalize(session); \ + return prefix##_size_finalize(session); \ + } \ + static inline void pvar_##prefix##_read(MPI_T_pvar_session session, size_t *cvalues, \ + size_t *svalues) \ + { \ + /* Read count values */ \ + prefix##_count_read(session, cvalues); \ + /* Read size values */ \ + prefix##_size_read(session, svalues); \ } GENERATE_CS(pml, "pml_monitoring_messages", MPI_T_PVAR_CLASS_SIZE, MPI_T_PVAR_CLASS_SIZE) @@ -143,7 +153,7 @@ GENERATE_CS(a2a, "coll_monitoring_a2a", MPI_T_PVAR_CLASS_COUNTER, MPI_T_PVAR_CLA static size_t *old_cvalues, *old_svalues; -static inline void pvar_all_init(MPI_T_pvar_session*session, int world_size) +static inline void pvar_all_init(MPI_T_pvar_session *session, int world_size) { int MPIT_result, provided; MPIT_result = MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); @@ -167,7 +177,7 @@ static inline void pvar_all_init(MPI_T_pvar_session*session, int world_size) pvar_a2a_init(*session); } -static inline void pvar_all_finalize(MPI_T_pvar_session*session) +static inline void pvar_all_finalize(MPI_T_pvar_session *session) { int MPIT_result; pvar_pml_finalize(*session); @@ -183,7 +193,7 @@ static inline void pvar_all_finalize(MPI_T_pvar_session*session) printf("Failed to close a session for PVARs.\n"); MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - (void)MPI_T_finalize(); + (void) MPI_T_finalize(); } static inline int pvar_pml_check(MPI_T_pvar_session session, int world_size, int world_rank) @@ -194,29 +204,30 @@ static inline int pvar_pml_check(MPI_T_pvar_session session, int world_size, int svalues = cvalues + world_size; /* Get values */ pvar_pml_read(session, cvalues, svalues); - for( i = 0; i < world_size && MPI_SUCCESS == ret; ++i ) { + for (i = 0; i < world_size && MPI_SUCCESS == ret; ++i) { /* Check count values */ - if( i == world_rank && (cvalues[i] - old_cvalues[i]) != (size_t) 0 ) { + if (i == world_rank && (cvalues[i] - old_cvalues[i]) != (size_t) 0) { fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be equal to %zu.\n", __func__, i, cvalues[i] - old_cvalues[i], (size_t) 0); ret = -1; - } else if ( i != world_rank && (cvalues[i] - old_cvalues[i]) < (size_t) world_size ) { - fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be >= %zu.\n", - __func__, i, cvalues[i] - old_cvalues[i], (size_t) world_size); + } else if (i != world_rank && (cvalues[i] - old_cvalues[i]) < (size_t) world_size) { + fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be >= %zu.\n", __func__, + i, cvalues[i] - old_cvalues[i], (size_t) world_size); ret = -1; } /* Check size values */ - if( i == world_rank && (svalues[i] - old_svalues[i]) != (size_t) 0 ) { + if (i == world_rank && (svalues[i] - old_svalues[i]) != (size_t) 0) { fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be equal to %zu.\n", __func__, i, svalues[i] - old_svalues[i], (size_t) 0); ret = -1; - } else if ( i != world_rank && (svalues[i] - old_svalues[i]) < (size_t) (world_size * 13 * sizeof(char)) ) { - fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be >= %zu.\n", - __func__, i, svalues[i] - old_svalues[i], (size_t) (world_size * 13 * sizeof(char))); + } else if (i != world_rank + && (svalues[i] - old_svalues[i]) < (size_t)(world_size * 13 * sizeof(char))) { + fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be >= %zu.\n", __func__, + i, svalues[i] - old_svalues[i], (size_t)(world_size * 13 * sizeof(char))); ret = -1; } } - if( MPI_SUCCESS == ret ) { + if (MPI_SUCCESS == ret) { fprintf(stdout, "Check PML...[ OK ]\n"); } else { fprintf(stdout, "Check PML...[FAIL]\n"); @@ -238,37 +249,37 @@ static inline int pvar_osc_check(MPI_T_pvar_session session, int world_size, int memset(cvalues, 0, 2 * world_size * sizeof(size_t)); /* Check OSC sent values */ pvar_osc_s_read(session, cvalues, svalues); - for( i = 0; i < world_size && MPI_SUCCESS == ret; ++i ) { + for (i = 0; i < world_size && MPI_SUCCESS == ret; ++i) { /* Check count values */ - if( cvalues[i] < (size_t) world_size ) { - fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be >= %zu.\n", - __func__, i, cvalues[i], (size_t) world_size); + if (cvalues[i] < (size_t) world_size) { + fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be >= %zu.\n", __func__, + i, cvalues[i], (size_t) world_size); ret = -1; } /* Check size values */ - if( svalues[i] < (size_t) (world_size * 13 * sizeof(char)) ) { - fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be >= %zu.\n", - __func__, i, svalues[i], (size_t) (world_size * 13 * sizeof(char))); + if (svalues[i] < (size_t)(world_size * 13 * sizeof(char))) { + fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be >= %zu.\n", __func__, + i, svalues[i], (size_t)(world_size * 13 * sizeof(char))); ret = -1; } } /* Check OSC received values */ pvar_osc_r_read(session, cvalues, svalues); - for( i = 0; i < world_size && MPI_SUCCESS == ret; ++i ) { + for (i = 0; i < world_size && MPI_SUCCESS == ret; ++i) { /* Check count values */ - if( cvalues[i] < (size_t) world_size ) { - fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be >= %zu.\n", - __func__, i, cvalues[i], (size_t) world_size); + if (cvalues[i] < (size_t) world_size) { + fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be >= %zu.\n", __func__, + i, cvalues[i], (size_t) world_size); ret = -1; } /* Check size values */ - if( svalues[i] < (size_t) (world_size * 13 * sizeof(char)) ) { - fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be >= %zu.\n", - __func__, i, svalues[i], (size_t) (world_size * 13 * sizeof(char))); + if (svalues[i] < (size_t)(world_size * 13 * sizeof(char))) { + fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be >= %zu.\n", __func__, + i, svalues[i], (size_t)(world_size * 13 * sizeof(char))); ret = -1; } } - if( MPI_SUCCESS == ret ) { + if (MPI_SUCCESS == ret) { fprintf(stdout, "Check OSC...[ OK ]\n"); } else { fprintf(stdout, "Check OSC...[FAIL]\n"); @@ -280,7 +291,8 @@ static inline int pvar_osc_check(MPI_T_pvar_session session, int world_size, int return ret; } -static inline int pvar_coll_check(MPI_T_pvar_session session, int world_size, int world_rank) { +static inline int pvar_coll_check(MPI_T_pvar_session session, int world_size, int world_rank) +{ int i, ret = MPI_SUCCESS; size_t count, size; size_t *cvalues, *svalues; @@ -288,67 +300,69 @@ static inline int pvar_coll_check(MPI_T_pvar_session session, int world_size, in svalues = cvalues + world_size; /* Get COLL values */ pvar_coll_read(session, cvalues, svalues); - for( i = 0; i < world_size && MPI_SUCCESS == ret; ++i ) { + for (i = 0; i < world_size && MPI_SUCCESS == ret; ++i) { /* Check count values */ - if( i == world_rank && cvalues[i] != (size_t) 0 ) { + if (i == world_rank && cvalues[i] != (size_t) 0) { fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be equal to %zu.\n", __func__, i, cvalues[i], (size_t) 0); ret = -1; - } else if ( i != world_rank && cvalues[i] < (size_t) (world_size + 1) * 4 ) { - fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be >= %zu.\n", - __func__, i, cvalues[i], (size_t) (world_size + 1) * 4); + } else if (i != world_rank && cvalues[i] < (size_t)(world_size + 1) * 4) { + fprintf(stderr, "Error in %s: count_values[%d]=%zu, and should be >= %zu.\n", __func__, + i, cvalues[i], (size_t)(world_size + 1) * 4); ret = -1; } /* Check size values */ - if( i == world_rank && svalues[i] != (size_t) 0 ) { + if (i == world_rank && svalues[i] != (size_t) 0) { fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be equal to %zu.\n", __func__, i, svalues[i], (size_t) 0); ret = -1; - } else if ( i != world_rank && svalues[i] < (size_t) (world_size * (2 * 13 * sizeof(char) + sizeof(int)) + 13 * 3 * sizeof(char) + sizeof(int)) ) { - fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be >= %zu.\n", - __func__, i, svalues[i], (size_t) (world_size * (2 * 13 * sizeof(char) + sizeof(int)) + 13 * 3 * sizeof(char) + sizeof(int))); + } else if (i != world_rank + && svalues[i] < (size_t)(world_size * (2 * 13 * sizeof(char) + sizeof(int)) + + 13 * 3 * sizeof(char) + sizeof(int))) { + fprintf(stderr, "Error in %s: size_values[%d]=%zu, and should be >= %zu.\n", __func__, + i, svalues[i], + (size_t)(world_size * (2 * 13 * sizeof(char) + sizeof(int)) + + 13 * 3 * sizeof(char) + sizeof(int))); ret = -1; } } /* Check One-to-all COLL values */ pvar_o2a_read(session, &count, &size); - if( count < (size_t) 2 ) { - fprintf(stderr, "Error in %s: count_o2a=%zu, and should be >= %zu.\n", - __func__, count, (size_t) 2); + if (count < (size_t) 2) { + fprintf(stderr, "Error in %s: count_o2a=%zu, and should be >= %zu.\n", __func__, count, + (size_t) 2); ret = -1; } - if( size < (size_t) ((world_size - 1) * 13 * 2 * sizeof(char)) ) { - fprintf(stderr, "Error in %s: size_o2a=%zu, and should be >= %zu.\n", - __func__, size, (size_t) ((world_size - 1) * 13 * 2 * sizeof(char))); + if (size < (size_t)((world_size - 1) * 13 * 2 * sizeof(char))) { + fprintf(stderr, "Error in %s: size_o2a=%zu, and should be >= %zu.\n", __func__, size, + (size_t)((world_size - 1) * 13 * 2 * sizeof(char))); ret = -1; } /* Check All-to-one COLL values */ pvar_a2o_read(session, &count, &size); - if( count < (size_t) 2 ) { - fprintf(stderr, "Error in %s: count_a2o=%zu, and should be >= %zu.\n", - __func__, count, (size_t) 2); + if (count < (size_t) 2) { + fprintf(stderr, "Error in %s: count_a2o=%zu, and should be >= %zu.\n", __func__, count, + (size_t) 2); ret = -1; } - if( size < (size_t) ((world_size - 1) * (13 * sizeof(char) + sizeof(int))) ) { - fprintf(stderr, "Error in %s: size_a2o=%zu, and should be >= %zu.\n", - __func__, size, - (size_t) ((world_size - 1) * (13 * sizeof(char) + sizeof(int)))); + if (size < (size_t)((world_size - 1) * (13 * sizeof(char) + sizeof(int)))) { + fprintf(stderr, "Error in %s: size_a2o=%zu, and should be >= %zu.\n", __func__, size, + (size_t)((world_size - 1) * (13 * sizeof(char) + sizeof(int)))); ret = -1; } /* Check All-to-all COLL values */ pvar_a2a_read(session, &count, &size); - if( count < (size_t) (world_size * 4) ) { - fprintf(stderr, "Error in %s: count_a2a=%zu, and should be >= %zu.\n", - __func__, count, (size_t) (world_size * 4)); + if (count < (size_t)(world_size * 4)) { + fprintf(stderr, "Error in %s: count_a2a=%zu, and should be >= %zu.\n", __func__, count, + (size_t)(world_size * 4)); ret = -1; } - if( size < (size_t) (world_size * (world_size - 1) * (2 * 13 * sizeof(char) + sizeof(int))) ) { - fprintf(stderr, "Error in %s: size_a2a=%zu, and should be >= %zu.\n", - __func__, size, - (size_t) (world_size * (world_size - 1) * (2 * 13 * sizeof(char) + sizeof(int)))); + if (size < (size_t)(world_size * (world_size - 1) * (2 * 13 * sizeof(char) + sizeof(int)))) { + fprintf(stderr, "Error in %s: size_a2a=%zu, and should be >= %zu.\n", __func__, size, + (size_t)(world_size * (world_size - 1) * (2 * 13 * sizeof(char) + sizeof(int)))); ret = -1; } - if( MPI_SUCCESS == ret ) { + if (MPI_SUCCESS == ret) { fprintf(stdout, "Check COLL...[ OK ]\n"); } else { fprintf(stdout, "Check COLL...[FAIL]\n"); @@ -360,7 +374,7 @@ static inline int pvar_coll_check(MPI_T_pvar_session session, int world_size, in return ret; } -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int size, i, n, to, from, world_rank; MPI_T_pvar_session session; @@ -371,7 +385,7 @@ int main(int argc, char* argv[]) MPI_Init(NULL, NULL); MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - + pvar_all_init(&session, size); /* first phase: exchange size times data with everyone in @@ -379,52 +393,60 @@ int main(int argc, char* argv[]) first in order to ease the prediction of messages exchanged of each kind. */ - char*coll_buff = malloc(2 * size * 13 * sizeof(char)); - char*coll_recv_buff = coll_buff + size * 13; + char *coll_buff = malloc(2 * size * 13 * sizeof(char)); + char *coll_recv_buff = coll_buff + size * 13; int sum_ranks; - for( n = 0; n < size; ++n ) { + for (n = 0; n < size; ++n) { /* Allgather */ memset(coll_buff, 0, size * 13 * sizeof(char)); MPI_Allgather(s1, 13, MPI_CHAR, coll_buff, 13, MPI_CHAR, MPI_COMM_WORLD); - for( i = 0; i < size; ++i ) { - if( strncmp(s1, &coll_buff[i * 13], 13) ) { - fprintf(stderr, "Error in Allgather check: received \"%s\" instead of " - "\"hello world!\" from %d.\n", &coll_buff[i * 13], i); + for (i = 0; i < size; ++i) { + if (strncmp(s1, &coll_buff[i * 13], 13)) { + fprintf(stderr, + "Error in Allgather check: received \"%s\" instead of " + "\"hello world!\" from %d.\n", + &coll_buff[i * 13], i); MPI_Abort(MPI_COMM_WORLD, -1); } } /* Scatter */ MPI_Scatter(coll_buff, 13, MPI_CHAR, s2, 13, MPI_CHAR, n, MPI_COMM_WORLD); - if( strncmp(s1, s2, 13) ) { - fprintf(stderr, "Error in Scatter check: received \"%s\" instead of " - "\"hello world!\" from %d.\n", s2, n); + if (strncmp(s1, s2, 13)) { + fprintf(stderr, + "Error in Scatter check: received \"%s\" instead of " + "\"hello world!\" from %d.\n", + s2, n); MPI_Abort(MPI_COMM_WORLD, -1); } /* Allreduce */ MPI_Allreduce(&world_rank, &sum_ranks, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD); - if( sum_ranks != ((size - 1) * size / 2) ) { - fprintf(stderr, "Error in Allreduce check: sum_ranks=%d instead of %d.\n", - sum_ranks, (size - 1) * size / 2); + if (sum_ranks != ((size - 1) * size / 2)) { + fprintf(stderr, "Error in Allreduce check: sum_ranks=%d instead of %d.\n", sum_ranks, + (size - 1) * size / 2); MPI_Abort(MPI_COMM_WORLD, -1); } /* Alltoall */ memset(coll_recv_buff, 0, size * 13 * sizeof(char)); MPI_Alltoall(coll_buff, 13, MPI_CHAR, coll_recv_buff, 13, MPI_CHAR, MPI_COMM_WORLD); - for( i = 0; i < size; ++i ) { - if( strncmp(s1, &coll_recv_buff[i * 13], 13) ) { - fprintf(stderr, "Error in Alltoall check: received \"%s\" instead of " - "\"hello world!\" from %d.\n", &coll_recv_buff[i * 13], i); + for (i = 0; i < size; ++i) { + if (strncmp(s1, &coll_recv_buff[i * 13], 13)) { + fprintf(stderr, + "Error in Alltoall check: received \"%s\" instead of " + "\"hello world!\" from %d.\n", + &coll_recv_buff[i * 13], i); MPI_Abort(MPI_COMM_WORLD, -1); } } /* Bcast */ - if( n == world_rank ) { + if (n == world_rank) { MPI_Bcast(s1, 13, MPI_CHAR, n, MPI_COMM_WORLD); } else { MPI_Bcast(s2, 13, MPI_CHAR, n, MPI_COMM_WORLD); - if( strncmp(s1, s2, 13) ) { - fprintf(stderr, "Error in Bcast check: received \"%s\" instead of " - "\"hello world!\" from %d.\n", s2, n); + if (strncmp(s1, s2, 13)) { + fprintf(stderr, + "Error in Bcast check: received \"%s\" instead of " + "\"hello world!\" from %d.\n", + s2, n); MPI_Abort(MPI_COMM_WORLD, -1); } } @@ -433,82 +455,85 @@ int main(int argc, char* argv[]) /* Gather */ memset(coll_buff, 0, size * 13 * sizeof(char)); MPI_Gather(s1, 13, MPI_CHAR, coll_buff, 13, MPI_CHAR, n, MPI_COMM_WORLD); - if( n == world_rank ) { - for( i = 0; i < size; ++i ) { - if( strncmp(s1, &coll_buff[i * 13], 13) ) { - fprintf(stderr, "Error in Gather check: received \"%s\" instead of " - "\"hello world!\" from %d.\n", &coll_buff[i * 13], i); + if (n == world_rank) { + for (i = 0; i < size; ++i) { + if (strncmp(s1, &coll_buff[i * 13], 13)) { + fprintf(stderr, + "Error in Gather check: received \"%s\" instead of " + "\"hello world!\" from %d.\n", + &coll_buff[i * 13], i); MPI_Abort(MPI_COMM_WORLD, -1); } } } /* Reduce */ MPI_Reduce(&world_rank, &sum_ranks, 1, MPI_INT, MPI_SUM, n, MPI_COMM_WORLD); - if( n == world_rank ) { - if( sum_ranks != ((size - 1) * size / 2) ) { - fprintf(stderr, "Error in Reduce check: sum_ranks=%d instead of %d.\n", - sum_ranks, (size - 1) * size / 2); + if (n == world_rank) { + if (sum_ranks != ((size - 1) * size / 2)) { + fprintf(stderr, "Error in Reduce check: sum_ranks=%d instead of %d.\n", sum_ranks, + (size - 1) * size / 2); MPI_Abort(MPI_COMM_WORLD, -1); } - } + } } free(coll_buff); - if( -1 == pvar_coll_check(session, size, world_rank) ) MPI_Abort(MPI_COMM_WORLD, -1); + if (-1 == pvar_coll_check(session, size, world_rank)) + MPI_Abort(MPI_COMM_WORLD, -1); /* second phase: exchange size times data with everyone except self - in MPI_COMM_WORLD with Send/Recv */ - for( n = 0; n < size; ++n ) { - for( i = 0; i < size - 1; ++i ) { - to = (world_rank+1+i)%size; - from = (world_rank+size-1-i)%size; - if(world_rank < to){ + in MPI_COMM_WORLD with Send/Recv */ + for (n = 0; n < size; ++n) { + for (i = 0; i < size - 1; ++i) { + to = (world_rank + 1 + i) % size; + from = (world_rank + size - 1 - i) % size; + if (world_rank < to) { MPI_Send(s1, 13, MPI_CHAR, to, world_rank, MPI_COMM_WORLD); MPI_Recv(s2, 13, MPI_CHAR, from, from, MPI_COMM_WORLD, &status); } else { MPI_Recv(s2, 13, MPI_CHAR, from, from, MPI_COMM_WORLD, &status); MPI_Send(s1, 13, MPI_CHAR, to, world_rank, MPI_COMM_WORLD); } - if( strncmp(s2, "hello world!", 13) ) { - fprintf(stderr, "Error in PML check: s2=\"%s\" instead of \"hello world!\".\n", - s2); + if (strncmp(s2, "hello world!", 13)) { + fprintf(stderr, "Error in PML check: s2=\"%s\" instead of \"hello world!\".\n", s2); MPI_Abort(MPI_COMM_WORLD, -1); } } - } - if( -1 == pvar_pml_check(session, size, world_rank) ) MPI_Abort(MPI_COMM_WORLD, -1); + } + if (-1 == pvar_pml_check(session, size, world_rank)) + MPI_Abort(MPI_COMM_WORLD, -1); /* third phase: exchange size times data with everyone, including self, in MPI_COMM_WORLD with RMA opertations */ char win_buff[20]; MPI_Win win; MPI_Win_create(win_buff, 20, sizeof(char), MPI_INFO_NULL, MPI_COMM_WORLD, &win); - for( n = 0; n < size; ++n ) { - for( i = 0; i < size; ++i ) { + for (n = 0; n < size; ++n) { + for (i = 0; i < size; ++i) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, i, 0, win); MPI_Put(s1, 13, MPI_CHAR, i, 0, 13, MPI_CHAR, win); MPI_Win_unlock(i, win); } MPI_Win_lock(MPI_LOCK_EXCLUSIVE, world_rank, 0, win); - if( strncmp(win_buff, "hello world!", 13) ) { + if (strncmp(win_buff, "hello world!", 13)) { fprintf(stderr, "Error in OSC check: win_buff=\"%s\" instead of \"hello world!\".\n", win_buff); MPI_Abort(MPI_COMM_WORLD, -1); } MPI_Win_unlock(world_rank, win); - for( i = 0; i < size; ++i ) { + for (i = 0; i < size; ++i) { MPI_Win_lock(MPI_LOCK_EXCLUSIVE, i, 0, win); MPI_Get(s2, 13, MPI_CHAR, i, 0, 13, MPI_CHAR, win); MPI_Win_unlock(i, win); - if( strncmp(s2, "hello world!", 13) ) { - fprintf(stderr, "Error in OSC check: s2=\"%s\" instead of \"hello world!\".\n", - s2); + if (strncmp(s2, "hello world!", 13)) { + fprintf(stderr, "Error in OSC check: s2=\"%s\" instead of \"hello world!\".\n", s2); MPI_Abort(MPI_COMM_WORLD, -1); } } } MPI_Win_free(&win); - if( -1 == pvar_osc_check(session, size, world_rank) ) MPI_Abort(MPI_COMM_WORLD, -1); - + if (-1 == pvar_osc_check(session, size, world_rank)) + MPI_Abort(MPI_COMM_WORLD, -1); + pvar_all_finalize(&session); MPI_Finalize(); diff --git a/test/monitoring/example_reduce_count.c b/test/monitoring/example_reduce_count.c index 12319db538..cb5ede304b 100644 --- a/test/monitoring/example_reduce_count.c +++ b/test/monitoring/example_reduce_count.c @@ -7,22 +7,22 @@ * $HEADER$ */ -#include <stdlib.h> -#include <stdio.h> #include <mpi.h> +#include <stdio.h> +#include <stdlib.h> static MPI_T_pvar_handle count_handle; static const char count_pvar_name[] = "pml_monitoring_messages_count"; static int count_pvar_idx; -int main(int argc, char**argv) +int main(int argc, char **argv) { int rank, size, n, to, from, tagno, MPIT_result, provided, count; MPI_T_pvar_session session; MPI_Status status; MPI_Request request; MPI_Comm comm = MPI_COMM_WORLD; - size_t*counts; + size_t *counts; n = -1; MPI_Init(&argc, &argv); @@ -34,95 +34,100 @@ int main(int argc, char**argv) MPIT_result = MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); if (MPIT_result != MPI_SUCCESS) - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); MPIT_result = MPI_T_pvar_get_index(count_pvar_name, MPI_T_PVAR_CLASS_SIZE, &count_pvar_idx); if (MPIT_result != MPI_SUCCESS) { - printf("cannot find monitoring MPI_T \"%s\" pvar, check that you have monitoring pml\n", - count_pvar_name); - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + printf("cannot find monitoring MPI_T \"%s\" pvar, check that you have monitoring pml\n", + count_pvar_name); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); } MPIT_result = MPI_T_pvar_session_create(&session); if (MPIT_result != MPI_SUCCESS) { - printf("cannot create a session for \"%s\" pvar\n", count_pvar_name); - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + printf("cannot create a session for \"%s\" pvar\n", count_pvar_name); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); } /* Allocating a new PVAR in a session will reset the counters */ - MPIT_result = MPI_T_pvar_handle_alloc(session, count_pvar_idx, - &comm, &count_handle, &count); + MPIT_result = MPI_T_pvar_handle_alloc(session, count_pvar_idx, &comm, &count_handle, &count); if (MPIT_result != MPI_SUCCESS) { - printf("failed to allocate handle on \"%s\" pvar, check that you have monitoring pml\n", - count_pvar_name); - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + printf("failed to allocate handle on \"%s\" pvar, check that you have monitoring pml\n", + count_pvar_name); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - counts = (size_t*)malloc(count * sizeof(size_t)); + counts = (size_t *) malloc(count * sizeof(size_t)); MPIT_result = MPI_T_pvar_start(session, count_handle); if (MPIT_result != MPI_SUCCESS) { - printf("failed to start handle on \"%s\" pvar, check that you have monitoring pml\n", - count_pvar_name); - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + printf("failed to start handle on \"%s\" pvar, check that you have monitoring pml\n", + count_pvar_name); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); } /* Token Ring communications */ if (rank == 0) { n = 25; - MPI_Isend(&n,1,MPI_INT,to,tagno,MPI_COMM_WORLD,&request); + MPI_Isend(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD, &request); } while (1) { MPI_Irecv(&n, 1, MPI_INT, from, tagno, MPI_COMM_WORLD, &request); MPI_Wait(&request, &status); - if (rank == 0) {n--;tagno++;} + if (rank == 0) { + n--; + tagno++; + } MPI_Isend(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD, &request); - if (rank != 0) {n--;tagno++;} - if (n<0){ + if (rank != 0) { + n--; + tagno++; + } + if (n < 0) { break; } } MPIT_result = MPI_T_pvar_read(session, count_handle, counts); if (MPIT_result != MPI_SUCCESS) { - printf("failed to read handle on \"%s\" pvar, check that you have monitoring pml\n", - count_pvar_name); - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + printf("failed to read handle on \"%s\" pvar, check that you have monitoring pml\n", + count_pvar_name); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); } /*** REDUCE ***/ MPI_Allreduce(MPI_IN_PLACE, counts, count, MPI_UNSIGNED_LONG, MPI_MAX, MPI_COMM_WORLD); - if(0 == rank) { - for(n = 0; n < count; ++n) - printf("%zu%s", counts[n], n < count - 1 ? ", " : "\n"); + if (0 == rank) { + for (n = 0; n < count; ++n) + printf("%zu%s", counts[n], n < count - 1 ? ", " : "\n"); } free(counts); MPIT_result = MPI_T_pvar_stop(session, count_handle); if (MPIT_result != MPI_SUCCESS) { - printf("failed to stop handle on \"%s\" pvar, check that you have monitoring pml\n", - count_pvar_name); - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + printf("failed to stop handle on \"%s\" pvar, check that you have monitoring pml\n", + count_pvar_name); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); } MPIT_result = MPI_T_pvar_handle_free(session, &count_handle); if (MPIT_result != MPI_SUCCESS) { - printf("failed to free handle on \"%s\" pvar, check that you have monitoring pml\n", - count_pvar_name); - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + printf("failed to free handle on \"%s\" pvar, check that you have monitoring pml\n", + count_pvar_name); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); } MPIT_result = MPI_T_pvar_session_free(&session); if (MPIT_result != MPI_SUCCESS) { - printf("cannot close a session for \"%s\" pvar\n", count_pvar_name); - MPI_Abort(MPI_COMM_WORLD, MPIT_result); + printf("cannot close a session for \"%s\" pvar\n", count_pvar_name); + MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - (void)MPI_T_finalize(); + (void) MPI_T_finalize(); MPI_Finalize(); - + return EXIT_SUCCESS; } diff --git a/test/monitoring/monitoring_test.c b/test/monitoring/monitoring_test.c index 9ae77abc49..f3ab40a30c 100644 --- a/test/monitoring/monitoring_test.c +++ b/test/monitoring/monitoring_test.c @@ -61,31 +61,30 @@ A2A 1 0 bytes 0 msgs sent */ - #include "mpi.h" #include <stdio.h> #include <string.h> static MPI_T_pvar_handle flush_handle; static const char flush_pvar_name[] = "pml_monitoring_flush"; -static const void*nullbuf = NULL; +static const void *nullbuf = NULL; static int flush_pvar_idx; static int with_mpit = 0; -static int with_rma = 1; +static int with_rma = 1; -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size, n, to, from, tagno, MPIT_result, provided, count, world_rank; MPI_T_pvar_session session; MPI_Comm newcomm; MPI_Comm comm = MPI_COMM_WORLD; char filename[1024]; - - for ( int arg_it = 1; argc > 1 && arg_it < argc; ++arg_it ) { - if( 0 == strcmp(argv[arg_it], "--with-mpit") ) { + + for (int arg_it = 1; argc > 1 && arg_it < argc; ++arg_it) { + if (0 == strcmp(argv[arg_it], "--with-mpit")) { with_mpit = 1; printf("enable MPIT support\n"); - } else if( 0 == strcmp(argv[arg_it], "--without-rma") ) { + } else if (0 == strcmp(argv[arg_it], "--without-rma")) { with_rma = 0; printf("disable RMA testing\n"); } @@ -101,12 +100,13 @@ int main(int argc, char* argv[]) from = (rank - 1) % size; tagno = 201; - if( with_mpit ) { + if (with_mpit) { MPIT_result = MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); if (MPIT_result != MPI_SUCCESS) MPI_Abort(MPI_COMM_WORLD, MPIT_result); - MPIT_result = MPI_T_pvar_get_index(flush_pvar_name, MPI_T_PVAR_CLASS_GENERIC, &flush_pvar_idx); + MPIT_result = MPI_T_pvar_get_index(flush_pvar_name, MPI_T_PVAR_CLASS_GENERIC, + &flush_pvar_idx); if (MPIT_result != MPI_SUCCESS) { printf("cannot find monitoring MPI_T \"%s\" pvar, check that you have monitoring pml\n", flush_pvar_name); @@ -120,8 +120,8 @@ int main(int argc, char* argv[]) } /* Allocating a new PVAR in a session will reset the counters */ - MPIT_result = MPI_T_pvar_handle_alloc(session, flush_pvar_idx, - &comm, &flush_handle, &count); + MPIT_result = MPI_T_pvar_handle_alloc(session, flush_pvar_idx, &comm, &flush_handle, + &count); if (MPIT_result != MPI_SUCCESS) { printf("failed to allocate handle on \"%s\" pvar, check that you have monitoring pml\n", flush_pvar_name); @@ -138,19 +138,25 @@ int main(int argc, char* argv[]) if (rank == 0) { n = 25; - MPI_Send(&n,1,MPI_INT,to,tagno,MPI_COMM_WORLD); + MPI_Send(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD); } while (1) { MPI_Recv(&n, 1, MPI_INT, from, tagno, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - if (rank == 0) {n--;tagno++;} + if (rank == 0) { + n--; + tagno++; + } MPI_Send(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD); - if (rank != 0) {n--;tagno++;} - if (n<0){ + if (rank != 0) { + n--; + tagno++; + } + if (n < 0) { break; } } - if( with_mpit ) { + if (with_mpit) { /* Build one file per processes Every thing that has been monitored by each process since the last flush will be output in filename */ @@ -162,9 +168,9 @@ int main(int argc, char* argv[]) */ sprintf(filename, "prof/phase_1"); - if( MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename) ) { - fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", - world_rank, filename, world_rank); + if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename)) { + fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", world_rank, + filename, world_rank); } /* Force the writing of the monitoring data */ MPIT_result = MPI_T_pvar_stop(session, flush_handle); @@ -183,7 +189,7 @@ int main(int argc, char* argv[]) /* Don't set a filename. If we stop the session before setting it, then no output file * will be generated. */ - if( MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, (void*)&nullbuf) ) { + if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, (void *) &nullbuf)) { fprintf(stderr, "Process %d cannot save monitoring in %s\n", world_rank, filename); } } @@ -193,25 +199,31 @@ int main(int argc, char* argv[]) even ranks will circulate a token while odd ranks will perform a all_to_all */ - MPI_Comm_split(MPI_COMM_WORLD, rank%2, rank, &newcomm); + MPI_Comm_split(MPI_COMM_WORLD, rank % 2, rank, &newcomm); - if(rank%2){ /*odd ranks (in COMM_WORD) circulate a token*/ + if (rank % 2) { /*odd ranks (in COMM_WORD) circulate a token*/ MPI_Comm_rank(newcomm, &rank); MPI_Comm_size(newcomm, &size); - if( size > 1 ) { + if (size > 1) { to = (rank + 1) % size; from = (rank - 1) % size; tagno = 201; - if (rank == 0){ + if (rank == 0) { n = 50; MPI_Send(&n, 1, MPI_INT, to, tagno, newcomm); } - while (1){ + while (1) { MPI_Recv(&n, 1, MPI_INT, from, tagno, newcomm, MPI_STATUS_IGNORE); - if (rank == 0) {n--; tagno++;} + if (rank == 0) { + n--; + tagno++; + } MPI_Send(&n, 1, MPI_INT, to, tagno, newcomm); - if (rank != 0) {n--; tagno++;} - if (n<0){ + if (rank != 0) { + n--; + tagno++; + } + if (n < 0) { break; } } @@ -222,13 +234,13 @@ int main(int argc, char* argv[]) MPI_Comm newcomm2; MPI_Comm_rank(newcomm, &rank); MPI_Comm_size(newcomm, &size); - MPI_Alltoall(send_buff, 10240/size, MPI_INT, recv_buff, 10240/size, MPI_INT, newcomm); - MPI_Comm_split(newcomm, rank%2, rank, &newcomm2); + MPI_Alltoall(send_buff, 10240 / size, MPI_INT, recv_buff, 10240 / size, MPI_INT, newcomm); + MPI_Comm_split(newcomm, rank % 2, rank, &newcomm2); MPI_Barrier(newcomm2); MPI_Comm_free(&newcomm2); } - if( with_mpit ) { + if (with_mpit) { /* Build one file per processes Every thing that has been monitored by each process since the last flush will be output in filename */ @@ -240,9 +252,9 @@ int main(int argc, char* argv[]) */ sprintf(filename, "prof/phase_2"); - if( MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename) ) { - fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", - world_rank, filename, world_rank); + if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename)) { + fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", world_rank, + filename, world_rank); } /* Force the writing of the monitoring data */ @@ -262,90 +274,93 @@ int main(int argc, char* argv[]) /* Don't set a filename. If we stop the session before setting it, then no output * will be generated. */ - if( MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, (void*)&nullbuf ) ) { + if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, (void *) &nullbuf)) { fprintf(stderr, "Process %d cannot save monitoring in %s\n", world_rank, filename); } } - if( with_rma ) { - MPI_Win win; - int rs_buff[10240]; - int win_buff[10240]; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - to = (rank + 1) % size; - from = (rank + size - 1) % size; - for( int v = 0; v < 10240; ++v ) - rs_buff[v] = win_buff[v] = rank; - - MPI_Win_create(win_buff, 10240 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, &win); - MPI_Win_fence(MPI_MODE_NOPRECEDE, win); - if( rank%2 ) { - MPI_Win_fence(MPI_MODE_NOSTORE | MPI_MODE_NOPUT, win); - MPI_Get(rs_buff, 10240, MPI_INT, from, 0, 10240, MPI_INT, win); - } else { - MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win); - MPI_Win_fence(MPI_MODE_NOSTORE | MPI_MODE_NOPUT, win); - } - MPI_Win_fence(MPI_MODE_NOSUCCEED, win); - - for( int v = 0; v < 10240; ++v ) - if( rs_buff[v] != win_buff[v] && ((rank%2 && rs_buff[v] != from) || (!(rank%2) && rs_buff[v] != rank)) ) { - printf("Error on checking exchanged values: %s_buff[%d] == %d instead of %d\n", - rank%2 ? "rs" : "win", v, rs_buff[v], rank%2 ? from : rank); - MPI_Abort(MPI_COMM_WORLD, -1); + if (with_rma) { + MPI_Win win; + int rs_buff[10240]; + int win_buff[10240]; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + to = (rank + 1) % size; + from = (rank + size - 1) % size; + for (int v = 0; v < 10240; ++v) + rs_buff[v] = win_buff[v] = rank; + + MPI_Win_create(win_buff, 10240 * sizeof(int), sizeof(int), MPI_INFO_NULL, MPI_COMM_WORLD, + &win); + MPI_Win_fence(MPI_MODE_NOPRECEDE, win); + if (rank % 2) { + MPI_Win_fence(MPI_MODE_NOSTORE | MPI_MODE_NOPUT, win); + MPI_Get(rs_buff, 10240, MPI_INT, from, 0, 10240, MPI_INT, win); + } else { + MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win); + MPI_Win_fence(MPI_MODE_NOSTORE | MPI_MODE_NOPUT, win); } + MPI_Win_fence(MPI_MODE_NOSUCCEED, win); + + for (int v = 0; v < 10240; ++v) + if (rs_buff[v] != win_buff[v] + && ((rank % 2 && rs_buff[v] != from) || (!(rank % 2) && rs_buff[v] != rank))) { + printf("Error on checking exchanged values: %s_buff[%d] == %d instead of %d\n", + rank % 2 ? "rs" : "win", v, rs_buff[v], rank % 2 ? from : rank); + MPI_Abort(MPI_COMM_WORLD, -1); + } - MPI_Group world_group, newcomm_group, distant_group; - MPI_Comm_group(MPI_COMM_WORLD, &world_group); - MPI_Comm_group(newcomm, &newcomm_group); - MPI_Group_difference(world_group, newcomm_group, &distant_group); - if( rank%2 ) { - MPI_Win_post(distant_group, 0, win); - MPI_Win_wait(win); - /* Check received values */ - for( int v = 0; v < 10240; ++v ) - if( from != win_buff[v] ) { - printf("Error on checking exchanged values: win_buff[%d] == %d instead of %d\n", - v, win_buff[v], from); - MPI_Abort(MPI_COMM_WORLD, -1); - } - } else { - MPI_Win_start(distant_group, 0, win); - MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win); - MPI_Win_complete(win); - } - MPI_Group_free(&world_group); - MPI_Group_free(&newcomm_group); - MPI_Group_free(&distant_group); - MPI_Barrier(MPI_COMM_WORLD); - - for( int v = 0; v < 10240; ++v ) rs_buff[v] = rank; - - MPI_Win_lock(MPI_LOCK_EXCLUSIVE, to, 0, win); - MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win); - MPI_Win_unlock(to, win); - - MPI_Barrier(MPI_COMM_WORLD); - - /* Check received values */ - for( int v = 0; v < 10240; ++v ) - if( from != win_buff[v] ) { - printf("Error on checking exchanged values: win_buff[%d] == %d instead of %d\n", - v, win_buff[v], from); - MPI_Abort(MPI_COMM_WORLD, -1); + MPI_Group world_group, newcomm_group, distant_group; + MPI_Comm_group(MPI_COMM_WORLD, &world_group); + MPI_Comm_group(newcomm, &newcomm_group); + MPI_Group_difference(world_group, newcomm_group, &distant_group); + if (rank % 2) { + MPI_Win_post(distant_group, 0, win); + MPI_Win_wait(win); + /* Check received values */ + for (int v = 0; v < 10240; ++v) + if (from != win_buff[v]) { + printf("Error on checking exchanged values: win_buff[%d] == %d instead of %d\n", + v, win_buff[v], from); + MPI_Abort(MPI_COMM_WORLD, -1); + } + } else { + MPI_Win_start(distant_group, 0, win); + MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win); + MPI_Win_complete(win); } + MPI_Group_free(&world_group); + MPI_Group_free(&newcomm_group); + MPI_Group_free(&distant_group); + MPI_Barrier(MPI_COMM_WORLD); + + for (int v = 0; v < 10240; ++v) + rs_buff[v] = rank; + + MPI_Win_lock(MPI_LOCK_EXCLUSIVE, to, 0, win); + MPI_Put(rs_buff, 10240, MPI_INT, to, 0, 10240, MPI_INT, win); + MPI_Win_unlock(to, win); + + MPI_Barrier(MPI_COMM_WORLD); + + /* Check received values */ + for (int v = 0; v < 10240; ++v) + if (from != win_buff[v]) { + printf("Error on checking exchanged values: win_buff[%d] == %d instead of %d\n", v, + win_buff[v], from); + MPI_Abort(MPI_COMM_WORLD, -1); + } - MPI_Win_free(&win); + MPI_Win_free(&win); } - if( with_mpit ) { + if (with_mpit) { /* the filename for flushing monitoring now uses 3 as phase number! */ sprintf(filename, "prof/phase_3"); - if( MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename) ) { - fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", - world_rank, filename, world_rank); + if (MPI_SUCCESS != MPI_T_pvar_write(session, flush_handle, filename)) { + fprintf(stderr, "Process %d cannot save monitoring in %s.%d.prof\n", world_rank, + filename, world_rank); } MPIT_result = MPI_T_pvar_stop(session, flush_handle); @@ -368,7 +383,7 @@ int main(int argc, char* argv[]) MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - (void)MPI_T_finalize(); + (void) MPI_T_finalize(); } MPI_Comm_free(&newcomm); diff --git a/test/monitoring/test_overhead.c b/test/monitoring/test_overhead.c index 5356761334..72d6f41e6a 100644 --- a/test/monitoring/test_overhead.c +++ b/test/monitoring/test_overhead.c @@ -20,17 +20,17 @@ */ -#include <stdlib.h> +#include "mpi.h" #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <sys/time.h> #include <time.h> -#include <string.h> -#include "mpi.h" -#define NB_ITER 1000 +#define NB_ITER 1000 #define FULL_NB_ITER (size_world * NB_ITER) -#define MAX_SIZE (1024 * 1024 * 1.4) -#define NB_OPS 6 +#define MAX_SIZE (1024 * 1024 * 1.4) +#define NB_OPS 6 static int rank_world = -1; static int size_world = 0; @@ -39,27 +39,27 @@ static int from = -1; static MPI_Win win = MPI_WIN_NULL; /* Sorting results */ -static int comp_double(const void*_a, const void*_b) +static int comp_double(const void *_a, const void *_b) { - const double*a = _a; - const double*b = _b; - if(*a < *b) + const double *a = _a; + const double *b = _b; + if (*a < *b) return -1; - else if(*a > *b) + else if (*a > *b) return 1; else return 0; } /* Timing */ -static inline void get_tick(struct timespec*t) +static inline void get_tick(struct timespec *t) { #if defined(__bg__) -# define CLOCK_TYPE CLOCK_REALTIME +# define CLOCK_TYPE CLOCK_REALTIME #elif defined(CLOCK_MONOTONIC_RAW) -# define CLOCK_TYPE CLOCK_MONOTONIC_RAW +# define CLOCK_TYPE CLOCK_MONOTONIC_RAW #elif defined(CLOCK_MONOTONIC) -# define CLOCK_TYPE CLOCK_MONOTONIC +# define CLOCK_TYPE CLOCK_MONOTONIC #endif #if defined(CLOCK_TYPE) clock_gettime(CLOCK_TYPE, t); @@ -70,24 +70,26 @@ static inline void get_tick(struct timespec*t) t->tv_nsec = tv.tv_usec * 1000; #endif } -static inline double timing_delay(const struct timespec*const t1, const struct timespec*const t2) +static inline double timing_delay(const struct timespec *const t1, const struct timespec *const t2) { - const double delay = 1000000.0 * (t2->tv_sec - t1->tv_sec) + (t2->tv_nsec - t1->tv_nsec) / 1000.0; + const double delay = 1000000.0 * (t2->tv_sec - t1->tv_sec) + + (t2->tv_nsec - t1->tv_nsec) / 1000.0; return delay; } /* Operations */ -static inline void op_send(double*res, void*sbuf, int size, int tagno, void*rbuf) { +static inline void op_send(double *res, void *sbuf, int size, int tagno, void *rbuf) +{ MPI_Request request; struct timespec start, end; /* Post to be sure no unexpected message will be generated */ MPI_Irecv(rbuf, size, MPI_BYTE, from, tagno, MPI_COMM_WORLD, &request); - + /* Token ring to synchronize */ /* We message the sender to make him know we are ready to receive (even for non-eager mode sending) */ - if( 0 == rank_world ) { + if (0 == rank_world) { MPI_Send(NULL, 0, MPI_BYTE, from, 100, MPI_COMM_WORLD); MPI_Recv(NULL, 0, MPI_BYTE, to, 100, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } else { @@ -104,13 +106,14 @@ static inline void op_send(double*res, void*sbuf, int size, int tagno, void*rbuf *res = timing_delay(&start, &end); } -static inline void op_send_pingpong(double*res, void*sbuf, int size, int tagno, void*rbuf) { +static inline void op_send_pingpong(double *res, void *sbuf, int size, int tagno, void *rbuf) +{ struct timespec start, end; MPI_Barrier(MPI_COMM_WORLD); /* do monitored operation */ - if(rank_world % 2) { /* Odd ranks : Recv - Send */ + if (rank_world % 2) { /* Odd ranks : Recv - Send */ MPI_Recv(rbuf, size, MPI_BYTE, from, tagno, MPI_COMM_WORLD, MPI_STATUS_IGNORE); MPI_Send(sbuf, size, MPI_BYTE, from, tagno, MPI_COMM_WORLD); MPI_Barrier(MPI_COMM_WORLD); @@ -131,7 +134,8 @@ static inline void op_send_pingpong(double*res, void*sbuf, int size, int tagno, *res = timing_delay(&start, &end) / 2; } -static inline void op_coll(double*res, void*buff, int size, int tagno, void*rbuf) { +static inline void op_coll(double *res, void *buff, int size, int tagno, void *rbuf) +{ struct timespec start, end; MPI_Barrier(MPI_COMM_WORLD); @@ -143,7 +147,8 @@ static inline void op_coll(double*res, void*buff, int size, int tagno, void*rbuf *res = timing_delay(&start, &end); } -static inline void op_a2a(double*res, void*sbuf, int size, int tagno, void*rbuf) { +static inline void op_a2a(double *res, void *sbuf, int size, int tagno, void *rbuf) +{ struct timespec start, end; MPI_Barrier(MPI_COMM_WORLD); @@ -155,7 +160,8 @@ static inline void op_a2a(double*res, void*sbuf, int size, int tagno, void*rbuf) *res = timing_delay(&start, &end); } -static inline void op_put(double*res, void*sbuf, int size, int tagno, void*rbuf) { +static inline void op_put(double *res, void *sbuf, int size, int tagno, void *rbuf) +{ struct timespec start, end; MPI_Win_lock(MPI_LOCK_EXCLUSIVE, to, 0, win); @@ -169,7 +175,8 @@ static inline void op_put(double*res, void*sbuf, int size, int tagno, void*rbuf) *res = timing_delay(&start, &end); } -static inline void op_get(double*res, void*rbuf, int size, int tagno, void*sbuf) { +static inline void op_get(double *res, void *rbuf, int size, int tagno, void *sbuf) +{ struct timespec start, end; MPI_Win_lock(MPI_LOCK_SHARED, to, 0, win); @@ -183,34 +190,35 @@ static inline void op_get(double*res, void*rbuf, int size, int tagno, void*sbuf) *res = timing_delay(&start, &end); } -static inline void do_bench(int size, char*sbuf, double*results, - void(*op)(double*, void*, int, int, void*)) { +static inline void do_bench(int size, char *sbuf, double *results, + void (*op)(double *, void *, int, int, void *)) +{ int iter; int tagno = 201; - char*rbuf = sbuf ? sbuf + size : NULL; + char *rbuf = sbuf ? sbuf + size : NULL; - if(op == op_put || op == op_get){ - win = MPI_WIN_NULL; - MPI_Win_create(rbuf, size, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); + if (op == op_put || op == op_get) { + win = MPI_WIN_NULL; + MPI_Win_create(rbuf, size, 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win); } - for( iter = 0; iter < NB_ITER; ++iter ) { + for (iter = 0; iter < NB_ITER; ++iter) { op(&results[iter], sbuf, size, tagno, rbuf); MPI_Barrier(MPI_COMM_WORLD); } - if(op == op_put || op == op_get){ - MPI_Win_free(&win); - win = MPI_WIN_NULL; + if (op == op_put || op == op_get) { + MPI_Win_free(&win); + win = MPI_WIN_NULL; } } -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int size, iter, nop; - char*sbuf = NULL; + char *sbuf = NULL; double results[NB_ITER]; - void(*op)(double*, void*, int, int, void*); + void (*op)(double *, void *, int, int, void *); char name[255]; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank_world); @@ -220,8 +228,8 @@ int main(int argc, char* argv[]) double full_res[FULL_NB_ITER]; - for( nop = 0; nop < NB_OPS; ++nop ) { - switch(nop) { + for (nop = 0; nop < NB_OPS; ++nop) { + switch (nop) { case 0: op = op_send; sprintf(name, "MPI_Send"); @@ -248,40 +256,45 @@ int main(int argc, char* argv[]) break; } - if( 0 == rank_world ) - printf("# %s%%%d\n# size \t| latency \t| 10^6 B/s \t| MB/s \t| median \t| q1 \t| q3 \t| d1 \t| d9 \t| avg \t| max\n", name, size_world); + if (0 == rank_world) + printf("# %s%%%d\n# size \t| latency \t| 10^6 B/s \t| MB/s \t| median \t| q1 " + "\t| q3 \t| d1 \t| d9 \t| avg \t| max\n", + name, size_world); - for(size = 0; size < MAX_SIZE; size = ((int)(size * 1.4) > size) ? (size * 1.4) : (size + 1)) { + for (size = 0; size < MAX_SIZE; + size = ((int) (size * 1.4) > size) ? (size * 1.4) : (size + 1)) { /* Init buffers */ - if( 0 != size ) { - sbuf = (char *)realloc(sbuf, (size_world + 1) * size); /* sbuf + alltoall recv buf */ - } + if (0 != size) { + sbuf = (char *) realloc(sbuf, + (size_world + 1) * size); /* sbuf + alltoall recv buf */ + } do_bench(size, sbuf, results, op); - MPI_Gather(results, NB_ITER, MPI_DOUBLE, full_res, NB_ITER, MPI_DOUBLE, 0, MPI_COMM_WORLD); + MPI_Gather(results, NB_ITER, MPI_DOUBLE, full_res, NB_ITER, MPI_DOUBLE, 0, + MPI_COMM_WORLD); - if( 0 == rank_world ) { + if (0 == rank_world) { qsort(full_res, FULL_NB_ITER, sizeof(double), &comp_double); const double min_lat = full_res[0]; const double max_lat = full_res[FULL_NB_ITER - 1]; const double med_lat = full_res[(FULL_NB_ITER - 1) / 2]; - const double q1_lat = full_res[(FULL_NB_ITER - 1) / 4]; - const double q3_lat = full_res[ 3 * (FULL_NB_ITER - 1) / 4]; - const double d1_lat = full_res[(FULL_NB_ITER - 1) / 10]; - const double d9_lat = full_res[ 9 * (FULL_NB_ITER - 1) / 10]; + const double q1_lat = full_res[(FULL_NB_ITER - 1) / 4]; + const double q3_lat = full_res[3 * (FULL_NB_ITER - 1) / 4]; + const double d1_lat = full_res[(FULL_NB_ITER - 1) / 10]; + const double d9_lat = full_res[9 * (FULL_NB_ITER - 1) / 10]; double avg_lat = 0.0; - for( iter = 0; iter < FULL_NB_ITER; iter++ ){ + for (iter = 0; iter < FULL_NB_ITER; iter++) { avg_lat += full_res[iter]; } avg_lat /= FULL_NB_ITER; const double bw_million_byte = size / min_lat; - const double bw_mbyte = bw_million_byte / 1.048576; + const double bw_mbyte = bw_million_byte / 1.048576; - printf("%9lld\t%9.3lf\t%9.3f\t%9.3f\t%9.3lf\t%9.3lf\t%9.3lf\t%9.3lf\t%9.3lf\t%9.3lf\t%9.3lf", - (long long)size, min_lat, bw_million_byte, bw_mbyte, - med_lat, q1_lat, q3_lat, d1_lat, d9_lat, - avg_lat, max_lat); + printf("%9lld\t%9.3lf\t%9.3f\t%9.3f\t%9.3lf\t%9.3lf\t%9.3lf\t%9.3lf\t%9.3lf\t%9." + "3lf\t%9.3lf", + (long long) size, min_lat, bw_million_byte, bw_mbyte, med_lat, q1_lat, + q3_lat, d1_lat, d9_lat, avg_lat, max_lat); printf("\n"); } } diff --git a/test/monitoring/test_pvar_access.c b/test/monitoring/test_pvar_access.c index d035ea388e..8041980a87 100644 --- a/test/monitoring/test_pvar_access.c +++ b/test/monitoring/test_pvar_access.c @@ -41,9 +41,9 @@ I 3 2 20 bytes 4 msgs sent */ -#include <stdlib.h> -#include <stdio.h> #include <mpi.h> +#include <stdio.h> +#include <stdlib.h> static MPI_T_pvar_handle count_handle; static MPI_T_pvar_handle msize_handle; @@ -52,16 +52,16 @@ static const char msize_pvar_name[] = "pml_monitoring_messages_size"; static int count_pvar_idx, msize_pvar_idx; static int world_rank, world_size; -static void print_vars(int rank, int size, size_t* msg_count, size_t*msg_size) +static void print_vars(int rank, int size, size_t *msg_count, size_t *msg_size) { int i; - for(i = 0; i < size; ++i) { - if(0 != msg_size[i]) + for (i = 0; i < size; ++i) { + if (0 != msg_size[i]) printf("I\t%d\t%d\t%zu bytes\t%zu msgs sent\n", rank, i, msg_size[i], msg_count[i]); } } -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size, n, to, from, tagno, MPIT_result, provided, count; MPI_T_pvar_session session; @@ -69,8 +69,8 @@ int main(int argc, char* argv[]) MPI_Comm newcomm; MPI_Comm comm = MPI_COMM_WORLD; MPI_Request request; - size_t*msg_count_p1, *msg_size_p1; - size_t*msg_count_p2, *msg_size_p2; + size_t *msg_count_p1, *msg_size_p1; + size_t *msg_count_p2, *msg_size_p2; /* first phase : make a token circulated in MPI_COMM_WORLD */ n = -1; @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) MPIT_result = MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); if (MPIT_result != MPI_SUCCESS) MPI_Abort(MPI_COMM_WORLD, MPIT_result); - + /* Retrieve the pvar indices */ MPIT_result = MPI_T_pvar_get_index(count_pvar_name, MPI_T_PVAR_CLASS_SIZE, &count_pvar_idx); if (MPIT_result != MPI_SUCCESS) { @@ -104,21 +104,19 @@ int main(int argc, char* argv[]) /* Get session for pvar binding */ MPIT_result = MPI_T_pvar_session_create(&session); if (MPIT_result != MPI_SUCCESS) { - printf("cannot create a session for \"%s\" and \"%s\" pvars\n", - count_pvar_name, msize_pvar_name); + printf("cannot create a session for \"%s\" and \"%s\" pvars\n", count_pvar_name, + msize_pvar_name); MPI_Abort(MPI_COMM_WORLD, MPIT_result); } /* Allocating a new PVAR in a session will reset the counters */ - MPIT_result = MPI_T_pvar_handle_alloc(session, count_pvar_idx, - &comm, &count_handle, &count); + MPIT_result = MPI_T_pvar_handle_alloc(session, count_pvar_idx, &comm, &count_handle, &count); if (MPIT_result != MPI_SUCCESS) { printf("failed to allocate handle on \"%s\" pvar, check that you have monitoring pml\n", count_pvar_name); MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - MPIT_result = MPI_T_pvar_handle_alloc(session, msize_pvar_idx, - &comm, &msize_handle, &count); + MPIT_result = MPI_T_pvar_handle_alloc(session, msize_pvar_idx, &comm, &msize_handle, &count); if (MPIT_result != MPI_SUCCESS) { printf("failed to allocate handle on \"%s\" pvar, check that you have monitoring pml\n", msize_pvar_name); @@ -128,8 +126,8 @@ int main(int argc, char* argv[]) /* Allocate arrays to retrieve results */ msg_count_p1 = calloc(count * 4, sizeof(size_t)); msg_size_p1 = &msg_count_p1[count]; - msg_count_p2 = &msg_count_p1[2*count]; - msg_size_p2 = &msg_count_p1[3*count]; + msg_count_p2 = &msg_count_p1[2 * count]; + msg_size_p2 = &msg_count_p1[3 * count]; /* Start pvar */ MPIT_result = MPI_T_pvar_start(session, count_handle); @@ -144,18 +142,24 @@ int main(int argc, char* argv[]) msize_pvar_name); MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - + if (rank == 0) { n = 25; - MPI_Isend(&n,1,MPI_INT,to,tagno,MPI_COMM_WORLD,&request); + MPI_Isend(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD, &request); } while (1) { MPI_Irecv(&n, 1, MPI_INT, from, tagno, MPI_COMM_WORLD, &request); MPI_Wait(&request, &status); - if (rank == 0) {n--;tagno++;} + if (rank == 0) { + n--; + tagno++; + } MPI_Isend(&n, 1, MPI_INT, to, tagno, MPI_COMM_WORLD, &request); - if (rank != 0) {n--;tagno++;} - if (n<0){ + if (rank != 0) { + n--; + tagno++; + } + if (n < 0) { break; } } @@ -166,7 +170,7 @@ int main(int argc, char* argv[]) printf("failed to stop handle on \"%s\" pvar, check that you have monitoring pml\n", count_pvar_name); MPI_Abort(MPI_COMM_WORLD, MPIT_result); - } + } MPIT_result = MPI_T_pvar_stop(session, msize_handle); if (MPIT_result != MPI_SUCCESS) { printf("failed to stop handle on \"%s\" pvar, check that you have monitoring pml\n", @@ -188,7 +192,7 @@ int main(int argc, char* argv[]) } /* Circulate a token to proper display the results */ - if(0 == world_rank) { + if (0 == world_rank) { printf("Flushing phase 1:\n"); print_vars(world_rank, world_size, msg_count_p1, msg_size_p1); MPI_Send(NULL, 0, MPI_BYTE, (world_rank + 1) % world_size, 300, MPI_COMM_WORLD); @@ -212,7 +216,7 @@ int main(int argc, char* argv[]) msize_pvar_name); MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - + /* Second phase. Work with different communicators. even ranks will circulate a token @@ -230,26 +234,32 @@ int main(int argc, char* argv[]) msize_pvar_name); MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - - MPI_Comm_split(MPI_COMM_WORLD, rank%2, rank, &newcomm); - if(rank%2){ /*even ranks (in COMM_WORD) circulate a token*/ + MPI_Comm_split(MPI_COMM_WORLD, rank % 2, rank, &newcomm); + + if (rank % 2) { /*even ranks (in COMM_WORD) circulate a token*/ MPI_Comm_rank(newcomm, &rank); MPI_Comm_size(newcomm, &size); - if( size > 1 ) { + if (size > 1) { to = (rank + 1) % size; from = (rank - 1) % size; tagno = 201; - if (rank == 0){ + if (rank == 0) { n = 50; MPI_Send(&n, 1, MPI_INT, to, tagno, newcomm); } - while (1){ + while (1) { MPI_Recv(&n, 1, MPI_INT, from, tagno, newcomm, &status); - if (rank == 0) {n--; tagno++;} + if (rank == 0) { + n--; + tagno++; + } MPI_Send(&n, 1, MPI_INT, to, tagno, newcomm); - if (rank != 0) {n--; tagno++;} - if (n<0){ + if (rank != 0) { + n--; + tagno++; + } + if (n < 0) { break; } } @@ -259,8 +269,8 @@ int main(int argc, char* argv[]) int recv_buff[10240]; MPI_Comm_rank(newcomm, &rank); MPI_Comm_size(newcomm, &size); - MPI_Alltoall(send_buff, 10240/size, MPI_INT, recv_buff, 10240/size, MPI_INT, newcomm); - MPI_Comm_split(newcomm, rank%2, rank, &newcomm); + MPI_Alltoall(send_buff, 10240 / size, MPI_INT, recv_buff, 10240 / size, MPI_INT, newcomm); + MPI_Comm_split(newcomm, rank % 2, rank, &newcomm); MPI_Barrier(newcomm); } @@ -278,13 +288,13 @@ int main(int argc, char* argv[]) } /* Taking only in account the second phase */ - for(int i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { msg_count_p2[i] -= msg_count_p1[i]; msg_size_p2[i] -= msg_size_p1[i]; } /* Circulate a token to proper display the results */ - if(0 == world_rank) { + if (0 == world_rank) { printf("Flushing phase 2:\n"); print_vars(world_rank, world_size, msg_count_p2, msg_size_p2); MPI_Send(NULL, 0, MPI_BYTE, (world_rank + 1) % world_size, 300, MPI_COMM_WORLD); @@ -310,15 +320,15 @@ int main(int argc, char* argv[]) MPIT_result = MPI_T_pvar_session_free(&session); if (MPIT_result != MPI_SUCCESS) { - printf("cannot close a session for \"%s\" and \"%s\" pvars\n", - count_pvar_name, msize_pvar_name); + printf("cannot close a session for \"%s\" and \"%s\" pvars\n", count_pvar_name, + msize_pvar_name); MPI_Abort(MPI_COMM_WORLD, MPIT_result); } - (void)MPI_T_finalize(); + (void) MPI_T_finalize(); free(msg_count_p1); - + MPI_Finalize(); return EXIT_SUCCESS; } diff --git a/test/mpi/environment/chello.c b/test/mpi/environment/chello.c index 453a5a1bf9..6f436673b3 100644 --- a/test/mpi/environment/chello.c +++ b/test/mpi/environment/chello.c @@ -22,14 +22,13 @@ #include <mpi.h> #include <stdio.h> -int -main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - MPI_Init(&argc, &argv); + MPI_Init(&argc, &argv); - printf("Hello, World\n"); + printf("Hello, World\n"); - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/test/mpool/mpool_memkind.c b/test/mpool/mpool_memkind.c index d33b0da9ef..d3a3e775dd 100644 --- a/test/mpool/mpool_memkind.c +++ b/test/mpool/mpool_memkind.c @@ -23,41 +23,28 @@ * only do this test if we have built with memkind support */ +#include "opal_config.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> -#include "opal_config.h" +#include <string.h> #ifdef HAVE_MEMKIND_H -#include "opal/constants.h" -#include "opal/align.h" -#include "opal/mca/mpool/mpool.h" -#include "opal/include/opal/frameworks.h" -#include "opal/runtime/opal.h" - -#define SIZE (2 * 1024 * 1024) - -const char *memory_types[] = { - "memkind_default", - "memkind_hbw", - NULL -}; - -const char *memory_policy[] = { - "mempolicy_bind_local", - "mempolicy_bind_all", - "mempolicy_perferred_local", - "mempolicy_interleave_local", - "mempolicy_interleave_all", - NULL -}; - -const char *memory_kind_bits[] = { - "memkind_mask_page_size_4KB", - "memkind_mask_page_size_2MB", - NULL -}; - -int main (int argc, char* argv[]) +# include "opal/align.h" +# include "opal/constants.h" +# include "opal/include/opal/frameworks.h" +# include "opal/mca/mpool/mpool.h" +# include "opal/runtime/opal.h" + +# define SIZE (2 * 1024 * 1024) + +const char *memory_types[] = {"memkind_default", "memkind_hbw", NULL}; + +const char *memory_policy[] = {"mempolicy_bind_local", "mempolicy_bind_all", + "mempolicy_perferred_local", "mempolicy_interleave_local", + "mempolicy_interleave_all", NULL}; + +const char *memory_kind_bits[] = {"memkind_mask_page_size_4KB", "memkind_mask_page_size_2MB", NULL}; + +int main(int argc, char *argv[]) { int ret = 0; void *ptr = NULL; @@ -70,7 +57,7 @@ int main (int argc, char* argv[]) opal_init_util(&argc, &argv); - if (opal_frameworks == NULL){ + if (opal_frameworks == NULL) { error = "opal frameworks is NULL"; goto error; } @@ -100,7 +87,7 @@ int main (int argc, char* argv[]) goto error; } - if (0 != ((uintptr_t)ptr % OPAL_ALIGN_MIN)) { + if (0 != ((uintptr_t) ptr % OPAL_ALIGN_MIN)) { error = "improper memory alignment detected"; goto error; } @@ -109,16 +96,16 @@ int main (int argc, char* argv[]) * now try policies */ - mp_ptr = (char **)memory_policy; + mp_ptr = (char **) memory_policy; while (NULL != *mp_ptr) { - mt_ptr = (char **)memory_types; + mt_ptr = (char **) memory_types; while (NULL != *mt_ptr) { - mk_ptr = (char **)memory_kind_bits; + mk_ptr = (char **) memory_kind_bits; while (NULL != *mk_ptr) { - snprintf(hints, sizeof(hints), "%s,policy=%s,type=%s,kind=%s", - mpool_hints, *mp_ptr, *mt_ptr, *mk_ptr); + snprintf(hints, sizeof(hints), "%s,policy=%s,type=%s,kind=%s", mpool_hints, *mp_ptr, + *mt_ptr, *mk_ptr); ptr = mca_mpool_base_alloc(SIZE, NULL, hints); if (NULL == ptr) { error = "mca_mpool_base_alloc() failed"; @@ -130,7 +117,7 @@ int main (int argc, char* argv[]) goto error; } - if (0 != ((uintptr_t)ptr % OPAL_ALIGN_MIN)) { + if (0 != ((uintptr_t) ptr % OPAL_ALIGN_MIN)) { error = "improper memory alignment detected"; goto error; } @@ -164,7 +151,7 @@ error: return ret; } #else -int main (int argc, char* argv[]) +int main(int argc, char *argv[]) { return 77; } diff --git a/test/runtime/opal_init_finalize.c b/test/runtime/opal_init_finalize.c index 42b4a17927..bf07bc577b 100644 --- a/test/runtime/opal_init_finalize.c +++ b/test/runtime/opal_init_finalize.c @@ -18,11 +18,10 @@ #include "ompi_config.h" -#include "opal/runtime/opal.h" #include "opal/constants.h" +#include "opal/runtime/opal.h" -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int ret; diff --git a/test/runtime/orte_init_finalize.c b/test/runtime/orte_init_finalize.c index b134f0f422..da9c2d3498 100644 --- a/test/runtime/orte_init_finalize.c +++ b/test/runtime/orte_init_finalize.c @@ -19,20 +19,19 @@ #include "orte_config.h" #include "orte/orte_constants.h" - #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> +# include <sys/param.h> #endif #ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> +# include <netinet/in.h> #endif #include "orte/runtime/runtime.h" -int main (int argc, char* argv[]) +int main(int argc, char *argv[]) { int rc; diff --git a/test/runtime/sigchld.c b/test/runtime/sigchld.c index d958a26de1..ea06079329 100644 --- a/test/runtime/sigchld.c +++ b/test/runtime/sigchld.c @@ -18,15 +18,15 @@ #include "ompi_config.h" #include "mpi.h" -#include "orte/runtime/orte_wait.h" #include "opal/runtime/opal_progress.h" +#include "orte/runtime/orte_wait.h" #include "runtime/runtime.h" #ifdef HAVE_SYS_TYPES_H -#include <sys/types.h> +# include <sys/types.h> #endif #ifdef HAVE_UNISTD_H -#include <unistd.h> +# include <unistd.h> #endif #include <stdio.h> #include <stdlib.h> @@ -39,7 +39,6 @@ static void callback(pid_t pid, int status, void *data) count--; } - int main(int argc, char *argv[]) { pid_t pid, ret; diff --git a/test/runtime/start_shut.c b/test/runtime/start_shut.c index c7004bcd77..6eb6e8171b 100644 --- a/test/runtime/start_shut.c +++ b/test/runtime/start_shut.c @@ -19,25 +19,24 @@ #include "orte_config.h" #include "orte/orte_constants.h" - #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> +# include <sys/param.h> #endif #ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> +# include <netinet/in.h> #endif -#include "support.h" #include "orte/runtime/runtime.h" +#include "support.h" #define NUM_ITERS 3 FILE *test_out; -int main (int argc, char* argv[]) +int main(int argc, char *argv[]) { int rc, i; @@ -50,14 +49,16 @@ int main (int argc, char* argv[]) exit(1); } - for (i=0; i < NUM_ITERS; i++) { + for (i = 0; i < NUM_ITERS; i++) { if (ORTE_SUCCESS != (rc = orte_finalize())) { - fprintf(test_out, "iter %d: couldn't complete orte system finalize - error %d\n", i, rc); + fprintf(test_out, "iter %d: couldn't complete orte system finalize - error %d\n", i, + rc); exit(1); } fprintf(test_out, "\tfinalize successful\n"); if (ORTE_SUCCESS != (rc = orte_init(true))) { - fprintf(test_out, "iter %d: couldn't complete orte system init - error code %d\n", i, rc); + fprintf(test_out, "iter %d: couldn't complete orte system init - error code %d\n", i, + rc); exit(1); } } diff --git a/test/simple/abort.c b/test/simple/abort.c index 65f17fddfd..f67e77f5f2 100644 --- a/test/simple/abort.c +++ b/test/simple/abort.c @@ -11,7 +11,7 @@ #include "mpi.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; int errcode; @@ -29,7 +29,7 @@ int main(int argc, char* argv[]) printf("Hello, World, I am %d of %d\n", rank, size); if (1 == size) { - MPI_Abort(MPI_COMM_WORLD, errcode); + MPI_Abort(MPI_COMM_WORLD, errcode); } else { if (1 == rank) { MPI_Abort(MPI_COMM_WORLD, errcode); diff --git a/test/simple/accept.c b/test/simple/accept.c index 3462c7500d..c68866f766 100644 --- a/test/simple/accept.c +++ b/test/simple/accept.c @@ -5,10 +5,10 @@ * Test of connect/accept - the accept (server) side */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; MPI_Info info; diff --git a/test/simple/add_host.c b/test/simple/add_host.c index e008043fe9..e59c4e498d 100644 --- a/test/simple/add_host.c +++ b/test/simple/add_host.c @@ -1,19 +1,19 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/param.h> #include <sys/types.h> #include <unistd.h> -#include <sys/param.h> #include <mpi.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int msg, rc; MPI_Comm parent, child; int rank, size; char hostname[1024]; pid_t pid; - char *env_rank,*env_nspace; + char *env_rank, *env_nspace; MPI_Info info; env_rank = getenv("PMIX_RANK"); @@ -21,7 +21,7 @@ int main(int argc, char* argv[]) pid = getpid(); gethostname(hostname, 1024); - printf("[%s:%s pid %ld] starting up on node %s!\n", env_nspace, env_rank, (long)pid, hostname); + printf("[%s:%s pid %ld] starting up on node %s!\n", env_nspace, env_rank, (long) pid, hostname); MPI_Init(NULL, NULL); MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -31,16 +31,19 @@ int main(int argc, char* argv[]) /* If we get COMM_NULL back, then we're the parent */ if (MPI_COMM_NULL == parent) { if (argc < 3) { - printf("%s requires two arguments (%d)- the name of the first host to add, and the name of the second host to add\n", argv[0], argc); + printf("%s requires two arguments (%d)- the name of the first host to add, and the " + "name of the second host to add\n", + argv[0], argc); exit(1); } pid = getpid(); - printf("Parent [pid %ld] about to spawn!\n", (long)pid); + printf("Parent [pid %ld] about to spawn!\n", (long) pid); MPI_Info_create(&info); MPI_Info_set(info, "PMIX_ADD_HOST", argv[1]); - if (MPI_SUCCESS != (rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, info, - 0, MPI_COMM_WORLD, &child, MPI_ERRCODES_IGNORE))) { + if (MPI_SUCCESS + != (rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, info, 0, MPI_COMM_WORLD, &child, + MPI_ERRCODES_IGNORE))) { printf("Child failed to spawn\n"); return rc; } @@ -56,8 +59,9 @@ int main(int argc, char* argv[]) printf("\n\n\n"); /* do it again */ MPI_Info_set(info, "PMIX_ADD_HOST", argv[2]); - if (MPI_SUCCESS != (rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, info, - 0, MPI_COMM_WORLD, &child, MPI_ERRCODES_IGNORE))) { + if (MPI_SUCCESS + != (rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, info, 0, MPI_COMM_WORLD, &child, + MPI_ERRCODES_IGNORE))) { printf("Child failed to spawn\n"); return rc; } @@ -75,7 +79,7 @@ int main(int argc, char* argv[]) MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); pid = getpid(); - printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid); + printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long) pid); if (0 == rank) { MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE); printf("Child %d received msg: %d\n", rank, msg); diff --git a/test/simple/attach.c b/test/simple/attach.c index adbe00e2de..589736f986 100644 --- a/test/simple/attach.c +++ b/test/simple/attach.c @@ -5,14 +5,14 @@ * The most basic of MPI applications */ +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> -#include <sys/types.h> #include <sys/stat.h> -#include <fcntl.h> +#include <sys/types.h> #include <unistd.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { unsigned char fifo_cmd = 1; int fd; diff --git a/test/simple/bad_arg.c b/test/simple/bad_arg.c index 282b97794a..616f100bbd 100644 --- a/test/simple/bad_arg.c +++ b/test/simple/bad_arg.c @@ -9,22 +9,22 @@ * $HEADER$ */ +#include "mpi.h" #include <stdio.h> #include <unistd.h> -#include "mpi.h" -void errhandler(MPI_Comm* comm, int* err) { +void errhandler(MPI_Comm *comm, int *err) +{ int rank, len = 0; char errstr[MPI_MAX_ERROR_STRING] = {0}; char cname[MPI_MAX_OBJECT_NAME] = {0}; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Error_string(*err, errstr, &len); MPI_Comm_get_name(*comm, cname, &len); - fprintf(stderr, "Rank %02d: The error handler for %s has been invoked with error %d: %s\n\n", rank, cname, *err, errstr); + fprintf(stderr, "Rank %02d: The error handler for %s has been invoked with error %d: %s\n\n", + rank, cname, *err, errstr); } - - int main(int argc, char *argv[]) { int rank, size, i = 5; @@ -38,34 +38,37 @@ int main(int argc, char *argv[]) MPI_Comm_set_errhandler(MPI_COMM_WORLD, errh); MPI_Comm_set_errhandler(MPI_COMM_SELF, errh); - if(0 == rank) { - fprintf(stderr, -"This test will have rank 1 pass an invalid argument to a local MPI call.\n" -"An error handler has been set, so:\n" -" * A high quality implementation should refrain from calling MPI_ERRORS_ARE_FATAL.\n" -" * An MPI-4 compliant implementation should trigger the MPI_COMM_SELF error handler.\n" -" * An MPI-3 compliant implementation should trigger the MPI_COMM_WORLD error handler.\n\n"); + if (0 == rank) { + fprintf( + stderr, + "This test will have rank 1 pass an invalid argument to a local MPI call.\n" + "An error handler has been set, so:\n" + " * A high quality implementation should refrain from calling MPI_ERRORS_ARE_FATAL.\n" + " * An MPI-4 compliant implementation should trigger the MPI_COMM_SELF error " + "handler.\n" + " * An MPI-3 compliant implementation should trigger the MPI_COMM_WORLD error " + "handler.\n\n"); } sleep(1); - if(1 == rank) { + if (1 == rank) { MPI_Type_set_name(MPI_DATATYPE_NULL, "bad type argument"); - } - else { + } else { MPI_Type_set_name(MPI_INT, "good type argument"); } /* The reported error was not 'important' so we expect MPI to remain * operative */ /* progress for some time to see if some error handler gets called */ - while(i-- > 0) { + while (i-- > 0) { MPI_Sendrecv_replace(&size, 1, MPI_INT, 0, 0, 0, 0, MPI_COMM_SELF, MPI_STATUS_IGNORE); sleep(1); - if(0 == rank) fprintf(stderr, "\rWaiting for %2ds", i); + if (0 == rank) + fprintf(stderr, "\rWaiting for %2ds", i); } - if(0 == rank) fprintf(stderr, "\n"); - + if (0 == rank) + fprintf(stderr, "\n"); MPI_Barrier(MPI_COMM_WORLD); fprintf(stderr, "Rank %02d: I have survived till the end of the test.\n", rank); @@ -73,4 +76,3 @@ int main(int argc, char *argv[]) MPI_Finalize(); return 0; } - diff --git a/test/simple/bad_exit.c b/test/simple/bad_exit.c index c319a0ae15..55536714e3 100644 --- a/test/simple/bad_exit.c +++ b/test/simple/bad_exit.c @@ -1,25 +1,24 @@ +#include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> -#include <mpi.h> #define RANK_DEATH 1 int main(int argc, char **argv) { - int rank; - MPI_Init(&argc,&argv); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + int rank; + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); - sleep(2); - if (rank==RANK_DEATH) { - printf("Rank %d exiting without calling finalize...\n", rank); - exit(1); - } - sleep(2); - printf("Rank %d calling MPI_Finalize\n", rank); - MPI_Finalize(); - printf("Rank %d exiting\n", rank); - return 0; + sleep(2); + if (rank == RANK_DEATH) { + printf("Rank %d exiting without calling finalize...\n", rank); + exit(1); + } + sleep(2); + printf("Rank %d calling MPI_Finalize\n", rank); + MPI_Finalize(); + printf("Rank %d exiting\n", rank); + return 0; } - diff --git a/test/simple/badcoll.c b/test/simple/badcoll.c index 0b4bfdc22a..a6210e6cd4 100644 --- a/test/simple/badcoll.c +++ b/test/simple/badcoll.c @@ -1,6 +1,6 @@ +#include "mpi.h" #include <stdio.h> #include <unistd.h> -#include "mpi.h" const int count = 1234; int buffer[1234] = {0}; @@ -13,8 +13,7 @@ int main(int argc, char *argv[]) MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - - for (i=0; i < 1000; i++) { + for (i = 0; i < 1000; i++) { fprintf(stderr, "%d: Executing Bcast #%d\n", rank, i); MPI_Bcast(buffer, count, MPI_INT, 0, MPI_COMM_WORLD); if (0 != rank) { @@ -25,4 +24,3 @@ int main(int argc, char *argv[]) MPI_Finalize(); return 0; } - diff --git a/test/simple/bcast_loop.c b/test/simple/bcast_loop.c index 39f7c49b2d..70dd286c81 100644 --- a/test/simple/bcast_loop.c +++ b/test/simple/bcast_loop.c @@ -1,7 +1,7 @@ #include <mpi.h> #include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int myid, nprocs, tag; int i, m, nt; @@ -33,4 +33,3 @@ int main(int argc, char* argv[]) return 0; } - diff --git a/test/simple/binding.c b/test/simple/binding.c index 36456616e1..eaa4ce3d5c 100644 --- a/test/simple/binding.c +++ b/test/simple/binding.c @@ -6,17 +6,17 @@ */ #define _GNU_SOURCE +#include "mpi.h" +#include "opal/mca/hwloc/base/base.h" +#include "opal/runtime/opal.h" +#include <sched.h> #include <stdio.h> #include <sys/types.h> #include <unistd.h> -#include <sched.h> -#include "opal/mca/hwloc/base/base.h" -#include "opal/runtime/opal.h" -#include "mpi.h" #include "orte/util/proc_info.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size, rc; hwloc_cpuset_t cpus; @@ -39,20 +39,20 @@ int main(int argc, char* argv[]) } printf("[%s;%d] Hello, World, I am %d of %d [%d local peers]: get_cpubind: %d bitmap %s\n", - hostname, (int)getpid(), rank, size, orte_process_info.num_local_peers, rc, + hostname, (int) getpid(), rank, size, orte_process_info.num_local_peers, rc, (NULL == bindings) ? "NULL" : bindings); nrcpus = sysconf(_SC_NPROCESSORS_ONLN); mask = CPU_ALLOC(nrcpus); csize = CPU_ALLOC_SIZE(nrcpus); CPU_ZERO_S(csize, mask); - if ( sched_getaffinity(0, csize, mask) == -1 ) { + if (sched_getaffinity(0, csize, mask) == -1) { perror("sched_getaffinity"); } else { - for ( c = 0; c < nrcpus; c++ ) { - if ( CPU_ISSET_S(c, csize, mask) ) { - printf("[%s:%d] CPU %d is set\n", hostname, (int)getpid(), c); - } + for (c = 0; c < nrcpus; c++) { + if (CPU_ISSET_S(c, csize, mask)) { + printf("[%s:%d] CPU %d is set\n", hostname, (int) getpid(), c); + } } } diff --git a/test/simple/client.c b/test/simple/client.c index c79ebc9def..daf3d831a0 100644 --- a/test/simple/client.c +++ b/test/simple/client.c @@ -1,37 +1,38 @@ +#include "mpi.h" #include <stdio.h> #include <stdlib.h> #include <string.h> -#include "mpi.h" #define MAX_DATA 100 -int main( int argc, char **argv ) +int main(int argc, char **argv) { - MPI_Comm server; - double buf[MAX_DATA]; - char port_name[MPI_MAX_PORT_NAME]; - int done = 0, tag, n, CNT=0; - - MPI_Init( &argc, &argv ); - strcpy(port_name, argv[1] ); /* assume server's name is cmd-line arg */ - - MPI_Comm_connect( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &server ); - - n = MAX_DATA; - - while (!done) - { - tag = 2; /* Action to perform */ - if ( CNT == 5 ) { tag = 0; done = 1; } - fprintf(stderr, "Client sending message %d\n", CNT); - MPI_Send( buf, n, MPI_DOUBLE, 0, tag, server ); - CNT++; - /* etc */ - } - - MPI_Comm_disconnect( &server ); - MPI_Finalize(); - - return 0; + MPI_Comm server; + double buf[MAX_DATA]; + char port_name[MPI_MAX_PORT_NAME]; + int done = 0, tag, n, CNT = 0; + + MPI_Init(&argc, &argv); + strcpy(port_name, argv[1]); /* assume server's name is cmd-line arg */ + + MPI_Comm_connect(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &server); + + n = MAX_DATA; + + while (!done) { + tag = 2; /* Action to perform */ + if (CNT == 5) { + tag = 0; + done = 1; + } + fprintf(stderr, "Client sending message %d\n", CNT); + MPI_Send(buf, n, MPI_DOUBLE, 0, tag, server); + CNT++; + /* etc */ + } + + MPI_Comm_disconnect(&server); + MPI_Finalize(); + + return 0; } - diff --git a/test/simple/comm_abort.c b/test/simple/comm_abort.c index 7acb8fad4b..d42a721b6a 100644 --- a/test/simple/comm_abort.c +++ b/test/simple/comm_abort.c @@ -11,14 +11,15 @@ * Test aborting communicators */ +#include "mpi.h" #include <stdio.h> #include <unistd.h> -#include "mpi.h" -#define print1(format...) if(0 == rank) printf(format) +#define print1(format...) \ + if (0 == rank) \ + printf(format) - -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size, more; double start, now; @@ -28,72 +29,76 @@ int main(int argc, char* argv[]) MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - if(0 == rank && size%2) { + if (0 == rank && size % 2) { fprintf(stderr, "This test requires an even number of processes\n\n"); MPI_Abort(MPI_COMM_WORLD, size); } /* Setup: split our world in a set of 2-processes islands */ - MPI_Comm_split(MPI_COMM_WORLD, rank/2, rank, &comm_pair_fatal); + MPI_Comm_split(MPI_COMM_WORLD, rank / 2, rank, &comm_pair_fatal); MPI_Comm_set_errhandler(comm_pair_fatal, MPI_ERRORS_ARE_FATAL); - MPI_Comm_split(MPI_COMM_WORLD, rank/2, rank, &comm_pair_return); + MPI_Comm_split(MPI_COMM_WORLD, rank / 2, rank, &comm_pair_return); MPI_Comm_set_errhandler(comm_pair_return, MPI_ERRORS_RETURN); - MPI_Comm_split(MPI_COMM_WORLD, rank/2, rank, &comm_pair_abort); - /* If this code fails to compile, the MPI implementation is not compliant + MPI_Comm_split(MPI_COMM_WORLD, rank / 2, rank, &comm_pair_abort); + /* If this code fails to compile, the MPI implementation is not compliant * with MPI-4 (TODO: add ref to chapter/line when MPI-4 published). */ MPI_Comm_set_errhandler(comm_pair_abort, MPI_ERRORS_ABORT); MPI_Barrier(MPI_COMM_WORLD); - print1( -"This program will test partial abort functionality (communicator scoped abort).\n" -" Each test will perform a loop of communication on a subcommunicator for about\n" -" 1 second between printouts, and then, a 1 second cooldown.\n"); + print1("This program will test partial abort functionality (communicator scoped abort).\n" + " Each test will perform a loop of communication on a subcommunicator for about\n" + " 1 second between printouts, and then, a 1 second cooldown.\n"); print1("\n\n" -"Test1: MPI_Abort(MPI_COMM_SELF) aborts only one process?\n" -" In a high quality implementation, all ranks except %d\n" -" should report their presence.\n", 1); - if(rank == 1) { + "Test1: MPI_Abort(MPI_COMM_SELF) aborts only one process?\n" + " In a high quality implementation, all ranks except %d\n" + " should report their presence.\n", + 1); + if (rank == 1) { MPI_Abort(MPI_COMM_SELF, 1); } /* Spin on communication for 1 second to let time for Abort to have an * effect, if any. */ - more = 1; start = MPI_Wtime(); + more = 1; + start = MPI_Wtime(); do { now = MPI_Wtime(); - if(now - start > 1.) more = 0; - if(rank > 1) /* don't reduce on aborted pairs */ + if (now - start > 1.) + more = 0; + if (rank > 1) /* don't reduce on aborted pairs */ MPI_Allreduce(MPI_IN_PLACE, &more, 1, MPI_INT, MPI_MIN, comm_pair_fatal); - } while(more); + } while (more); printf(" This is rank %d: still kickin after %d MPI_Abort'ed self\n", rank, 1); sleep(1); print1("===============================================================\n"); print1("\n\n" -"Test2: MPI_Abort(comm) aborts all processes in comm?\n" -" In a high quality implementation, all ranks except %d--%d\n" -" should report their presence.\n", 1, 3); - if(rank == 3) { + "Test2: MPI_Abort(comm) aborts all processes in comm?\n" + " In a high quality implementation, all ranks except %d--%d\n" + " should report their presence.\n", + 1, 3); + if (rank == 3) { MPI_Abort(comm_pair_return, 2); } /* Spin on communication for 1 second to let time for Abort to have an * effect, if any. */ - more = 1; start = MPI_Wtime(); + more = 1; + start = MPI_Wtime(); do { now = MPI_Wtime(); - if(now - start > 1.) more = 0; - if(rank > 3) /* don't reduce on aborted pairs */ + if (now - start > 1.) + more = 0; + if (rank > 3) /* don't reduce on aborted pairs */ MPI_Allreduce(MPI_IN_PLACE, &more, 1, MPI_INT, MPI_MIN, comm_pair_fatal); - } while(more); + } while (more); printf(" This is rank %d: still kickin after %d aborted comm pair %d-%d\n", rank, 3, 2, 3); /* This process should have aborted, give it an opportunity to do so if no * async progress: message to self to spin MPI progress. */ - if(rank == 2) { - MPI_Sendrecv(&start, 1, MPI_DOUBLE, 0, 0, - &now, 1, MPI_DOUBLE, 0, 0, - MPI_COMM_SELF, MPI_STATUS_IGNORE); + if (rank == 2) { + MPI_Sendrecv(&start, 1, MPI_DOUBLE, 0, 0, &now, 1, MPI_DOUBLE, 0, 0, MPI_COMM_SELF, + MPI_STATUS_IGNORE); printf(" This is rank %d: ERROR: I SHOULD HAVE ABORTED!\n", 2); } @@ -101,70 +106,75 @@ int main(int argc, char* argv[]) print1("===============================================================\n"); print1("\n\n" -"Test3: MPI_ERRORS_ABORT aborts all processes in comm?\n" -" In a high quality implementation, all ranks except %d--%d\n" -" should report their presence.\n", 1, 5); - if(rank == 5) { + "Test3: MPI_ERRORS_ABORT aborts all processes in comm?\n" + " In a high quality implementation, all ranks except %d--%d\n" + " should report their presence.\n", + 1, 5); + if (rank == 5) { MPI_Comm_call_errhandler(comm_pair_abort, 3); } /* Spin on communication for 1 second to let time for Abort to have an * effect, if any. */ - more = 1; start = MPI_Wtime(); + more = 1; + start = MPI_Wtime(); do { now = MPI_Wtime(); - if(now - start > 1.) more = 0; - if(rank > 5) /* don't reduce on aborted pairs */ + if (now - start > 1.) + more = 0; + if (rank > 5) /* don't reduce on aborted pairs */ MPI_Allreduce(MPI_IN_PLACE, &more, 1, MPI_INT, MPI_MIN, comm_pair_fatal); - } while(more); + } while (more); printf(" This is rank %d: still kickin after %d aborted comm pair %d-%d\n", rank, 5, 4, 5); /* This process should have aborted, give it an opportunity to do so if no * async progress: message to self to spin MPI progress. */ - if(rank == 4) { - MPI_Sendrecv(&start, 1, MPI_DOUBLE, 0, 0, - &now, 1, MPI_DOUBLE, 0, 0, - MPI_COMM_SELF, MPI_STATUS_IGNORE); + if (rank == 4) { + MPI_Sendrecv(&start, 1, MPI_DOUBLE, 0, 0, &now, 1, MPI_DOUBLE, 0, 0, MPI_COMM_SELF, + MPI_STATUS_IGNORE); printf(" This is rank %d: ERROR: I SHOULD HAVE ABORTED!\n", 4); } sleep(1); print1("===============================================================\n"); - print1("\n\n"\ -"Test4: Communicating with an aborted process %d returns a good error code?\n" -" In a high quality implementation, rank %d should print an error string;\n" -" In a higher quality implementation the error should be of class\n" -" MPI_ERR_PROC_ABORTED.\n", 1, 0); - if(rank == 0) { + print1("\n\n" + "Test4: Communicating with an aborted process %d returns a good error code?\n" + " In a high quality implementation, rank %d should print an error string;\n" + " In a higher quality implementation the error should be of class\n" + " MPI_ERR_PROC_ABORTED.\n", + 1, 0); + if (rank == 0) { int err, class, slen; char str[MPI_MAX_ERROR_STRING]; /* remember, 1 aborted in test1 */ MPI_Error_class(err, &class); MPI_Error_string(err, str, &slen); err = MPI_Recv(&more, 1, MPI_INT, 1, 0, comm_pair_return, MPI_STATUS_IGNORE); - printf(" This is rank %d: Recv(from=%d) returned code=%d: class=%d: %s\n", 0, 1, err, class, str); + printf(" This is rank %d: Recv(from=%d) returned code=%d: class=%d: %s\n", 0, 1, err, + class, str); } sleep(1); print1("===============================================================\n"); print1("\n\n" -"Test5: MPI_ERRORS_ARE_FATAL aborts all processes?\n"); - if(rank == 0) { + "Test5: MPI_ERRORS_ARE_FATAL aborts all processes?\n"); + if (rank == 0) { MPI_Comm_call_errhandler(comm_pair_fatal, 5); } /* Spin on communication for 1 second to let time for Abort to have an * effect, if any. */ - more = 1; start = MPI_Wtime(); + more = 1; + start = MPI_Wtime(); do { now = MPI_Wtime(); - if(now - start > 1.) more = 0; - if(rank > 5) /* don't reduce on aborted pairs */ + if (now - start > 1.) + more = 0; + if (rank > 5) /* don't reduce on aborted pairs */ MPI_Allreduce(MPI_IN_PLACE, &more, 1, MPI_INT, MPI_MIN, comm_pair_fatal); - } while(more); - MPI_Sendrecv(&start, 1, MPI_DOUBLE, 0, 0, - &now, 1, MPI_DOUBLE, 0, 0, - MPI_COMM_SELF, MPI_STATUS_IGNORE); + } while (more); + MPI_Sendrecv(&start, 1, MPI_DOUBLE, 0, 0, &now, 1, MPI_DOUBLE, 0, 0, MPI_COMM_SELF, + MPI_STATUS_IGNORE); printf(" This is rank %d: ERROR: I SHOULD HAVE ABORTED!\n", rank); /* Should never get there */ diff --git a/test/simple/concurrent_spawn.c b/test/simple/concurrent_spawn.c index 3c2eefbc7d..e2e5eb3fa9 100644 --- a/test/simple/concurrent_spawn.c +++ b/test/simple/concurrent_spawn.c @@ -4,22 +4,22 @@ #include "opal/runtime/opal.h" #include <stdio.h> +#include <stdlib.h> #include <sys/types.h> #include <unistd.h> -#include <stdlib.h> #include <mpi.h> #define NUM_CHILDREN 5 -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int msg; MPI_Comm parent, children[NUM_CHILDREN]; int rank, size, i; const char *hostname; pid_t pid; - char *child_argv[2] = { "", NULL }; + char *child_argv[2] = {"", NULL}; MPI_Init(NULL, NULL); MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -32,11 +32,9 @@ int main(int argc, char* argv[]) /* First, spawn all the children. Give them an argv identifying which child they are */ for (i = 0; i < NUM_CHILDREN; ++i) { - printf("Parent [pid %ld] about to spawn child #%d\n", - (long)pid, i); + printf("Parent [pid %ld] about to spawn child #%d\n", (long) pid, i); opal_asprintf(&(child_argv[0]), "%d", i); - MPI_Comm_spawn(argv[0], child_argv, 1, MPI_INFO_NULL, - 0, MPI_COMM_WORLD, &children[i], + MPI_Comm_spawn(argv[0], child_argv, 1, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &children[i], MPI_ERRCODES_IGNORE); printf("Parent done with spawn of child %d\n", i); } @@ -66,13 +64,12 @@ int main(int argc, char* argv[]) i = atoi(argv[1]); } pid = getpid(); - printf("Hello from the child %d on host %s pid %ld\n", i, hostname, (long)pid); + printf("Hello from the child %d on host %s pid %ld\n", i, hostname, (long) pid); if (0 == rank) { MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE); printf("Child %d received msg: %d\n", i, msg); if (i != msg) { - printf("ERROR: Child %d got wrong message (got %d, expected %d)\n", - i, msg, i); + printf("ERROR: Child %d got wrong message (got %d, expected %d)\n", i, msg, i); } } MPI_Comm_disconnect(&parent); diff --git a/test/simple/connect.c b/test/simple/connect.c index 2de897eb40..ed9bb47bc4 100644 --- a/test/simple/connect.c +++ b/test/simple/connect.c @@ -5,10 +5,10 @@ * Test of connect/accept - the accept (server) side */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; MPI_Comm server; diff --git a/test/simple/crisscross.c b/test/simple/crisscross.c index 993b15423f..50668d69bd 100644 --- a/test/simple/crisscross.c +++ b/test/simple/crisscross.c @@ -2,272 +2,252 @@ cc -o crisscross crisscross.c -lmpi */ +#include "mpi.h" #include <stdio.h> #include <stdlib.h> -#include "mpi.h" -#include <unistd.h> #include <string.h> #include <time.h> +#include <unistd.h> #define MAX_RR_NAME 7 int main(int argc, char *argv[]) { - MPI_Status status; /* MPI status */ - int mpierr; /* MPI function return code */ - int rank; /* Process rank within MPI_COMM_WORLD */ - int nproc; /* Total number of MPI processes */ - int tag0=41; /* MPI message tag */ - int tag1=42; /* MPI message tag */ - int tag2=43; /* MPI message tag */ - int warmup=1; /* MPI warmup loops */ - - char process_name[MPI_MAX_PROCESSOR_NAME + 1]; - char partner_name[MPI_MAX_PROCESSOR_NAME + 1]; - - char rr_blank[] = {" "}; - char rr_empty[] = {"???????"}; - - int n_bytes=128*1024*1024; - int n_loops=2; - unsigned char* send_buff; - unsigned char* recv_buff; - - int i,j,k,m,count,mismatch; - - double et1,et2,mbs; - double avg_mbs=0, sum_avg_mbs=0; - int xfers=0, sum_xfers=0; - double max_mbs=-1.0,min_mbs=999999.9; - double r_max_mbs,r_min_mbs; - - time_t curtime; - struct tm *loctime; - - if ( argc > 2 ) - { - n_loops = atoi(argv[2]); - n_loops = n_loops < 1 ? 10 : n_loops; - } - if ( argc > 1 ) - { - n_bytes = atoi(argv[1]); - n_bytes = n_bytes < 1 ? 32768 : n_bytes; - } - - send_buff = (unsigned char *) valloc(n_bytes); - recv_buff = (unsigned char *) valloc(n_bytes); - - for ( i=0; i<n_bytes; i++ ) - { - send_buff[i] = i%128; - } - - mpierr = MPI_Init(&argc, &argv); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr, "MPI Error %d (MPI_Init)\n",mpierr); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - - MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN); - - mpierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (mpierr != MPI_SUCCESS || rank < 0) - { - fprintf(stderr, "MPI Error %d (MPI_Comm_rank)\n",mpierr); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - - if ( rank == 0 ) - { - curtime = time (NULL); - loctime = localtime (&curtime); - printf("\n %s\n",asctime (loctime)); - } - - mpierr = MPI_Comm_size(MPI_COMM_WORLD, &nproc); - if (mpierr != MPI_SUCCESS || nproc < 1 || nproc <= rank) - { - fprintf(stderr, "MPI Error %d (MPI_Comm_size) [%d]\n",mpierr, rank); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - - mpierr = MPI_Get_processor_name(process_name, &count); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Get_processor_name) [%d]\n", mpierr, rank); - sprintf(process_name, "%s", rr_empty); - } - else - { - if (count < MAX_RR_NAME) strncat(&process_name[count],rr_blank,MAX_RR_NAME-count); - process_name[MAX_RR_NAME] = '\0'; - } - - for ( i=0; i<nproc; i++ ) - { - mpierr = MPI_Barrier(MPI_COMM_WORLD); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr, "MPI Error %d (MPI_Barrier) [%d]\n", mpierr, rank); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - for ( j=0; j<nproc; j++ ) - { - if ( i != j ) - { - if (rank == j) - { - mpierr = MPI_Sendrecv(process_name, MPI_MAX_PROCESSOR_NAME + 1, MPI_CHAR, i, tag0, - partner_name, MPI_MAX_PROCESSOR_NAME + 1, MPI_CHAR, i, tag0, MPI_COMM_WORLD, &status); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Sendrecv) %s [%d,%d]\n",mpierr,process_name,rank,i); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - for ( k=0; k<n_bytes; k++ ) - { - recv_buff[k] = 0x80; - } - } - if ( rank == i ) - { - mpierr = MPI_Sendrecv(process_name, MPI_MAX_PROCESSOR_NAME + 1, MPI_CHAR, j, tag0, - partner_name, MPI_MAX_PROCESSOR_NAME + 1, MPI_CHAR, j, tag0, MPI_COMM_WORLD, &status); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Sendrecv) %s [%d,%d]\n",mpierr,process_name,i,j); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - } - for ( k=0; k<n_loops+warmup; k++ ) - { - if ( rank == i ) - { - if (k == warmup) et1 = MPI_Wtime(); - mpierr = MPI_Send(send_buff, n_bytes, MPI_BYTE, j, tag1, MPI_COMM_WORLD); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Send) %s [4%d] --> %s [4%d]\n",mpierr,process_name,i,partner_name,j); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - } - if ( rank == j ) - { - mpierr = MPI_Recv(recv_buff, n_bytes, MPI_BYTE, i, tag1, MPI_COMM_WORLD, &status); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Recv) %s [4%d] <-- %s [4%d]\n",mpierr,process_name,j,partner_name,i); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - if (k == n_loops+warmup-1) et2 = MPI_Wtime(); - } - } - if ( rank == i ) - { - mpierr = MPI_Send(&et1, 1, MPI_DOUBLE, j, tag1, MPI_COMM_WORLD); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Send) %s [4%d] --> %s [4%d]\n",mpierr,process_name,i,partner_name,j); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - } - if ( rank == j ) - { - mpierr = MPI_Recv(&et1, 1, MPI_DOUBLE, i, tag1, MPI_COMM_WORLD, &status); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Recv) %s [4%d] <-- %s [4%d]\n",mpierr,process_name,j,partner_name,i); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - mbs = ((double)n_loops*n_bytes)/(1000000.0*(et2-et1)); - if (mbs < 50.0) - { - printf(" %s [%4d] =====>> %s [%4d] %9.1f mbs SLOW!\n",partner_name,i,process_name,j,mbs); - } - else - { - printf(" %s [%4d] =====>> %s [%4d] %9.1f mbs\n",partner_name,i,process_name,j,mbs); - } - - min_mbs = (mbs < min_mbs) ? mbs:min_mbs; - max_mbs = (mbs > max_mbs) ? mbs:max_mbs; - - avg_mbs += mbs; - xfers++; - mismatch = 0; - for ( k=0; k<n_bytes; k++ ) - { - if ( recv_buff[k] != k%128 ) mismatch++; - } - if ( mismatch ) printf(" WARNING! %d data mismatches\n",mismatch); - fflush(stdout); + MPI_Status status; /* MPI status */ + int mpierr; /* MPI function return code */ + int rank; /* Process rank within MPI_COMM_WORLD */ + int nproc; /* Total number of MPI processes */ + int tag0 = 41; /* MPI message tag */ + int tag1 = 42; /* MPI message tag */ + int tag2 = 43; /* MPI message tag */ + int warmup = 1; /* MPI warmup loops */ + + char process_name[MPI_MAX_PROCESSOR_NAME + 1]; + char partner_name[MPI_MAX_PROCESSOR_NAME + 1]; + + char rr_blank[] = {" "}; + char rr_empty[] = {"???????"}; + + int n_bytes = 128 * 1024 * 1024; + int n_loops = 2; + unsigned char *send_buff; + unsigned char *recv_buff; + + int i, j, k, m, count, mismatch; + + double et1, et2, mbs; + double avg_mbs = 0, sum_avg_mbs = 0; + int xfers = 0, sum_xfers = 0; + double max_mbs = -1.0, min_mbs = 999999.9; + double r_max_mbs, r_min_mbs; + + time_t curtime; + struct tm *loctime; + + if (argc > 2) { + n_loops = atoi(argv[2]); + n_loops = n_loops < 1 ? 10 : n_loops; + } + if (argc > 1) { + n_bytes = atoi(argv[1]); + n_bytes = n_bytes < 1 ? 32768 : n_bytes; + } + + send_buff = (unsigned char *) valloc(n_bytes); + recv_buff = (unsigned char *) valloc(n_bytes); + + for (i = 0; i < n_bytes; i++) { + send_buff[i] = i % 128; + } + + mpierr = MPI_Init(&argc, &argv); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Init)\n", mpierr); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN); + + mpierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank); + if (mpierr != MPI_SUCCESS || rank < 0) { + fprintf(stderr, "MPI Error %d (MPI_Comm_rank)\n", mpierr); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + if (rank == 0) { + curtime = time(NULL); + loctime = localtime(&curtime); + printf("\n %s\n", asctime(loctime)); + } + + mpierr = MPI_Comm_size(MPI_COMM_WORLD, &nproc); + if (mpierr != MPI_SUCCESS || nproc < 1 || nproc <= rank) { + fprintf(stderr, "MPI Error %d (MPI_Comm_size) [%d]\n", mpierr, rank); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + mpierr = MPI_Get_processor_name(process_name, &count); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Get_processor_name) [%d]\n", mpierr, rank); + sprintf(process_name, "%s", rr_empty); + } else { + if (count < MAX_RR_NAME) + strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); + process_name[MAX_RR_NAME] = '\0'; + } + + for (i = 0; i < nproc; i++) { + mpierr = MPI_Barrier(MPI_COMM_WORLD); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Barrier) [%d]\n", mpierr, rank); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + for (j = 0; j < nproc; j++) { + if (i != j) { + if (rank == j) { + mpierr = MPI_Sendrecv(process_name, MPI_MAX_PROCESSOR_NAME + 1, MPI_CHAR, i, + tag0, partner_name, MPI_MAX_PROCESSOR_NAME + 1, MPI_CHAR, + i, tag0, MPI_COMM_WORLD, &status); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Sendrecv) %s [%d,%d]\n", mpierr, + process_name, rank, i); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + for (k = 0; k < n_bytes; k++) { + recv_buff[k] = 0x80; + } + } + if (rank == i) { + mpierr = MPI_Sendrecv(process_name, MPI_MAX_PROCESSOR_NAME + 1, MPI_CHAR, j, + tag0, partner_name, MPI_MAX_PROCESSOR_NAME + 1, MPI_CHAR, + j, tag0, MPI_COMM_WORLD, &status); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Sendrecv) %s [%d,%d]\n", mpierr, + process_name, i, j); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + } + for (k = 0; k < n_loops + warmup; k++) { + if (rank == i) { + if (k == warmup) + et1 = MPI_Wtime(); + mpierr = MPI_Send(send_buff, n_bytes, MPI_BYTE, j, tag1, MPI_COMM_WORLD); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Send) %s [4%d] --> %s [4%d]\n", + mpierr, process_name, i, partner_name, j); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + } + if (rank == j) { + mpierr = MPI_Recv(recv_buff, n_bytes, MPI_BYTE, i, tag1, MPI_COMM_WORLD, + &status); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Recv) %s [4%d] <-- %s [4%d]\n", + mpierr, process_name, j, partner_name, i); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + if (k == n_loops + warmup - 1) + et2 = MPI_Wtime(); + } + } + if (rank == i) { + mpierr = MPI_Send(&et1, 1, MPI_DOUBLE, j, tag1, MPI_COMM_WORLD); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Send) %s [4%d] --> %s [4%d]\n", mpierr, + process_name, i, partner_name, j); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + } + if (rank == j) { + mpierr = MPI_Recv(&et1, 1, MPI_DOUBLE, i, tag1, MPI_COMM_WORLD, &status); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Recv) %s [4%d] <-- %s [4%d]\n", mpierr, + process_name, j, partner_name, i); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + mbs = ((double) n_loops * n_bytes) / (1000000.0 * (et2 - et1)); + if (mbs < 50.0) { + printf(" %s [%4d] =====>> %s [%4d] %9.1f mbs SLOW!\n", + partner_name, i, process_name, j, mbs); + } else { + printf(" %s [%4d] =====>> %s [%4d] %9.1f mbs\n", partner_name, i, + process_name, j, mbs); + } + + min_mbs = (mbs < min_mbs) ? mbs : min_mbs; + max_mbs = (mbs > max_mbs) ? mbs : max_mbs; + + avg_mbs += mbs; + xfers++; + mismatch = 0; + for (k = 0; k < n_bytes; k++) { + if (recv_buff[k] != k % 128) + mismatch++; + } + if (mismatch) + printf(" " + "WARNING! %d data mismatches\n", + mismatch); + fflush(stdout); + } } - } - } - } - - mpierr = MPI_Reduce(&xfers, &sum_xfers, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Reduce) %s [%d]\n",mpierr,process_name,rank); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - - mpierr = MPI_Reduce(&avg_mbs, &sum_avg_mbs, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Reduce) %s [%d]\n",mpierr,process_name,rank); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - - mpierr = MPI_Reduce(&min_mbs, &r_min_mbs, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Reduce) %s [%d]\n",mpierr,process_name,rank); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } + } + } + + mpierr = MPI_Reduce(&xfers, &sum_xfers, 1, MPI_INT, MPI_SUM, 0, MPI_COMM_WORLD); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Reduce) %s [%d]\n", mpierr, process_name, rank); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + mpierr = MPI_Reduce(&avg_mbs, &sum_avg_mbs, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Reduce) %s [%d]\n", mpierr, process_name, rank); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + mpierr = MPI_Reduce(&min_mbs, &r_min_mbs, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Reduce) %s [%d]\n", mpierr, process_name, rank); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + mpierr = MPI_Reduce(&max_mbs, &r_max_mbs, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Reduce) %s [%d]\n", mpierr, process_name, rank); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } + + mpierr = MPI_Finalize(); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Finalize) %s [%d]\n", mpierr, process_name, rank); + fflush(stderr); + MPI_Abort(MPI_COMM_WORLD, -1); + } - mpierr = MPI_Reduce(&max_mbs, &r_max_mbs, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Reduce) %s [%d]\n",mpierr,process_name,rank); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - - mpierr = MPI_Finalize(); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Finalize) %s [%d]\n",mpierr,process_name,rank); - fflush(stderr); - MPI_Abort(MPI_COMM_WORLD, -1); - } - - fflush(stdout); - - if ( rank == 0 ) - { - mbs = sum_avg_mbs/sum_xfers; - printf("\n average tranfer rate for %d transfers: %9.1f mbs\n",sum_xfers, mbs); - printf(" minimum tranfer rate for %d transfers: %9.1f mbs\n",sum_xfers, r_min_mbs); - printf(" maximum tranfer rate for %d transfers: %9.1f mbs\n",sum_xfers, r_max_mbs); fflush(stdout); - } - return 0; + if (rank == 0) { + mbs = sum_avg_mbs / sum_xfers; + printf("\n average tranfer rate for %d transfers: %9.1f mbs\n", sum_xfers, mbs); + printf(" minimum tranfer rate for %d transfers: %9.1f mbs\n", sum_xfers, r_min_mbs); + printf(" maximum tranfer rate for %d transfers: %9.1f mbs\n", sum_xfers, r_max_mbs); + fflush(stdout); + } + + return 0; } diff --git a/test/simple/debugger.c b/test/simple/debugger.c index 3cecd4b58d..0bb5119bd8 100644 --- a/test/simple/debugger.c +++ b/test/simple/debugger.c @@ -9,22 +9,23 @@ #include <stdio.h> #include <unistd.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - int i, rc, j=0; + int i, rc, j = 0; double pi; pid_t pid; pid = getpid(); - printf("spin: Pid %ld\n", (long)pid); + printf("spin: Pid %ld\n", (long) pid); i = 0; while (0 == j) { i++; pi = i / 3.14159256; - if (i > 100) i = 0; + if (i > 100) + i = 0; } return 0; diff --git a/test/simple/delayed_abort.c b/test/simple/delayed_abort.c index 572b2a30f4..41f9a5d324 100644 --- a/test/simple/delayed_abort.c +++ b/test/simple/delayed_abort.c @@ -9,11 +9,11 @@ #include "opal/runtime/opal.h" +#include "mpi.h" #include <stdio.h> #include <unistd.h> -#include "mpi.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; const char *hostname; @@ -25,7 +25,7 @@ int main(int argc, char* argv[]) hostname = opal_gethostname(); printf("%s: I am %d of %d. pid=%d\n", hostname, rank, size, getpid()); - if (rank%3 == 0) { + if (rank % 3 == 0) { printf("%s: rank %d aborts\n", hostname, rank); if (rank == 3) { printf("%s: rank %d is going to sleep\n", hostname, rank); diff --git a/test/simple/early_abort.c b/test/simple/early_abort.c index a3aed65dcd..5398fa4a7b 100644 --- a/test/simple/early_abort.c +++ b/test/simple/early_abort.c @@ -5,13 +5,13 @@ * The most basic of MPI applications */ +#include "mpi.h" #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> -#include "mpi.h" +#include <unistd.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; char *rk; diff --git a/test/simple/hello.c b/test/simple/hello.c index f1bd7fd3e2..0c8bf34c2e 100644 --- a/test/simple/hello.c +++ b/test/simple/hello.c @@ -5,11 +5,10 @@ * The most basic of MPI applications */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> - -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; diff --git a/test/simple/hello_barrier.c b/test/simple/hello_barrier.c index de8bdf7ce1..eba0697428 100644 --- a/test/simple/hello_barrier.c +++ b/test/simple/hello_barrier.c @@ -5,10 +5,10 @@ * The most basic of MPI applications */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; diff --git a/test/simple/hello_nodename.c b/test/simple/hello_nodename.c index b3c87e977a..6528e4c8f3 100644 --- a/test/simple/hello_nodename.c +++ b/test/simple/hello_nodename.c @@ -12,12 +12,12 @@ #include "opal/runtime/opal.h" #include <stdio.h> -#include <unistd.h> #include <stdlib.h> +#include <unistd.h> #include "mpi.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; const char *hostname; @@ -36,17 +36,18 @@ int main(int argc, char* argv[]) if (NULL == appnum) { opal_asprintf(&appstr, "UNDEFINED"); } else { - opal_asprintf(&appstr, "%d", *(int*)appnum); + opal_asprintf(&appstr, "%d", *(int *) appnum); } MPI_Comm_get_attr(MPI_COMM_WORLD, MPI_UNIVERSE_SIZE, &univ_size, &flag); if (NULL == univ_size) { opal_asprintf(&unistr, "UNDEFINED"); } else { - opal_asprintf(&unistr, "%d", *(int*)univ_size); + opal_asprintf(&unistr, "%d", *(int *) univ_size); } hostname = opal_gethostname(); - printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s universe envar %s\n", + printf("Hello, World, I am %d of %d on host %s from app number %s universe size %s universe " + "envar %s\n", rank, size, hostname, appstr, unistr, (NULL == envar) ? "NULL" : envar); MPI_Finalize(); diff --git a/test/simple/hello_output.c b/test/simple/hello_output.c index 950e31eb24..ee384d9d88 100644 --- a/test/simple/hello_output.c +++ b/test/simple/hello_output.c @@ -6,12 +6,11 @@ */ #include "opal_config.h" -#include <stdio.h> #include "mpi.h" #include "opal/util/output.h" +#include <stdio.h> - -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; int stream, stream2; diff --git a/test/simple/hello_show_help.c b/test/simple/hello_show_help.c index d133c8b6cf..468008e3fb 100644 --- a/test/simple/hello_show_help.c +++ b/test/simple/hello_show_help.c @@ -7,14 +7,14 @@ #include "opal_config.h" -#include <stdio.h> -#include <unistd.h> #include "mpi.h" #include "opal/util/output.h" +#include <stdio.h> +#include <unistd.h> #include "orte/util/show_help.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; int stream; @@ -24,28 +24,38 @@ int main(int argc, char* argv[]) MPI_Comm_size(MPI_COMM_WORLD, &size); if (0 == rank) { - opal_output(0, "============================================================================"); - opal_output(0, "This test ensures that the aggregation functionality of the orte_show_help\nsystem is working properly. It outputs a bogus warning about orte_init(),\nand contains sleep statements to ensure that the timer is firiing properly\nin the HNP and aggregates messages properly. The total sleep time is\n(3 * num_procs). You should see:\n\n - aggregation messages from the HNP every five seconds or so\n - a total of (2 * num_procs) messages"); - opal_output(0, "============================================================================"); + opal_output(0, + "============================================================================"); + opal_output( + 0, "This test ensures that the aggregation functionality of the orte_show_help\nsystem " + "is working properly. It outputs a bogus warning about orte_init(),\nand contains " + "sleep statements to ensure that the timer is firiing properly\nin the HNP and " + "aggregates messages properly. The total sleep time is\n(3 * num_procs). You " + "should see:\n\n - aggregation messages from the HNP every five seconds or so\n - a " + "total of (2 * num_procs) messages"); + opal_output(0, + "============================================================================"); } MPI_Barrier(MPI_COMM_WORLD); - orte_show_help("help-orte-runtime.txt", - "orte_init:startup:internal-failure", true, - "Nothing", "ORTE_EVERYTHING_IS_PEACHY", "42"); + orte_show_help("help-orte-runtime.txt", "orte_init:startup:internal-failure", true, "Nothing", + "ORTE_EVERYTHING_IS_PEACHY", "42"); sleep(rank * 3); - orte_show_help("help-orte-runtime.txt", - "orte_init:startup:internal-failure", true, - "Duplicate orte_show_help detection", - "ORTE_SHOW_HELP_DUPLICATE_FAILED", "99999"); + orte_show_help("help-orte-runtime.txt", "orte_init:startup:internal-failure", true, + "Duplicate orte_show_help detection", "ORTE_SHOW_HELP_DUPLICATE_FAILED", + "99999"); MPI_Barrier(MPI_COMM_WORLD); if (0 == rank) { - opal_output(0, "============================================================================"); - opal_output(0, "The test is now complete. Please verify that the HNP output all the required\nmessages (you may see 1 or 2 more messages from the HNP after this message)."); - opal_output(0, "============================================================================"); + opal_output(0, + "============================================================================"); + opal_output(0, "The test is now complete. Please verify that the HNP output all the " + "required\nmessages (you may see 1 or 2 more messages from the HNP after " + "this message)."); + opal_output(0, + "============================================================================"); } MPI_Finalize(); diff --git a/test/simple/info_spawn.c b/test/simple/info_spawn.c index b75efc1d34..1003938bc0 100644 --- a/test/simple/info_spawn.c +++ b/test/simple/info_spawn.c @@ -3,14 +3,14 @@ #include "opal/runtime/opal.h" #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <sys/types.h> #include <unistd.h> -#include <string.h> -#include <stdlib.h> #include <mpi.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int msg, rc, i; MPI_Comm parent, child; @@ -34,9 +34,9 @@ int main(int argc, char* argv[]) } pid = getpid(); - printf("Parent [pid %ld] about to spawn!\n", (long)pid); + printf("Parent [pid %ld] about to spawn!\n", (long) pid); MPI_Info_create(&info); - for (i=1; i < argc; i++) { + for (i = 1; i < argc; i++) { tmp = strdup(argv[i]); keyval = strchr(tmp, ':'); if (NULL == keyval) { @@ -49,8 +49,9 @@ int main(int argc, char* argv[]) MPI_Info_set(info, tmp, keyval); free(tmp); } - if (MPI_SUCCESS != (rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, info, - 0, MPI_COMM_WORLD, &child, MPI_ERRCODES_IGNORE))) { + if (MPI_SUCCESS + != (rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, info, 0, MPI_COMM_WORLD, &child, + MPI_ERRCODES_IGNORE))) { printf("Child failed to spawn\n"); return rc; } @@ -69,7 +70,7 @@ int main(int argc, char* argv[]) MPI_Comm_size(MPI_COMM_WORLD, &size); hostname = opal_gethostname(); pid = getpid(); - printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid); + printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long) pid); if (0 == rank) { MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE); printf("Child %d received msg: %d\n", rank, msg); diff --git a/test/simple/init-exit77.c b/test/simple/init-exit77.c index 81c2b37f4d..b0fb0f2e7e 100644 --- a/test/simple/init-exit77.c +++ b/test/simple/init-exit77.c @@ -1,13 +1,14 @@ +#include "mpi.h" #include <stdio.h> #include <stdlib.h> -#include "mpi.h" -int main(int argc, char **argv) { - int debugme = 1; +int main(int argc, char **argv) +{ + int debugme = 1; - MPI_Init(&argc, &argv); - printf("init...\n"); - fflush(0); - MPI_Finalize(); - exit(77); + MPI_Init(&argc, &argv); + printf("init...\n"); + fflush(0); + MPI_Finalize(); + exit(77); } diff --git a/test/simple/initial_errh.c b/test/simple/initial_errh.c index 27adbd6ce0..7e86de9778 100644 --- a/test/simple/initial_errh.c +++ b/test/simple/initial_errh.c @@ -9,26 +9,30 @@ * $HEADER$ */ +#include "mpi.h" #include <stdio.h> #include <string.h> #include <unistd.h> -#include "mpi.h" -#define print1(format...) if(0 == rank) printf(format) +#define print1(format...) \ + if (0 == rank) \ + printf(format) int main_child(int argc, char *argv[]); int main(int argc, char *argv[]) { - int rank=MPI_PROC_NULL, rc; + int rank = MPI_PROC_NULL, rc; /* info_env and error handlers */ - char init_errh_info[MPI_MAX_INFO_VAL+1]; int flag; + char init_errh_info[MPI_MAX_INFO_VAL + 1]; + int flag; MPI_Errhandler errh; /* error ops */ - int eclass=MPI_SUCCESS; - char estr[MPI_MAX_ERROR_STRING]="NOT UPDATED"; int slen; + int eclass = MPI_SUCCESS; + char estr[MPI_MAX_ERROR_STRING] = "NOT UPDATED"; + int slen; /* spawn params */ - char* spawn_argv[3]; + char *spawn_argv[3]; MPI_Info spawn_info; int spawn_err[2] = {MPI_SUCCESS}; MPI_Comm icomm = MPI_COMM_NULL; @@ -36,7 +40,7 @@ int main(int argc, char *argv[]) /* We will verify pre-init behavior in a spawnee to avoid aborting early in * implementations with only partial support. */ - if(argc > 1 && 0 == strcmp(argv[1], "preinit-error")) { + if (argc > 1 && 0 == strcmp(argv[1], "preinit-error")) { return main_child(argc, argv); } @@ -45,42 +49,43 @@ int main(int argc, char *argv[]) MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); - print1( -"# This test checks compliance with MPI-4 initial error handler.\n" -"# This test assumes that the command line parameter '-initial-errhandler mpi_errors_return'\n" -"# is passed to 'mpiexec', in which case, a compliant implementation will:\n" -"# * Set the MPI_INFO_ENV key to the requested error handler.\n" -"# * The requested handler is set on the predefined communicators MPI_COMM_SELF, MPI_COMM_WORLD,\n" -"# and the communicator returned from MPI_COMM_GET_PARENT.\n" -"# In a high quality implementation:\n" -"# * Errors reported from calls during, before, and after MPI_INIT and MPI_FINALIZE also invoke the\n" -"# initial error handler.\n" -"# * MPI_ERROR_STRING and MPI_ERROR_CLASS provide useful information before/after MPI_INIT and\n" -"# MPI_FINALIZE respectively.\n\n"); + print1("# This test checks compliance with MPI-4 initial error handler.\n" + "# This test assumes that the command line parameter '-initial-errhandler " + "mpi_errors_return'\n" + "# is passed to 'mpiexec', in which case, a compliant implementation will:\n" + "# * Set the MPI_INFO_ENV key to the requested error handler.\n" + "# * The requested handler is set on the predefined communicators MPI_COMM_SELF, " + "MPI_COMM_WORLD,\n" + "# and the communicator returned from MPI_COMM_GET_PARENT.\n" + "# In a high quality implementation:\n" + "# * Errors reported from calls during, before, and after MPI_INIT and MPI_FINALIZE " + "also invoke the\n" + "# initial error handler.\n" + "# * MPI_ERROR_STRING and MPI_ERROR_CLASS provide useful information before/after " + "MPI_INIT and\n" + "# MPI_FINALIZE respectively.\n\n"); print1("MPI_INFO_ENV for key 'mpi_initial_errhandler'\n"); MPI_Info_get(MPI_INFO_ENV, "mpi_initial_errhandler", MPI_MAX_INFO_VAL, init_errh_info, &flag); - if(flag) { - print1(" MPI-4 COMPLIANT:\tMPI_INFO_ENV value set for key 'mpi_initial_errhandler' = %s\n\n", init_errh_info); - } - else { - print1(" NOT MPI-4 COMPLIANT:\tMPI_INFO_ENV has no value set for key 'mpi_initial_errhandler'\n\n"); + if (flag) { + print1( + " MPI-4 COMPLIANT:\tMPI_INFO_ENV value set for key 'mpi_initial_errhandler' = %s\n\n", + init_errh_info); + } else { + print1(" NOT MPI-4 COMPLIANT:\tMPI_INFO_ENV has no value set for key " + "'mpi_initial_errhandler'\n\n"); } print1("MPI_COMM_GET_ERRHANDLER:\n"); MPI_Comm_get_errhandler(MPI_COMM_SELF, &errh); - if(MPI_ERRORS_RETURN == errh) { + if (MPI_ERRORS_RETURN == errh) { print1(" MPI-4 COMPLIANT:\tMPI_COMM_SELF error handler set to MPI_ERRORS_RETURN.\n\n"); - } - else - if(MPI_ERRORS_ABORT == errh) { + } else if (MPI_ERRORS_ABORT == errh) { print1(" UNEXPECTED:\tMPI_COMM_SELF error handler set to MPI_ERRORS_ABORT.\n\n"); - } - else - if(MPI_ERRORS_ARE_FATAL == errh) { - print1(" NOT MPI-4 COMPLIANT:\tMPI_COMM_SELF error handler set to MPI_ERRORS_ARE_FATAL.\n\n"); - } - else { + } else if (MPI_ERRORS_ARE_FATAL == errh) { + print1( + " NOT MPI-4 COMPLIANT:\tMPI_COMM_SELF error handler set to MPI_ERRORS_ARE_FATAL.\n\n"); + } else { print1(" UNEXPECTED:\tMPI_COMM_SELF error handler is not one of the predefined ones.\n\n"); } @@ -101,15 +106,17 @@ int main(int argc, char *argv[]) /* set error handler to fatal before FINALIZE */ rc = MPI_Comm_set_errhandler(MPI_COMM_SELF, MPI_ERRORS_ARE_FATAL); - if(MPI_SUCCESS != rc) { + if (MPI_SUCCESS != rc) { MPI_Error_string(rc, estr, &slen); - fprintf(stderr, " UNEXPECTED: An error occured during MPI_COMM_SETERRHANDLER(SELF) rc=%d: %s\n", rc, estr); + fprintf(stderr, + " UNEXPECTED: An error occured during MPI_COMM_SETERRHANDLER(SELF) rc=%d: %s\n", + rc, estr); return rc; } /* FINALIZE should force reversion to the initial errhandler, so we need to * check again (though we did not insert errors so all should go smooth). */ rc = MPI_Finalize(); - if(MPI_SUCCESS != rc) { + if (MPI_SUCCESS != rc) { MPI_Error_string(rc, estr, &slen); fprintf(stderr, " UNEXPECTED: An error occured during MPI_FINALIZE rc=%d: %s\n", rc, estr); return rc; @@ -117,13 +124,16 @@ int main(int argc, char *argv[]) printf("Post-finalize MPI_ERROR_STRING call:\n"); rc = MPI_Error_string(MPI_ERR_WIN, estr, &slen); - if(MPI_SUCCESS != rc) { - fprintf(stderr, " NOT MPI-4 COMPLIANT:\tpost-finalize MPI_ERROR_STRING returned %d (expected MPI_SUCCESS)\n", rc); - } - else if(0 == strcmp(estr, "NOT UPDATED")) { - fprintf(stderr, " NOT MPI-4 COMPLIANT:\tpost-finalize MPI_ERROR_STRING did not set a valid string.\n"); - } - else { + if (MPI_SUCCESS != rc) { + fprintf(stderr, + " NOT MPI-4 COMPLIANT:\tpost-finalize MPI_ERROR_STRING returned %d (expected " + "MPI_SUCCESS)\n", + rc); + } else if (0 == strcmp(estr, "NOT UPDATED")) { + fprintf( + stderr, + " NOT MPI-4 COMPLIANT:\tpost-finalize MPI_ERROR_STRING did not set a valid string.\n"); + } else { /* We can't further check if the error string makes sense; In any * case, any string is compliant, even low-quality non-informative * generic strings. So we just print it. */ @@ -132,35 +142,42 @@ int main(int argc, char *argv[]) return 0; } -int main_child(int argc, char *argv[]) { - int rank=0, rc; - MPI_Comm icomm=MPI_COMM_NULL; - int eclass=MPI_SUCCESS; - char estr[MPI_MAX_ERROR_STRING]="NOT UPDATED"; int slen; +int main_child(int argc, char *argv[]) +{ + int rank = 0, rc; + MPI_Comm icomm = MPI_COMM_NULL; + int eclass = MPI_SUCCESS; + char estr[MPI_MAX_ERROR_STRING] = "NOT UPDATED"; + int slen; /* ERROR_CLASS and ERROR_STRING are callable before MPI_INIT */ printf("Pre-init MPI_ERROR_CLASS call:\n"); rc = MPI_Error_class(MPI_ERR_WIN, &eclass); - if(MPI_SUCCESS != rc) { - fprintf(stderr, " NOT MPI-4 COMPLIANT:\tpre-init MPI_ERROR_CLASS returned %d (expected MPI_SUCCESS)\n", rc); - } - else if(MPI_ERR_WIN != eclass) { - fprintf(stderr, " NOT MPI-4 COMPLIANT:\tpre-init MPI_ERROR_CLASS set eclass=%d (expected %d)\n", eclass, MPI_ERR_WIN); - } - else { + if (MPI_SUCCESS != rc) { + fprintf( + stderr, + " NOT MPI-4 COMPLIANT:\tpre-init MPI_ERROR_CLASS returned %d (expected MPI_SUCCESS)\n", + rc); + } else if (MPI_ERR_WIN != eclass) { + fprintf(stderr, + " NOT MPI-4 COMPLIANT:\tpre-init MPI_ERROR_CLASS set eclass=%d (expected %d)\n", + eclass, MPI_ERR_WIN); + } else { printf(" MPI-4 COMPLIANT:\tPre-init MPI_ERROR_CLASS\n"); } print1("Pre-init MPI_ERROR_STRING call:\n"); rc = MPI_Error_string(MPI_ERR_WIN, estr, &slen); - if(MPI_SUCCESS != rc) { - fprintf(stderr, " NOT MPI-4 COMPLIANT:\tpre-init MPI_ERROR_STRING returned %d (expected MPI_SUCCESS)\n", rc); - } - else if(0 == strcmp(estr, "NOT UPDATED")) { - fprintf(stderr, " NOT MPI-4 COMPLIANT:\tpre-init MPI_ERROR_STRING did not set a valid string.\n"); - } - else { + if (MPI_SUCCESS != rc) { + fprintf(stderr, + " NOT MPI-4 COMPLIANT:\tpre-init MPI_ERROR_STRING returned %d (expected " + "MPI_SUCCESS)\n", + rc); + } else if (0 == strcmp(estr, "NOT UPDATED")) { + fprintf(stderr, + " NOT MPI-4 COMPLIANT:\tpre-init MPI_ERROR_STRING did not set a valid string.\n"); + } else { /* We can't further check if the error string makes sense; In any * case, any string is compliant, even low-quality non-informative * generic strings. So we just print it. */ @@ -168,19 +185,22 @@ int main_child(int argc, char *argv[]) { } printf("Pre-init error in a call: compliant if it does not abort\n"); - rc = MPI_Error_class(MPI_ERR_LASTCODE+1, &eclass); + rc = MPI_Error_class(MPI_ERR_LASTCODE + 1, &eclass); eclass = rc; rc = MPI_Error_string(eclass, estr, &slen); - if(MPI_SUCCESS != rc) { - printf(" MPI-4 COMPLIANT:\tPre-init MPI_ERROR_CLASS with erroneous arguments returned (LOW QUALITY: error code=%d caused error %d in MPI_ERROR_STRING).\n", eclass, rc); - } - else { - printf(" MPI-4 COMPLIANT:\tPre-init MPI_ERROR_STRING for non-existing code returned %d: %s\n", eclass, estr); + if (MPI_SUCCESS != rc) { + printf(" MPI-4 COMPLIANT:\tPre-init MPI_ERROR_CLASS with erroneous arguments returned " + "(LOW QUALITY: error code=%d caused error %d in MPI_ERROR_STRING).\n", + eclass, rc); + } else { + printf( + " MPI-4 COMPLIANT:\tPre-init MPI_ERROR_STRING for non-existing code returned %d: %s\n", + eclass, estr); } printf("Initializing MPI and setting error handlers on predefined communicators.\n"); rc = MPI_Init(&argc, &argv); - if(MPI_SUCCESS != rc) { + if (MPI_SUCCESS != rc) { MPI_Error_string(rc, estr, &slen); fprintf(stderr, " UNEXPECTED: An error occured during MPI_INIT rc=%d: %s\n", rc, estr); return rc; @@ -189,9 +209,11 @@ int main_child(int argc, char *argv[]) { /* sync-up with parent */ MPI_Comm_get_parent(&icomm); rc = MPI_Comm_set_errhandler(icomm, MPI_ERRORS_ARE_FATAL); - if(MPI_SUCCESS != rc) { + if (MPI_SUCCESS != rc) { MPI_Error_string(rc, estr, &slen); - fprintf(stderr, " UNEXPECTED: An error occured during MPI_COMM_SETERRHANDLER(PARENT) rc=%d: %s\n", rc, estr); + fprintf(stderr, + " UNEXPECTED: An error occured during MPI_COMM_SETERRHANDLER(PARENT) rc=%d: %s\n", + rc, estr); return rc; } MPI_Barrier(icomm); diff --git a/test/simple/intercomm1.c b/test/simple/intercomm1.c index 8c01d3aef2..bd2eeb408e 100644 --- a/test/simple/intercomm1.c +++ b/test/simple/intercomm1.c @@ -1,25 +1,23 @@ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> - -int main( int argc, char *argv[] ) +int main(int argc, char *argv[]) { MPI_Status status; - MPI_Comm comm,scomm; - int rank, size, color, errs=0; - MPI_Init( 0, 0 ); - MPI_Comm_rank( MPI_COMM_WORLD, &rank ); + MPI_Comm comm, scomm; + int rank, size, color, errs = 0; + MPI_Init(0, 0); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); color = rank % 2; printf("%d Calling split\n", rank); - MPI_Comm_split( MPI_COMM_WORLD, color, rank, &scomm ); + MPI_Comm_split(MPI_COMM_WORLD, color, rank, &scomm); printf("%d Calling Intercomm_create\n", rank); - MPI_Intercomm_create( scomm, 0, MPI_COMM_WORLD, 1-color, 1, &comm); + MPI_Intercomm_create(scomm, 0, MPI_COMM_WORLD, 1 - color, 1, &comm); printf("%d Completet\n", rank); - MPI_Comm_rank( comm, &rank ); - MPI_Comm_remote_size( comm, &size ); + MPI_Comm_rank(comm, &rank); + MPI_Comm_remote_size(comm, &size); MPI_Comm_free(&scomm); MPI_Comm_free(&comm); MPI_Finalize(); return errs; } - diff --git a/test/simple/intercomm_create.c b/test/simple/intercomm_create.c index 8e76958a21..8a8c39d1b3 100644 --- a/test/simple/intercomm_create.c +++ b/test/simple/intercomm_create.c @@ -1,8 +1,8 @@ #define _GNU_SOURCE +#include <stdarg.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <stdarg.h> #include <unistd.h> #include <mpi.h> @@ -10,39 +10,38 @@ #define NB_SPAWN 4 static void do_parent(char *argv[], int rank, int count); -static void do_target(char* argv[], MPI_Comm parent); +static void do_target(char *argv[], MPI_Comm parent); static char *cmd_argv1 = "b"; static char *cmd_argv2 = "c"; static char *whoami = "a"; static int tag = 201; -void ompitest_warning( char* filename, int lineno, const char* fmt, ... ) +void ompitest_warning(char *filename, int lineno, const char *fmt, ...) { - char* buf = NULL; + char *buf = NULL; va_list va_list; va_start(va_list, fmt); - vasprintf( &buf, fmt, va_list ); + vasprintf(&buf, fmt, va_list); va_end(va_list); - printf( "*warning* %s:%d %s\n", filename, lineno, buf ); + printf("*warning* %s:%d %s\n", filename, lineno, buf); free(buf); } -void ompitest_error( char* filename, int lineno, const char* fmt, ... ) +void ompitest_error(char *filename, int lineno, const char *fmt, ...) { - char* buf = NULL; + char *buf = NULL; va_list va_list; va_start(va_list, fmt); - vasprintf( &buf, fmt, va_list ); + vasprintf(&buf, fmt, va_list); va_end(va_list); - printf( "*error* %s:%d %s\n", filename, lineno, buf ); + printf("*error* %s:%d %s\n", filename, lineno, buf); free(buf); } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int rank, size; MPI_Comm parent; @@ -71,58 +70,55 @@ main(int argc, char *argv[]) return 0; } -static int -spawn_and_merge( char* argv[], char* arg, int count, - MPI_Comm* inter, MPI_Comm* intra ) +static int spawn_and_merge(char *argv[], char *arg, int count, MPI_Comm *inter, MPI_Comm *intra) { int *errcode, err, i; char *spawn_argv[2]; errcode = malloc(sizeof(int) * count); if (errcode == NULL) - ompitest_error(__FILE__, __LINE__, "Doh! Rank %d was not able to allocate enough memory. MPI test aborted!\n", 0); + ompitest_error(__FILE__, __LINE__, + "Doh! Rank %d was not able to allocate enough memory. MPI test aborted!\n", + 0); memset(errcode, -1, count); /*MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN);*/ spawn_argv[0] = arg; spawn_argv[1] = NULL; - err = MPI_Comm_spawn(argv[0], spawn_argv, count, MPI_INFO_NULL, 0, - MPI_COMM_WORLD, inter, errcode); + err = MPI_Comm_spawn(argv[0], spawn_argv, count, MPI_INFO_NULL, 0, MPI_COMM_WORLD, inter, + errcode); for (i = 0; i < count; i++) if (errcode[i] != MPI_SUCCESS) - ompitest_error(__FILE__, __LINE__, - "ERROR: MPI_Comm_spawn returned errcode[%d] = %d\n", + ompitest_error(__FILE__, __LINE__, "ERROR: MPI_Comm_spawn returned errcode[%d] = %d\n", i, errcode[i]); if (err != MPI_SUCCESS) - ompitest_error(__FILE__, __LINE__, - "ERROR: MPI_Comm_spawn returned errcode = %d\n", err); - err = MPI_Intercomm_merge( *inter, 0, intra ); + ompitest_error(__FILE__, __LINE__, "ERROR: MPI_Comm_spawn returned errcode = %d\n", err); + err = MPI_Intercomm_merge(*inter, 0, intra); free(errcode); return err; } -static void -do_parent(char *argv[], int rank, int count) +static void do_parent(char *argv[], int rank, int count) { MPI_Comm ab_inter, ab_intra, ac_inter, ac_intra, ab_c_inter, abc_intra; int err; - err = spawn_and_merge( argv, cmd_argv1, count, &ab_inter, &ab_intra ); - err = spawn_and_merge( argv, cmd_argv2, count, &ac_inter, &ac_intra ); + err = spawn_and_merge(argv, cmd_argv1, count, &ab_inter, &ab_intra); + err = spawn_and_merge(argv, cmd_argv2, count, &ac_inter, &ac_intra); - printf( "%s: MPI_Intercomm_create( ab_intra, 0, ac_intra, %d, %d, &inter) (%d)\n", - whoami, count, tag, err ); - err = MPI_Intercomm_create( ab_intra, 0, ac_intra, count, tag, &ab_c_inter ); - printf( "%s: intercomm_create (%d)\n", whoami, err ); + printf("%s: MPI_Intercomm_create( ab_intra, 0, ac_intra, %d, %d, &inter) (%d)\n", whoami, count, + tag, err); + err = MPI_Intercomm_create(ab_intra, 0, ac_intra, count, tag, &ab_c_inter); + printf("%s: intercomm_create (%d)\n", whoami, err); - printf( "%s: barrier on inter-comm - before\n", whoami ); + printf("%s: barrier on inter-comm - before\n", whoami); err = MPI_Barrier(ab_c_inter); - printf( "%s: barrier on inter-comm - after\n", whoami ); + printf("%s: barrier on inter-comm - after\n", whoami); err = MPI_Intercomm_merge(ab_c_inter, 0, &abc_intra); - printf( "%s: intercomm_merge(%d) (%d) [rank %d]\n", whoami, 0, err, rank ); + printf("%s: intercomm_merge(%d) (%d) [rank %d]\n", whoami, 0, err, rank); err = MPI_Barrier(abc_intra); - printf( "%s: barrier (%d)\n", whoami, err ); + printf("%s: barrier (%d)\n", whoami, err); MPI_Comm_free(&abc_intra); MPI_Comm_free(&ab_c_inter); @@ -133,38 +129,39 @@ do_parent(char *argv[], int rank, int count) MPI_Comm_disconnect(&ac_inter); } - -static void -do_target(char* argv[], MPI_Comm parent) +static void do_target(char *argv[], MPI_Comm parent) { int rank, first = 0, err; MPI_Comm intra, inter, merge1; - if( 0 == strcmp(argv[1], cmd_argv1) ) first = 1; + if (0 == strcmp(argv[1], cmd_argv1)) + first = 1; /*MPI_Comm_set_errhandler(parent, MPI_ERRORS_RETURN);*/ - err = MPI_Intercomm_merge( parent, 1, &intra ); + err = MPI_Intercomm_merge(parent, 1, &intra); MPI_Comm_rank(intra, &rank); - if( first ) { - printf( "%s: MPI_Intercomm_create( intra, 0, intra, MPI_COMM_NULL, %d, &inter) [rank %d]\n", whoami, tag, rank ); - err = MPI_Intercomm_create( intra, 0, MPI_COMM_NULL, 0, tag, &inter); - printf( "%s: intercomm_create (%d)\n", whoami, err ); + if (first) { + printf("%s: MPI_Intercomm_create( intra, 0, intra, MPI_COMM_NULL, %d, &inter) [rank %d]\n", + whoami, tag, rank); + err = MPI_Intercomm_create(intra, 0, MPI_COMM_NULL, 0, tag, &inter); + printf("%s: intercomm_create (%d)\n", whoami, err); } else { - printf( "%s: MPI_Intercomm_create( MPI_COMM_WORLD, 0, intra, 0, %d, &inter) [rank %d]\n", whoami, tag, rank ); - err = MPI_Intercomm_create( MPI_COMM_WORLD, 0, intra, 0, tag, &inter); - printf( "%s: intercomm_create (%d)\n", whoami, err ); + printf("%s: MPI_Intercomm_create( MPI_COMM_WORLD, 0, intra, 0, %d, &inter) [rank %d]\n", + whoami, tag, rank); + err = MPI_Intercomm_create(MPI_COMM_WORLD, 0, intra, 0, tag, &inter); + printf("%s: intercomm_create (%d)\n", whoami, err); } - printf( "%s: barrier on inter-comm - before\n", whoami ); + printf("%s: barrier on inter-comm - before\n", whoami); err = MPI_Barrier(inter); - printf( "%s: barrier on inter-comm - after\n", whoami ); + printf("%s: barrier on inter-comm - after\n", whoami); - err = MPI_Intercomm_merge( inter, 0, &merge1 ); + err = MPI_Intercomm_merge(inter, 0, &merge1); MPI_Comm_rank(merge1, &rank); - printf( "%s: intercomm_merge(%d) (%d) [rank %d]\n", whoami, first, err, rank ); + printf("%s: intercomm_merge(%d) (%d) [rank %d]\n", whoami, first, err, rank); err = MPI_Barrier(merge1); - printf( "%s: barrier (%d)\n", whoami, err ); + printf("%s: barrier (%d)\n", whoami, err); MPI_Comm_free(&merge1); MPI_Comm_free(&inter); diff --git a/test/simple/interlib.c b/test/simple/interlib.c index fefec2b238..470eb3e313 100644 --- a/test/simple/interlib.c +++ b/test/simple/interlib.c @@ -5,31 +5,27 @@ * The most basic of MPI applications */ -#include <stdio.h> #include <pthread.h> +#include <stdio.h> -#include "opal/mca/hwloc/base/base.h" #include "mpi.h" +#include "opal/mca/hwloc/base/base.h" -#include "orte/util/proc_info.h" #include "opal/mca/pmix/base/base.h" +#include "orte/util/proc_info.h" static size_t interlibhandler_id = SIZE_MAX; static opal_pmix_lock_t thread_complete; -static void model_registration_callback(int status, - size_t errhandler_ref, - void *cbdata) +static void model_registration_callback(int status, size_t errhandler_ref, void *cbdata) { - opal_pmix_lock_t *lock = (opal_pmix_lock_t*)cbdata; + opal_pmix_lock_t *lock = (opal_pmix_lock_t *) cbdata; interlibhandler_id = errhandler_ref; OPAL_PMIX_WAKEUP_THREAD(lock); } -static void model_callback(int status, - const opal_process_name_t *source, - opal_list_t *info, opal_list_t *results, - opal_pmix_notification_complete_fn_t cbfunc, +static void model_callback(int status, const opal_process_name_t *source, opal_list_t *info, + opal_list_t *results, opal_pmix_notification_complete_fn_t cbfunc, void *cbdata) { opal_value_t *val; @@ -37,9 +33,9 @@ static void model_callback(int status, /* we can ignore our own callback as we obviously * know that we are OpenMP */ if (NULL != info) { - OPAL_LIST_FOREACH(val, info, opal_value_t) { - if (0 == strcmp(val->key, OPAL_PMIX_PROGRAMMING_MODEL) && - 0 == strcmp(val->data.string, "OpenMP")) { + OPAL_LIST_FOREACH (val, info, opal_value_t) { + if (0 == strcmp(val->key, OPAL_PMIX_PROGRAMMING_MODEL) + && 0 == strcmp(val->data.string, "OpenMP")) { goto cback; } if (PMIX_STRING == val->type) { @@ -49,7 +45,7 @@ static void model_callback(int status, } /* otherwise, do something clever here */ - cback: +cback: /* we must NOT tell the event handler state machine that we * are the last step as that will prevent it from notifying * anyone else that might be listening for declarations */ @@ -61,20 +57,17 @@ static void model_callback(int status, static void opcbfunc(int status, void *cbdata) { - opal_pmix_lock_t *lock = (opal_pmix_lock_t*)cbdata; + opal_pmix_lock_t *lock = (opal_pmix_lock_t *) cbdata; OPAL_PMIX_WAKEUP_THREAD(lock); } -static void infocb(int status, - opal_list_t *info, - void *cbdata, - opal_pmix_release_cbfunc_t release_fn, - void *release_cbdata) +static void infocb(int status, opal_list_t *info, void *cbdata, + opal_pmix_release_cbfunc_t release_fn, void *release_cbdata) { - opal_pmix_lock_t *lock = (opal_pmix_lock_t*)cbdata; + opal_pmix_lock_t *lock = (opal_pmix_lock_t *) cbdata; opal_value_t *kv; - OPAL_LIST_FOREACH(kv, info, opal_value_t) { + OPAL_LIST_FOREACH (kv, info, opal_value_t) { opal_output(0, "QUERY DATA KEY: %s VALUE %s", kv->key, kv->data.string); } if (NULL != release_fn) { @@ -130,10 +123,8 @@ static void *mylib(void *ptr) /* it is, so let's just use the event notification * API to let everyone know we are here */ OPAL_PMIX_CONSTRUCT_LOCK(&lock); - ret = opal_pmix.notify_event(OPAL_ERR_MODEL_DECLARED, - &orte_process_info.my_name, - OPAL_PMIX_RANGE_PROC_LOCAL, &info, - opcbfunc, &lock); + ret = opal_pmix.notify_event(OPAL_ERR_MODEL_DECLARED, &orte_process_info.my_name, + OPAL_PMIX_RANGE_PROC_LOCAL, &info, opcbfunc, &lock); OPAL_PMIX_WAIT_THREAD(&lock); OPAL_PMIX_DESTRUCT_LOCK(&lock); OPAL_LIST_DESTRUCT(&info); @@ -156,7 +147,7 @@ static void *mylib(void *ptr) /* specify the event code */ OBJ_CONSTRUCT(&info, opal_list_t); kv = OBJ_NEW(opal_value_t); - kv->key = strdup("status"); // the key here is irrelevant + kv->key = strdup("status"); // the key here is irrelevant kv->type = OPAL_INT; kv->data.integer = OPAL_ERR_MODEL_DECLARED; opal_list_append(&info, &kv->super); @@ -165,9 +156,8 @@ static void *mylib(void *ptr) * the event stipulates its range as proc_local. We rely * on that here */ OPAL_PMIX_CONSTRUCT_LOCK(&lock); - opal_pmix.register_evhandler(&info, &directives, model_callback, - model_registration_callback, - (void*)&lock); + opal_pmix.register_evhandler(&info, &directives, model_callback, model_registration_callback, + (void *) &lock); OPAL_PMIX_WAIT_THREAD(&lock); OPAL_PMIX_DESTRUCT_LOCK(&lock); OPAL_LIST_DESTRUCT(&info); @@ -189,8 +179,7 @@ static void *mylib(void *ptr) OPAL_LIST_DESTRUCT(&info); /* Get something */ - opal_pmix.get(&orte_process_info.my_name, - "WASSUP", NULL, &kv); + opal_pmix.get(&orte_process_info.my_name, "WASSUP", NULL, &kv); if (NULL == kv) { fprintf(stderr, "ERROR GETTING WASSUP\n"); } else { @@ -209,13 +198,13 @@ static void *mylib(void *ptr) kv = OBJ_NEW(opal_value_t); kv->key = strdup(OPAL_PMIX_WAIT); kv->type = OPAL_INT; - kv->data.integer = 0; // wait for all + kv->data.integer = 0; // wait for all opal_list_append(&directives, &kv->super); if (OPAL_SUCCESS != opal_pmix.lookup(&info, &directives)) { fprintf(stderr, "LOOKUP FAILED\n"); } else { - pdata = (opal_pmix_pdata_t*)opal_list_get_first(&info); + pdata = (opal_pmix_pdata_t *) opal_list_get_first(&info); fprintf(stderr, "LOOKUP RETURNED %s\n", pdata->value.data.string); } OPAL_LIST_DESTRUCT(&info); @@ -230,7 +219,7 @@ static void *mylib(void *ptr) return NULL; } -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size, rc; hwloc_cpuset_t cpus; @@ -260,7 +249,7 @@ int main(int argc, char* argv[]) goto done; } - printf("[%lu] Rank %d: getting topology\n", (unsigned long)pid, rank); + printf("[%lu] Rank %d: getting topology\n", (unsigned long) pid, rank); fflush(stdout); if (OPAL_SUCCESS == opal_hwloc_base_get_topology()) { cpus = hwloc_bitmap_alloc(); @@ -268,9 +257,8 @@ int main(int argc, char* argv[]) hwloc_bitmap_list_asprintf(&bindings, cpus); } - printf("Hello, World, I am %d of %d [%d local peers]: get_cpubind: %d bitmap %s\n", - rank, size, orte_process_info.num_local_peers, rc, - (NULL == bindings) ? "NULL" : bindings); + printf("Hello, World, I am %d of %d [%d local peers]: get_cpubind: %d bitmap %s\n", rank, size, + orte_process_info.num_local_peers, rc, (NULL == bindings) ? "NULL" : bindings); /* publish something */ OBJ_CONSTRUCT(&list, opal_list_t); @@ -287,7 +275,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "Error joining thread\n"); } - done: +done: MPI_Finalize(); return 0; } diff --git a/test/simple/iof.c b/test/simple/iof.c index 4ec85b8861..88d2b6d0fe 100644 --- a/test/simple/iof.c +++ b/test/simple/iof.c @@ -1,11 +1,11 @@ -#include <stdlib.h> +#include <mpi.h> +#include <stdbool.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <stdbool.h> #include <unistd.h> -#include <mpi.h> -#define ORTE_IOF_BASE_MSG_MAX 2048 +#define ORTE_IOF_BASE_MSG_MAX 2048 int main(int argc, char *argv[]) { @@ -45,7 +45,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Rank %d: recvd blob %d\n", rank, pos); ++pos; done = true; - for (i=0; i < ORTE_IOF_BASE_MSG_MAX; i++) { + for (i = 0; i < ORTE_IOF_BASE_MSG_MAX; i++) { if (0 != msg[i]) { done = false; break; diff --git a/test/simple/loop_child.c b/test/simple/loop_child.c index 7a5000abbf..caeaac8921 100644 --- a/test/simple/loop_child.c +++ b/test/simple/loop_child.c @@ -1,13 +1,12 @@ -#include <string.h> -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> +#include "mpi.h" #include <pthread.h> #include <semaphore.h> -#include "mpi.h" - +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> -int main( int argc, char **argv ) +int main(int argc, char **argv) { MPI_Comm parent; MPI_Comm merged; @@ -25,6 +24,6 @@ int main( int argc, char **argv ) MPI_Comm_free(&merged); MPI_Comm_disconnect(&parent); MPI_Finalize(); - printf("Child %d: exiting\n", (int)getpid()); + printf("Child %d: exiting\n", (int) getpid()); return 0; } diff --git a/test/simple/loop_spawn.c b/test/simple/loop_spawn.c index 1d5f19a120..5759623304 100644 --- a/test/simple/loop_spawn.c +++ b/test/simple/loop_spawn.c @@ -1,14 +1,13 @@ /*file .c : spawned the file Exe*/ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> #include "mpi.h" +#include <errno.h> #include <pthread.h> #include <signal.h> +#include <stdio.h> +#include <stdlib.h> #include <sys/time.h> -#include <errno.h> -#define EXE_TEST "./loop_child" - +#include <unistd.h> +#define EXE_TEST "./loop_child" int main(int argc, char **argv) { @@ -26,23 +25,21 @@ int main(int argc, char **argv) printf("parent*******************************\n"); printf("parent: Launching MPI*\n"); - MPI_Init( &argc, &argv); + MPI_Init(&argc, &argv); for (iter = 0; iter < itermax; ++iter) { - MPI_Comm_spawn(EXE_TEST, NULL, 1, MPI_INFO_NULL, - 0, MPI_COMM_WORLD, &comm, &err); + MPI_Comm_spawn(EXE_TEST, NULL, 1, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &comm, &err); printf("parent: MPI_Comm_spawn #%d return : %d\n", iter, err); MPI_Intercomm_merge(comm, 0, &merged); MPI_Comm_rank(merged, &rank); MPI_Comm_size(merged, &size); - printf("parent: MPI_Comm_spawn #%d rank %d, size %d\n", - iter, rank, size); + printf("parent: MPI_Comm_spawn #%d rank %d, size %d\n", iter, rank, size); MPI_Comm_free(&merged); MPI_Comm_disconnect(&comm); } MPI_Finalize(); - printf("parent: End .\n" ); + printf("parent: End .\n"); return 0; } diff --git a/test/simple/mpi_barrier.c b/test/simple/mpi_barrier.c index 9eeef50b68..315258aec6 100644 --- a/test/simple/mpi_barrier.c +++ b/test/simple/mpi_barrier.c @@ -5,10 +5,10 @@ * The most basic of MPI applications */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { MPI_Init(&argc, &argv); MPI_Barrier(MPI_COMM_WORLD); diff --git a/test/simple/mpi_info.c b/test/simple/mpi_info.c index 6973c5e908..186503e85c 100644 --- a/test/simple/mpi_info.c +++ b/test/simple/mpi_info.c @@ -5,36 +5,27 @@ * The most basic of MPI applications */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { char value[MPI_MAX_INFO_VAL]; int flag; - char *keys[] = { - "command", - "argv", - "maxprocs", - "soft", - "host", - "arch", - "wdir", - "thread_level", - "ompi_num_apps", - "ompi_first_rank", - "ompi_np", - "ompi_positioned_file_dir" - }; + char *keys[] = {"command", "argv", + "maxprocs", "soft", + "host", "arch", + "wdir", "thread_level", + "ompi_num_apps", "ompi_first_rank", + "ompi_np", "ompi_positioned_file_dir"}; int i, nk; MPI_Init(&argc, &argv); - nk = sizeof(keys) / sizeof(char*); + nk = sizeof(keys) / sizeof(char *); - for (i=0; i < nk; i++) { - MPI_Info_get(MPI_INFO_ENV, keys[i], MPI_MAX_INFO_VAL, - value, &flag); + for (i = 0; i < nk; i++) { + MPI_Info_get(MPI_INFO_ENV, keys[i], MPI_MAX_INFO_VAL, value, &flag); fprintf(stderr, "%s: %s\n", keys[i], (flag) ? value : "Not found"); } diff --git a/test/simple/mpi_no_op.c b/test/simple/mpi_no_op.c index 1d382add87..a38c1b7bf3 100644 --- a/test/simple/mpi_no_op.c +++ b/test/simple/mpi_no_op.c @@ -5,10 +5,10 @@ * The most basic of MPI applications */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { MPI_Init(&argc, &argv); diff --git a/test/simple/mpi_spin.c b/test/simple/mpi_spin.c index 3bd0d2069b..a868f61f2e 100644 --- a/test/simple/mpi_spin.c +++ b/test/simple/mpi_spin.c @@ -6,21 +6,19 @@ * abnormal program termination */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> #include "opal/dss/dss.h" #include "opal/mca/pmix/pmix.h" #include "opal/util/output.h" -#include "orte/util/name_fns.h" #include "orte/constants.h" +#include "orte/util/name_fns.h" static volatile bool register_active = false; -static void _event_fn(int status, - const opal_process_name_t *source, - opal_list_t *info, opal_list_t *results, - opal_pmix_notification_complete_fn_t cbfunc, +static void _event_fn(int status, const opal_process_name_t *source, opal_list_t *info, + opal_list_t *results, opal_pmix_notification_complete_fn_t cbfunc, void *cbdata) { opal_value_t *kv; @@ -29,7 +27,7 @@ static void _event_fn(int status, /* the name of the terminating proc should be on the info list */ proc.jobid = ORTE_JOBID_INVALID; proc.vpid = ORTE_VPID_INVALID; - OPAL_LIST_FOREACH(kv, info, opal_value_t) { + OPAL_LIST_FOREACH (kv, info, opal_value_t) { if (0 == strcmp(kv->key, OPAL_PMIX_EVENT_AFFECTED_PROC)) { proc.jobid = kv->data.name.jobid; proc.vpid = kv->data.name.vpid; @@ -37,8 +35,7 @@ static void _event_fn(int status, } } - opal_output(0, "NOTIFIED OF TERMINATION OF PROC %s", - ORTE_NAME_PRINT(&proc)); + opal_output(0, "NOTIFIED OF TERMINATION OF PROC %s", ORTE_NAME_PRINT(&proc)); /* must let the notifier know we are done */ if (NULL != cbfunc) { @@ -46,18 +43,15 @@ static void _event_fn(int status, } } -static void _register_fn(int status, - size_t evhandler_ref, - void *cbdata) +static void _register_fn(int status, size_t evhandler_ref, void *cbdata) { - opal_list_t *codes = (opal_list_t*)cbdata; + opal_list_t *codes = (opal_list_t *) cbdata; OPAL_LIST_RELEASE(codes); register_active = false; } - -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int i; @@ -82,7 +76,8 @@ int main(int argc, char* argv[]) while (1) { i++; pi = i / 3.14159256; - if (i > 100) i = 0; + if (i > 100) + i = 0; } MPI_Finalize(); diff --git a/test/simple/multi_abort.c b/test/simple/multi_abort.c index e76b0d0de0..8849cfd7f4 100644 --- a/test/simple/multi_abort.c +++ b/test/simple/multi_abort.c @@ -5,10 +5,10 @@ * The most basic of MPI applications */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; @@ -18,7 +18,8 @@ int main(int argc, char* argv[]) printf("Hello, World, I am %d of %d\n", rank, size); - if (0 != rank) MPI_Abort(MPI_COMM_WORLD, rank); + if (0 != rank) + MPI_Abort(MPI_COMM_WORLD, rank); MPI_Finalize(); return 0; diff --git a/test/simple/no-disconnect.c b/test/simple/no-disconnect.c index db54de80f0..f1998b8572 100644 --- a/test/simple/no-disconnect.c +++ b/test/simple/no-disconnect.c @@ -9,12 +9,12 @@ as of Open MPI 1.7. However, we hope this feature will work in 2.0. with the new state machine based orte. */ -#include <unistd.h> -#include <stdlib.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <time.h> #include <sys/utsname.h> +#include <time.h> +#include <unistd.h> #include <mpi.h> @@ -31,14 +31,15 @@ const int max_depth = 4; * MPI_Barrier with nice_barrier */ - -static int nice_send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { +static int nice_send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) +{ /* Assume a standard (presumably short/eager) send suffices. */ return MPI_Send(buf, count, datatype, dest, tag, comm); } - -static int nice_recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status *status) { +static int nice_recv(void *buf, int count, MPI_Datatype datatype, int source, int tag, + MPI_Comm comm, MPI_Status *status) +{ MPI_Request req; int flag; struct timespec dt; @@ -51,53 +52,52 @@ static int nice_recv(void *buf, int count, MPI_Datatype datatype, int source, in * something less than a millisecond should be sufficient. * Excessive sleep times (e.g., 1 second) would degrade performance. */ - dt.tv_sec = 0; - dt.tv_nsec = 100000; + dt.tv_sec = 0; + dt.tv_nsec = 100000; MPI_Irecv(buf, count, datatype, source, tag, comm, &req); MPI_Test(&req, &flag, status); - while ( ! flag ) { + while (!flag) { nanosleep(&dt, NULL); MPI_Test(&req, &flag, status); } return MPI_SUCCESS; } - -static void nice_barrier(MPI_Comm comm) { +static void nice_barrier(MPI_Comm comm) +{ int me, np, jump, buf = -1; - MPI_Comm_rank(comm,&me); - MPI_Comm_size(comm,&np); + MPI_Comm_rank(comm, &me); + MPI_Comm_size(comm, &np); /* fan in */ - for ( jump = 1; jump < np; jump <<= 1 ) { - if ( ( me & jump ) != 0 ) { + for (jump = 1; jump < np; jump <<= 1) { + if ((me & jump) != 0) { nice_send(&buf, 1, MPI_INT, me - jump, 343, comm); break; - } else if ( me + jump < np ) { + } else if (me + jump < np) { nice_recv(&buf, 1, MPI_INT, me + jump, 343, comm, MPI_STATUS_IGNORE); } } /* fan out */ - if ( 0 != me ) { + if (0 != me) { nice_recv(&buf, 1, MPI_INT, me - jump, 344, comm, MPI_STATUS_IGNORE); } jump >>= 1; - for ( ; jump > 0; jump >>= 1 ) { - if ( me + jump < np ) { + for (; jump > 0; jump >>= 1) { + if (me + jump < np) { nice_send(&buf, 1, MPI_INT, me + jump, 344, comm); } } } - -int main (int argc, char **argv) +int main(int argc, char **argv) { - char bufs [NCHARS]; /* send buffer */ - char bufr[2][NCHARS]; /* recv buffers */ + char bufs[NCHARS]; /* send buffer */ + char bufr[2][NCHARS]; /* recv buffers */ MPI_Comm parent; int level = 0, participate = 1; struct utsname buf; @@ -114,7 +114,8 @@ int main (int argc, char **argv) #endif uname(&buf); - printf("I AM pid %d with level %d on %s\n", getpid(), (argc < 2)?0:atoi(argv[1]), buf.nodename); + printf("I AM pid %d with level %d on %s\n", getpid(), (argc < 2) ? 0 : atoi(argv[1]), + buf.nodename); MPI_Init(&argc, &argv); MPI_Comm_get_parent(&parent); @@ -122,8 +123,8 @@ int main (int argc, char **argv) if (MPI_COMM_NULL != parent) { /* spawned processes get stuff from parent */ level = atoi(argv[1]); - MPI_Recv(&bufr[0], sizeof(char)*NCHARS, MPI_CHAR, MPI_ANY_SOURCE, - MPI_ANY_TAG, parent, MPI_STATUS_IGNORE); + MPI_Recv(&bufr[0], sizeof(char) * NCHARS, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, parent, + MPI_STATUS_IGNORE); printf("Parent sent: %s\n", bufr[0]); } else { @@ -142,60 +143,62 @@ int main (int argc, char **argv) int me, np; - MPI_Comm_size(MPI_COMM_WORLD,&np); - MPI_Comm_rank(MPI_COMM_WORLD,&me); + MPI_Comm_size(MPI_COMM_WORLD, &np); + MPI_Comm_rank(MPI_COMM_WORLD, &me); - if ( np > 4 ) { + if (np > 4) { /* turn off all but every 4th process */ - if ( ( me & 3 ) != 0 ) participate = 0; - } else - if ( np > 2 ) { + if ((me & 3) != 0) + participate = 0; + } else if (np > 2) { /* turn off all but every 2nd process */ - if ( ( me & 1 ) != 0 ) participate = 0; + if ((me & 1) != 0) + participate = 0; } } /* all spawned processes and selected "root" processes participate */ - if ( participate ) { + if (participate) { printf("level = %d\n", level); /* prepare send buffer */ - sprintf(bufs,"level %d (pid:%d)", level, getpid()); + sprintf(bufs, "level %d (pid:%d)", level, getpid()); /* spawn */ if (level < max_depth) { int i, nspawn = 2, errcodes[1]; MPI_Request req[2]; - MPI_Comm comm[2]; + MPI_Comm comm[2]; char argv1[NCHARS]; char *args[2]; /* level 0 spawns only one process to mimic the original test */ - if ( level == 0 ) nspawn = 1; + if (level == 0) + nspawn = 1; /* prepare command line arguments */ - snprintf(argv1, sizeof(argv1), "%d", level+1); + snprintf(argv1, sizeof(argv1), "%d", level + 1); args[0] = argv1; args[1] = NULL; /* spawn, with a message sent to and received from each child */ - for ( i = 0; i < nspawn; i++ ) { - MPI_Comm_spawn(argv[0], args, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, - &comm[i], errcodes); - MPI_Send(&bufs, sizeof(char)*NCHARS, MPI_CHAR, 0, 100, comm[i]); - MPI_Irecv(&bufr[i], sizeof(char)*NCHARS, MPI_CHAR, MPI_ANY_SOURCE, - MPI_ANY_TAG, comm[i], &req[i]); + for (i = 0; i < nspawn; i++) { + MPI_Comm_spawn(argv[0], args, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm[i], + errcodes); + MPI_Send(&bufs, sizeof(char) * NCHARS, MPI_CHAR, 0, 100, comm[i]); + MPI_Irecv(&bufr[i], sizeof(char) * NCHARS, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, + comm[i], &req[i]); } /* wait for messages from children and print them */ MPI_Waitall(nspawn, req, MPI_STATUSES_IGNORE); - for ( i = 0; i < nspawn; i++ ) + for (i = 0; i < nspawn; i++) printf("Child %d sent: %s\n", i, bufr[i]); } /* send message back to parent */ if (MPI_COMM_NULL != parent) { - MPI_Send(&bufs, sizeof(char)*NCHARS, MPI_CHAR, 0, 100, parent); + MPI_Send(&bufs, sizeof(char) * NCHARS, MPI_CHAR, 0, 100, parent); } } diff --git a/test/simple/nonzero.c b/test/simple/nonzero.c index 4b7ff266bf..20e2393960 100644 --- a/test/simple/nonzero.c +++ b/test/simple/nonzero.c @@ -1,16 +1,16 @@ +#include <mpi.h> #include <stdlib.h> #include <unistd.h> -#include <mpi.h> int main(int argc, char **argv) { int rank; - if(argc < 2) { + if (argc < 2) { return 0; } MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD,&rank); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); int i = atoi(argv[1]); diff --git a/test/simple/parallel_r64.c b/test/simple/parallel_r64.c index c7354b4f4c..7ca5219417 100644 --- a/test/simple/parallel_r64.c +++ b/test/simple/parallel_r64.c @@ -5,218 +5,208 @@ #include <stdio.h> #include <string.h> -#define D 3 /* dimensions */ +#define D 3 /* dimensions */ -#define X 1024 /* global x grid size */ -#define Y 1024 /* global y grid size */ -#define Z 1024 /* global z grid size */ +#define X 1024 /* global x grid size */ +#define Y 1024 /* global y grid size */ +#define Z 1024 /* global z grid size */ -#define nx 256 /* local x grid size */ -#define ny 256 /* local y grid size */ -#define nz 256 /* local z grid size */ +#define nx 256 /* local x grid size */ +#define ny 256 /* local y grid size */ +#define nz 256 /* local z grid size */ -#define ng (nx*ny*nz) /* local grid (cube) size */ +#define ng (nx * ny * nz) /* local grid (cube) size */ -#define npx 4 /* number of PE's in x direction */ -#define npy 4 /* number of PE's in y direction */ -#define npz 4 /* number of PE's in z direction */ +#define npx 4 /* number of PE's in x direction */ +#define npy 4 /* number of PE's in y direction */ +#define npz 4 /* number of PE's in z direction */ -#define np (npx*npy*npz) /* total PE count */ +#define np (npx * npy * npz) /* total PE count */ #define LOOP 1 #define MAX_RR_NAME 7 -int -main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - int i, rank, npes, bug=0; - int buf[ng]; - MPI_File thefile; - MPI_Status status; - MPI_Datatype filetype; - MPI_Comm new_comm; - MPI_Offset offset=0; - MPI_Info info=MPI_INFO_NULL; - int gsize[D],distrib[D],dargs[D],psize[D]; - int dims[D],periods[D],reorder; - double t1,t2,mbs; - double to1,to2,tc1,tc2; - double et,eto,etc; - double max_mbs,min_mbs,avg_mbs; - double max_et,min_et,avg_et; - double max_eto,min_eto,avg_eto; - double max_etc,min_etc,avg_etc; - char process_name[MPI_MAX_PROCESSOR_NAME + 1]; - char rr_blank[] = {" "}; - char rr_empty[] = {"???????"}; - int count; - - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &npes); - if ( rank == 0 ) - { - if ( argc < 2 ) - { - printf(" ERROR: no filename given\n"); - bug++; - } - if ( npes == np ) - { - printf(" file name: %s\n",argv[1]); - printf(" total number of PE's: %3d\n",np); - printf(" number of PE's in x direction: %3d\n",npx); - printf(" number of PE's in y direction: %3d\n",npy); - printf(" number of PE's in z direction: %3d\n",npz); - printf(" global grid size: %dx%dx%d 4 byte integers (total %lu)\n",X,Y,Z,(unsigned long)X*Y*Z); - printf(" local grid size: %dx%dx%d 4 byte integers (total %d)\n",nx,ny,nz,ng); - } - else - { - printf(" ERROR: total number of PE's must be %d\n",np); - printf(" actual number of PE's was %d\n",npes); - bug++; - } - if ( bug ) - { - MPI_Abort(MPI_COMM_WORLD,-1); - } + int i, rank, npes, bug = 0; + int buf[ng]; + MPI_File thefile; + MPI_Status status; + MPI_Datatype filetype; + MPI_Comm new_comm; + MPI_Offset offset = 0; + MPI_Info info = MPI_INFO_NULL; + int gsize[D], distrib[D], dargs[D], psize[D]; + int dims[D], periods[D], reorder; + double t1, t2, mbs; + double to1, to2, tc1, tc2; + double et, eto, etc; + double max_mbs, min_mbs, avg_mbs; + double max_et, min_et, avg_et; + double max_eto, min_eto, avg_eto; + double max_etc, min_etc, avg_etc; + char process_name[MPI_MAX_PROCESSOR_NAME + 1]; + char rr_blank[] = {" "}; + char rr_empty[] = {"???????"}; + int count; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &npes); + if (rank == 0) { + if (argc < 2) { + printf(" ERROR: no filename given\n"); + bug++; + } + if (npes == np) { + printf(" file name: %s\n", argv[1]); + printf(" total number of PE's: %3d\n", np); + printf(" number of PE's in x direction: %3d\n", npx); + printf(" number of PE's in y direction: %3d\n", npy); + printf(" number of PE's in z direction: %3d\n", npz); + printf(" global grid size: %dx%dx%d 4 byte integers (total %lu)\n", X, Y, Z, + (unsigned long) X * Y * Z); + printf(" local grid size: %dx%dx%d 4 byte integers (total %d)\n", nx, ny, nz, ng); + } else { + printf(" ERROR: total number of PE's must be %d\n", np); + printf(" actual number of PE's was %d\n", npes); + bug++; + } + if (bug) { + MPI_Abort(MPI_COMM_WORLD, -1); + } + } + if (MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) { + sprintf(process_name, "%s", rr_empty); + } else { + if (count < MAX_RR_NAME) + strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); + process_name[MAX_RR_NAME] = '\0'; } - if ( MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) - { - sprintf(process_name, "%s", rr_empty); - } - else - { - if (count < MAX_RR_NAME) strncat(&process_name[count],rr_blank,MAX_RR_NAME-count); - process_name[MAX_RR_NAME] = '\0'; - } - MPI_Info_create(&info); + MPI_Info_create(&info); -/* allow multiple writers to write to the file concurrently */ + /* allow multiple writers to write to the file concurrently */ -/*MPI_Info_set(info,"panfs_concurrent_write","1");*/ + /*MPI_Info_set(info,"panfs_concurrent_write","1");*/ -/* use data aggregation */ + /* use data aggregation */ -/*MPI_Info_set(info,"romio_cb_write","enable"); */ -/*MPI_Info_set(info,"romio_cb_write","disable");*/ -/*MPI_Info_set(info,"romio_cb_read","enable"); */ -/*MPI_Info_set(info,"romio_cb_read","disable");*/ + /*MPI_Info_set(info,"romio_cb_write","enable"); */ + /*MPI_Info_set(info,"romio_cb_write","disable");*/ + /*MPI_Info_set(info,"romio_cb_read","enable"); */ + /*MPI_Info_set(info,"romio_cb_read","disable");*/ -/* use one aggregator/writer per node */ + /* use one aggregator/writer per node */ -/*MPI_Info_set(info,"cb_config_list","*:1");*/ + /*MPI_Info_set(info,"cb_config_list","*:1");*/ -/* aggregators/writers per allocation: use this or the above (both work) */ + /* aggregators/writers per allocation: use this or the above (both work) */ -/*i = ((npes-1)/8) + 1; - sprintf(awpa,"%d",i); - MPI_Info_set (info,"cb_nodes",awpa);*/ + /*i = ((npes-1)/8) + 1; + sprintf(awpa,"%d",i); + MPI_Info_set (info,"cb_nodes",awpa);*/ - for ( i=0; i<D; i++ ) - { - periods[i] = 1; /* true */ + for (i = 0; i < D; i++) { + periods[i] = 1; /* true */ } - reorder = 1; /* true */ + reorder = 1; /* true */ - dims[0] = npx; - dims[1] = npy; - dims[2] = npz; + dims[0] = npx; + dims[1] = npy; + dims[2] = npz; - MPI_Cart_create(MPI_COMM_WORLD, D, dims, periods, reorder, &new_comm); + MPI_Cart_create(MPI_COMM_WORLD, D, dims, periods, reorder, &new_comm); - for ( i=0; i<D; i++ ) - { - distrib[i] = MPI_DISTRIBUTE_BLOCK; - dargs[i] = MPI_DISTRIBUTE_DFLT_DARG; -/* psize[i] = 0; */ + for (i = 0; i < D; i++) { + distrib[i] = MPI_DISTRIBUTE_BLOCK; + dargs[i] = MPI_DISTRIBUTE_DFLT_DARG; + /* psize[i] = 0; */ } - gsize[0] = X; - gsize[1] = Y; - gsize[2] = Z; + gsize[0] = X; + gsize[1] = Y; + gsize[2] = Z; - psize[0] = npx; - psize[1] = npy; - psize[2] = npz; + psize[0] = npx; + psize[1] = npy; + psize[2] = npz; -/* - MPI_Dims_create(npes, D, psize); + /* + MPI_Dims_create(npes, D, psize); - printf("psize %d %d %d\n",psize[0],psize[1],psize[2]); -*/ + printf("psize %d %d %d\n",psize[0],psize[1],psize[2]); + */ - MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_FORTRAN, MPI_INT, &filetype); + MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_FORTRAN, MPI_INT, + &filetype); - MPI_Type_commit(&filetype); + MPI_Type_commit(&filetype); - to1 = MPI_Wtime(); - MPI_File_open(new_comm, argv[1], MPI_MODE_RDONLY, info, &thefile); - to2 = MPI_Wtime(); + to1 = MPI_Wtime(); + MPI_File_open(new_comm, argv[1], MPI_MODE_RDONLY, info, &thefile); + to2 = MPI_Wtime(); - MPI_File_set_view(thefile, offset, MPI_INT, filetype, "native", MPI_INFO_NULL); + MPI_File_set_view(thefile, offset, MPI_INT, filetype, "native", MPI_INFO_NULL); - t1 = MPI_Wtime(); - for ( i=0; i<LOOP; i++ ) - { - MPI_File_read_all(thefile, buf, ng, MPI_INT, &status); + t1 = MPI_Wtime(); + for (i = 0; i < LOOP; i++) { + MPI_File_read_all(thefile, buf, ng, MPI_INT, &status); } - t2 = MPI_Wtime(); + t2 = MPI_Wtime(); -/*MPI_File_sync(thefile); */ + /*MPI_File_sync(thefile); */ - tc1 = MPI_Wtime(); - MPI_File_close(&thefile); - tc2 = MPI_Wtime(); + tc1 = MPI_Wtime(); + MPI_File_close(&thefile); + tc2 = MPI_Wtime(); - et = (t2 - t1)/LOOP; - eto = (to2 - to1)/LOOP; - etc = (tc2 - tc1)/LOOP; + et = (t2 - t1) / LOOP; + eto = (to2 - to1) / LOOP; + etc = (tc2 - tc1) / LOOP; - mbs = (((double)(LOOP*X*Y*Z)*sizeof(int)))/(1000000.0*(t2-t1)); + mbs = (((double) (LOOP * X * Y * Z) * sizeof(int))) / (1000000.0 * (t2 - t1)); -/*printf(" %s[%3d] ET %5.2f %6.2f %6.2f %5.1f mbs Data %9d %9d \n", process_name, rank, t1, t2, t2-t1, mbs, buf[0], buf[ng-1]);*/ + /*printf(" %s[%3d] ET %5.2f %6.2f %6.2f %5.1f mbs Data %9d %9d \n", + * process_name, rank, t1, t2, t2-t1, mbs, buf[0], buf[ng-1]);*/ - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); - MPI_Reduce(&mbs, &avg_mbs, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&mbs, &min_mbs, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&mbs, &max_mbs, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &avg_mbs, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &min_mbs, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &max_mbs, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &avg_et, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &min_et, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &max_et, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &avg_et, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &min_et, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &max_et, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &avg_eto, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &min_eto, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &max_eto, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &avg_eto, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &min_eto, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &max_eto, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &avg_etc, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &min_etc, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &max_etc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &avg_etc, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &min_etc, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &max_etc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - fflush(stdout); + fflush(stdout); - if ( rank == 0 ) - { - mbs = avg_mbs/npes; - printf("\n average read rate: %9.1f mbs\n", mbs); - printf(" minimum read rate: %9.1f mbs\n", min_mbs); - printf(" maximum read rate: %9.1f mbs\n\n", max_mbs); - avg_eto = avg_eto/npes; - avg_et = avg_et/npes; - avg_etc = avg_etc/npes; - printf(" open time: %9.3f min %9.3f avg %9.3f max\n",min_eto,avg_eto,max_eto); - printf(" read time: %9.3f min %9.3f avg %9.3f max\n",min_et,avg_et,max_et); - printf(" close time: %9.3f min %9.3f avg %9.3f max\n\n",min_etc,avg_etc,max_etc); - fflush(stdout); + if (rank == 0) { + mbs = avg_mbs / npes; + printf("\n average read rate: %9.1f mbs\n", mbs); + printf(" minimum read rate: %9.1f mbs\n", min_mbs); + printf(" maximum read rate: %9.1f mbs\n\n", max_mbs); + avg_eto = avg_eto / npes; + avg_et = avg_et / npes; + avg_etc = avg_etc / npes; + printf(" open time: %9.3f min %9.3f avg %9.3f max\n", min_eto, avg_eto, max_eto); + printf(" read time: %9.3f min %9.3f avg %9.3f max\n", min_et, avg_et, max_et); + printf(" close time: %9.3f min %9.3f avg %9.3f max\n\n", min_etc, avg_etc, max_etc); + fflush(stdout); } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/test/simple/parallel_r8.c b/test/simple/parallel_r8.c index ad3f5f7ad1..b8541e17ed 100644 --- a/test/simple/parallel_r8.c +++ b/test/simple/parallel_r8.c @@ -5,218 +5,208 @@ #include <stdio.h> #include <string.h> -#define D 3 /* dimensions */ +#define D 3 /* dimensions */ -#define X 256 /* global x grid size */ -#define Y 256 /* global y grid size */ -#define Z 256 /* global z grid size */ +#define X 256 /* global x grid size */ +#define Y 256 /* global y grid size */ +#define Z 256 /* global z grid size */ -#define nx 128 /* local x grid size */ -#define ny 128 /* local y grid size */ -#define nz 128 /* local z grid size */ +#define nx 128 /* local x grid size */ +#define ny 128 /* local y grid size */ +#define nz 128 /* local z grid size */ -#define ng (nx*ny*nz) /* local grid (cube) size */ +#define ng (nx * ny * nz) /* local grid (cube) size */ -#define npx 2 /* number of PE's in x direction */ -#define npy 2 /* number of PE's in y direction */ -#define npz 2 /* number of PE's in z direction */ +#define npx 2 /* number of PE's in x direction */ +#define npy 2 /* number of PE's in y direction */ +#define npz 2 /* number of PE's in z direction */ -#define np (npx*npy*npz) /* total PE count */ +#define np (npx * npy * npz) /* total PE count */ #define LOOP 1 #define MAX_RR_NAME 7 -int -main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - int i, rank, npes, bug=0; - int buf[ng]; - MPI_File thefile; - MPI_Status status; - MPI_Datatype filetype; - MPI_Comm new_comm; - MPI_Offset offset=0; - MPI_Info info=MPI_INFO_NULL; - int gsize[D],distrib[D],dargs[D],psize[D]; - int dims[D],periods[D],reorder; - double t1,t2,mbs; - double to1,to2,tc1,tc2; - double et,eto,etc; - double max_mbs,min_mbs,avg_mbs; - double max_et,min_et,avg_et; - double max_eto,min_eto,avg_eto; - double max_etc,min_etc,avg_etc; - char process_name[MPI_MAX_PROCESSOR_NAME + 1]; - char rr_blank[] = {" "}; - char rr_empty[] = {"???????"}; - int count; - - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &npes); - if ( rank == 0 ) - { - if ( argc < 2 ) - { - printf(" ERROR: no filename given\n"); - bug++; - } - if ( npes == np ) - { - printf(" file name: %s\n",argv[1]); - printf(" total number of PE's: %3d\n",np); - printf(" number of PE's in x direction: %3d\n",npx); - printf(" number of PE's in y direction: %3d\n",npy); - printf(" number of PE's in z direction: %3d\n",npz); - printf(" global grid size: %dx%dx%d 4 byte integers (total %lu)\n",X,Y,Z,(unsigned long)X*Y*Z); - printf(" local grid size: %dx%dx%d 4 byte integers (total %d)\n",nx,ny,nz,ng); - } - else - { - printf(" ERROR: total number of PE's must be %d\n",np); - printf(" actual number of PE's was %d\n",npes); - bug++; - } - if ( bug ) - { - MPI_Abort(MPI_COMM_WORLD,-1); - } + int i, rank, npes, bug = 0; + int buf[ng]; + MPI_File thefile; + MPI_Status status; + MPI_Datatype filetype; + MPI_Comm new_comm; + MPI_Offset offset = 0; + MPI_Info info = MPI_INFO_NULL; + int gsize[D], distrib[D], dargs[D], psize[D]; + int dims[D], periods[D], reorder; + double t1, t2, mbs; + double to1, to2, tc1, tc2; + double et, eto, etc; + double max_mbs, min_mbs, avg_mbs; + double max_et, min_et, avg_et; + double max_eto, min_eto, avg_eto; + double max_etc, min_etc, avg_etc; + char process_name[MPI_MAX_PROCESSOR_NAME + 1]; + char rr_blank[] = {" "}; + char rr_empty[] = {"???????"}; + int count; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &npes); + if (rank == 0) { + if (argc < 2) { + printf(" ERROR: no filename given\n"); + bug++; + } + if (npes == np) { + printf(" file name: %s\n", argv[1]); + printf(" total number of PE's: %3d\n", np); + printf(" number of PE's in x direction: %3d\n", npx); + printf(" number of PE's in y direction: %3d\n", npy); + printf(" number of PE's in z direction: %3d\n", npz); + printf(" global grid size: %dx%dx%d 4 byte integers (total %lu)\n", X, Y, Z, + (unsigned long) X * Y * Z); + printf(" local grid size: %dx%dx%d 4 byte integers (total %d)\n", nx, ny, nz, ng); + } else { + printf(" ERROR: total number of PE's must be %d\n", np); + printf(" actual number of PE's was %d\n", npes); + bug++; + } + if (bug) { + MPI_Abort(MPI_COMM_WORLD, -1); + } + } + if (MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) { + sprintf(process_name, "%s", rr_empty); + } else { + if (count < MAX_RR_NAME) + strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); + process_name[MAX_RR_NAME] = '\0'; } - if ( MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) - { - sprintf(process_name, "%s", rr_empty); - } - else - { - if (count < MAX_RR_NAME) strncat(&process_name[count],rr_blank,MAX_RR_NAME-count); - process_name[MAX_RR_NAME] = '\0'; - } - MPI_Info_create(&info); + MPI_Info_create(&info); -/* allow multiple writers to write to the file concurrently */ + /* allow multiple writers to write to the file concurrently */ -/*MPI_Info_set(info,"panfs_concurrent_write","1");*/ + /*MPI_Info_set(info,"panfs_concurrent_write","1");*/ -/* use data aggregation */ + /* use data aggregation */ -/*MPI_Info_set(info,"romio_cb_write","enable"); */ -/*MPI_Info_set(info,"romio_cb_write","disable");*/ -/*MPI_Info_set(info,"romio_cb_read","enable"); */ -/*MPI_Info_set(info,"romio_cb_read","disable");*/ + /*MPI_Info_set(info,"romio_cb_write","enable"); */ + /*MPI_Info_set(info,"romio_cb_write","disable");*/ + /*MPI_Info_set(info,"romio_cb_read","enable"); */ + /*MPI_Info_set(info,"romio_cb_read","disable");*/ -/* use one aggregator/writer per node */ + /* use one aggregator/writer per node */ -/*MPI_Info_set(info,"cb_config_list","*:1");*/ + /*MPI_Info_set(info,"cb_config_list","*:1");*/ -/* aggregators/writers per allocation: use this or the above (both work) */ + /* aggregators/writers per allocation: use this or the above (both work) */ -/*i = ((npes-1)/8) + 1; - sprintf(awpa,"%d",i); - MPI_Info_set (info,"cb_nodes",awpa);*/ + /*i = ((npes-1)/8) + 1; + sprintf(awpa,"%d",i); + MPI_Info_set (info,"cb_nodes",awpa);*/ - for ( i=0; i<D; i++ ) - { - periods[i] = 1; /* true */ + for (i = 0; i < D; i++) { + periods[i] = 1; /* true */ } - reorder = 1; /* true */ + reorder = 1; /* true */ - dims[0] = npx; - dims[1] = npy; - dims[2] = npz; + dims[0] = npx; + dims[1] = npy; + dims[2] = npz; - MPI_Cart_create(MPI_COMM_WORLD, D, dims, periods, reorder, &new_comm); + MPI_Cart_create(MPI_COMM_WORLD, D, dims, periods, reorder, &new_comm); - for ( i=0; i<D; i++ ) - { - distrib[i] = MPI_DISTRIBUTE_BLOCK; - dargs[i] = MPI_DISTRIBUTE_DFLT_DARG; -/* psize[i] = 0; */ + for (i = 0; i < D; i++) { + distrib[i] = MPI_DISTRIBUTE_BLOCK; + dargs[i] = MPI_DISTRIBUTE_DFLT_DARG; + /* psize[i] = 0; */ } - gsize[0] = X; - gsize[1] = Y; - gsize[2] = Z; + gsize[0] = X; + gsize[1] = Y; + gsize[2] = Z; - psize[0] = npx; - psize[1] = npy; - psize[2] = npz; + psize[0] = npx; + psize[1] = npy; + psize[2] = npz; -/* - MPI_Dims_create(npes, D, psize); + /* + MPI_Dims_create(npes, D, psize); - printf("psize %d %d %d\n",psize[0],psize[1],psize[2]); -*/ + printf("psize %d %d %d\n",psize[0],psize[1],psize[2]); + */ - MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_FORTRAN, MPI_INT, &filetype); + MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_FORTRAN, MPI_INT, + &filetype); - MPI_Type_commit(&filetype); + MPI_Type_commit(&filetype); - to1 = MPI_Wtime(); - MPI_File_open(new_comm, argv[1], MPI_MODE_RDONLY, info, &thefile); - to2 = MPI_Wtime(); + to1 = MPI_Wtime(); + MPI_File_open(new_comm, argv[1], MPI_MODE_RDONLY, info, &thefile); + to2 = MPI_Wtime(); - MPI_File_set_view(thefile, offset, MPI_INT, filetype, "native", MPI_INFO_NULL); + MPI_File_set_view(thefile, offset, MPI_INT, filetype, "native", MPI_INFO_NULL); - t1 = MPI_Wtime(); - for ( i=0; i<LOOP; i++ ) - { - MPI_File_read_all(thefile, buf, ng, MPI_INT, &status); + t1 = MPI_Wtime(); + for (i = 0; i < LOOP; i++) { + MPI_File_read_all(thefile, buf, ng, MPI_INT, &status); } - t2 = MPI_Wtime(); + t2 = MPI_Wtime(); -/*MPI_File_sync(thefile); */ + /*MPI_File_sync(thefile); */ - tc1 = MPI_Wtime(); - MPI_File_close(&thefile); - tc2 = MPI_Wtime(); + tc1 = MPI_Wtime(); + MPI_File_close(&thefile); + tc2 = MPI_Wtime(); - et = (t2 - t1)/LOOP; - eto = (to2 - to1)/LOOP; - etc = (tc2 - tc1)/LOOP; + et = (t2 - t1) / LOOP; + eto = (to2 - to1) / LOOP; + etc = (tc2 - tc1) / LOOP; - mbs = (((double)(LOOP*X*Y*Z)*sizeof(int)))/(1000000.0*(t2-t1)); + mbs = (((double) (LOOP * X * Y * Z) * sizeof(int))) / (1000000.0 * (t2 - t1)); -/*printf(" %s[%3d] ET %5.2f %6.2f %6.2f %5.1f mbs Data %9d %9d \n", process_name, rank, t1, t2, t2-t1, mbs, buf[0], buf[ng-1]);*/ + /*printf(" %s[%3d] ET %5.2f %6.2f %6.2f %5.1f mbs Data %9d %9d \n", + * process_name, rank, t1, t2, t2-t1, mbs, buf[0], buf[ng-1]);*/ - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); - MPI_Reduce(&mbs, &avg_mbs, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&mbs, &min_mbs, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&mbs, &max_mbs, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &avg_mbs, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &min_mbs, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &max_mbs, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &avg_et, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &min_et, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &max_et, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &avg_et, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &min_et, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &max_et, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &avg_eto, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &min_eto, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &max_eto, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &avg_eto, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &min_eto, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &max_eto, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &avg_etc, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &min_etc, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &max_etc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &avg_etc, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &min_etc, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &max_etc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - fflush(stdout); + fflush(stdout); - if ( rank == 0 ) - { - mbs = avg_mbs/npes; - printf("\n average read rate: %9.1f mbs\n", mbs); - printf(" minimum read rate: %9.1f mbs\n", min_mbs); - printf(" maximum read rate: %9.1f mbs\n\n", max_mbs); - avg_eto = avg_eto/npes; - avg_et = avg_et/npes; - avg_etc = avg_etc/npes; - printf(" open time: %9.3f min %9.3f avg %9.3f max\n",min_eto,avg_eto,max_eto); - printf(" read time: %9.3f min %9.3f avg %9.3f max\n",min_et,avg_et,max_et); - printf(" close time: %9.3f min %9.3f avg %9.3f max\n\n",min_etc,avg_etc,max_etc); - fflush(stdout); + if (rank == 0) { + mbs = avg_mbs / npes; + printf("\n average read rate: %9.1f mbs\n", mbs); + printf(" minimum read rate: %9.1f mbs\n", min_mbs); + printf(" maximum read rate: %9.1f mbs\n\n", max_mbs); + avg_eto = avg_eto / npes; + avg_et = avg_et / npes; + avg_etc = avg_etc / npes; + printf(" open time: %9.3f min %9.3f avg %9.3f max\n", min_eto, avg_eto, max_eto); + printf(" read time: %9.3f min %9.3f avg %9.3f max\n", min_et, avg_et, max_et); + printf(" close time: %9.3f min %9.3f avg %9.3f max\n\n", min_etc, avg_etc, max_etc); + fflush(stdout); } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/test/simple/parallel_w64.c b/test/simple/parallel_w64.c index 57f0f878bf..fdb9acdd29 100644 --- a/test/simple/parallel_w64.c +++ b/test/simple/parallel_w64.c @@ -5,224 +5,215 @@ #include <stdio.h> #include <string.h> -#define D 3 /* dimensions */ +#define D 3 /* dimensions */ -#define X 1024 /* global x grid size */ -#define Y 1024 /* global y grid size */ -#define Z 1024 /* global z grid size */ +#define X 1024 /* global x grid size */ +#define Y 1024 /* global y grid size */ +#define Z 1024 /* global z grid size */ -#define nx 256 /* local x grid size */ -#define ny 256 /* local y grid size */ -#define nz 256 /* local z grid size */ +#define nx 256 /* local x grid size */ +#define ny 256 /* local y grid size */ +#define nz 256 /* local z grid size */ -#define ng (nx*ny*nz) /* local grid (cube) size */ +#define ng (nx * ny * nz) /* local grid (cube) size */ -#define npx 4 /* number of PE's in x direction */ -#define npy 4 /* number of PE's in y direction */ -#define npz 4 /* number of PE's in z direction */ +#define npx 4 /* number of PE's in x direction */ +#define npy 4 /* number of PE's in y direction */ +#define npz 4 /* number of PE's in z direction */ -#define np (npx*npy*npz) /* total PE count */ +#define np (npx * npy * npz) /* total PE count */ #define LOOP 1 #define MAX_RR_NAME 7 -int -main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - int i, rank, npes, bug=0; - int buf[ng]; - MPI_File thefile; - MPI_Status status; - MPI_Datatype filetype; - MPI_Comm new_comm; - MPI_Offset offset=0; - MPI_Info info=MPI_INFO_NULL; - int gsize[D],distrib[D],dargs[D],psize[D]; - int dims[D],periods[D],reorder; - double t1,t2,mbs; - double to1,to2,tc1,tc2; - double et,eto,etc; - double max_mbs,min_mbs,avg_mbs; - double max_et,min_et,avg_et; - double max_eto,min_eto,avg_eto; - double max_etc,min_etc,avg_etc; - char process_name[MPI_MAX_PROCESSOR_NAME + 1]; - char rr_blank[] = {" "}; - char rr_empty[] = {"???????"}; - int count; - - MPI_Init(&argc, &argv); - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &npes); - if ( rank == 0 ) - { - if ( argc < 2 ) - { - printf(" ERROR: no filename given\n"); - bug++; - } - if ( npes == np ) - { - printf(" file name: %s\n",argv[1]); - printf(" total number of PE's: %3d\n",np); - printf(" number of PE's in x direction: %4d\n",npx); - printf(" number of PE's in y direction: %4d\n",npy); - printf(" number of PE's in z direction: %4d\n",npz); - printf(" global grid size: %dx%dx%d 4 byte integers (total %lu)\n",X,Y,Z,(unsigned long)X*Y*Z); - printf(" local grid size: %dx%dx%d 4 byte integers (total %d)\n",nx,ny,nz,ng); - } - else - { - printf(" ERROR: total number of PE's must be %d\n",np); - printf(" actual number of PE's was %d\n",npes); - bug++; - } - if ( bug ) - { - MPI_Abort(MPI_COMM_WORLD,-1); - } + int i, rank, npes, bug = 0; + int buf[ng]; + MPI_File thefile; + MPI_Status status; + MPI_Datatype filetype; + MPI_Comm new_comm; + MPI_Offset offset = 0; + MPI_Info info = MPI_INFO_NULL; + int gsize[D], distrib[D], dargs[D], psize[D]; + int dims[D], periods[D], reorder; + double t1, t2, mbs; + double to1, to2, tc1, tc2; + double et, eto, etc; + double max_mbs, min_mbs, avg_mbs; + double max_et, min_et, avg_et; + double max_eto, min_eto, avg_eto; + double max_etc, min_etc, avg_etc; + char process_name[MPI_MAX_PROCESSOR_NAME + 1]; + char rr_blank[] = {" "}; + char rr_empty[] = {"???????"}; + int count; + + MPI_Init(&argc, &argv); + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &npes); + if (rank == 0) { + if (argc < 2) { + printf(" ERROR: no filename given\n"); + bug++; + } + if (npes == np) { + printf(" file name: %s\n", argv[1]); + printf(" total number of PE's: %3d\n", np); + printf(" number of PE's in x direction: %4d\n", npx); + printf(" number of PE's in y direction: %4d\n", npy); + printf(" number of PE's in z direction: %4d\n", npz); + printf(" global grid size: %dx%dx%d 4 byte integers (total %lu)\n", X, Y, Z, + (unsigned long) X * Y * Z); + printf(" local grid size: %dx%dx%d 4 byte integers (total %d)\n", nx, ny, nz, ng); + } else { + printf(" ERROR: total number of PE's must be %d\n", np); + printf(" actual number of PE's was %d\n", npes); + bug++; + } + if (bug) { + MPI_Abort(MPI_COMM_WORLD, -1); + } + } + if (MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) { + sprintf(process_name, "%s", rr_empty); + } else { + if (count < MAX_RR_NAME) + strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); + process_name[MAX_RR_NAME] = '\0'; } - if ( MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) - { - sprintf(process_name, "%s", rr_empty); - } - else - { - if (count < MAX_RR_NAME) strncat(&process_name[count],rr_blank,MAX_RR_NAME-count); - process_name[MAX_RR_NAME] = '\0'; - } - - MPI_Barrier(MPI_COMM_WORLD); - MPI_Info_create(&info); + MPI_Barrier(MPI_COMM_WORLD); -/* allow multiple writers to write to the file concurrently */ + MPI_Info_create(&info); -/*MPI_Info_set(info,"panfs_concurrent_write","1");*/ + /* allow multiple writers to write to the file concurrently */ -/* use data aggregation */ + /*MPI_Info_set(info,"panfs_concurrent_write","1");*/ -/*MPI_Info_set(info,"romio_cb_write","enable"); */ -/*MPI_Info_set(info,"romio_cb_write","disable");*/ -/*MPI_Info_set(info,"romio_cb_read","enable"); */ -/*MPI_Info_set(info,"romio_cb_read","disable");*/ + /* use data aggregation */ -/* use one aggregator/writer per node */ + /*MPI_Info_set(info,"romio_cb_write","enable"); */ + /*MPI_Info_set(info,"romio_cb_write","disable");*/ + /*MPI_Info_set(info,"romio_cb_read","enable"); */ + /*MPI_Info_set(info,"romio_cb_read","disable");*/ -/*MPI_Info_set(info,"cb_config_list","*:1");*/ + /* use one aggregator/writer per node */ -/* aggregators/writers per allocation: use this or the above (both work) */ + /*MPI_Info_set(info,"cb_config_list","*:1");*/ -/*i = ((npes-1)/8) + 1; - sprintf(awpa,"%d",i); - MPI_Info_set (info,"cb_nodes",awpa);*/ + /* aggregators/writers per allocation: use this or the above (both work) */ + /*i = ((npes-1)/8) + 1; + sprintf(awpa,"%d",i); + MPI_Info_set (info,"cb_nodes",awpa);*/ - for ( i=0; i<ng; i++ ) buf[i] = rank*10000 + (i+1)%1024; + for (i = 0; i < ng; i++) + buf[i] = rank * 10000 + (i + 1) % 1024; - for ( i=0; i<D; i++ ) - { - periods[i] = 1; /* true */ + for (i = 0; i < D; i++) { + periods[i] = 1; /* true */ } - reorder = 1; /* true */ + reorder = 1; /* true */ - dims[0] = npx; - dims[1] = npy; - dims[2] = npz; + dims[0] = npx; + dims[1] = npy; + dims[2] = npz; - MPI_Cart_create(MPI_COMM_WORLD, D, dims, periods, reorder, &new_comm); + MPI_Cart_create(MPI_COMM_WORLD, D, dims, periods, reorder, &new_comm); - for ( i=0; i<D; i++ ) - { - distrib[i] = MPI_DISTRIBUTE_BLOCK; - dargs[i] = MPI_DISTRIBUTE_DFLT_DARG; -/* psize[i] = 0; */ + for (i = 0; i < D; i++) { + distrib[i] = MPI_DISTRIBUTE_BLOCK; + dargs[i] = MPI_DISTRIBUTE_DFLT_DARG; + /* psize[i] = 0; */ } - gsize[0] = X; - gsize[1] = Y; - gsize[2] = Z; + gsize[0] = X; + gsize[1] = Y; + gsize[2] = Z; - psize[0] = npx; - psize[1] = npy; - psize[2] = npz; + psize[0] = npx; + psize[1] = npy; + psize[2] = npz; -/* - MPI_Dims_create(npes, D, psize); + /* + MPI_Dims_create(npes, D, psize); - printf("psize %d %d %d\n",psize[0],psize[1],psize[2]); -*/ + printf("psize %d %d %d\n",psize[0],psize[1],psize[2]); + */ - MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_FORTRAN, MPI_INT, &filetype); -/*MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_C, MPI_INT, &filetype); don't do this */ + MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_FORTRAN, MPI_INT, + &filetype); + /*MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_C, MPI_INT, + * &filetype); don't do this */ - MPI_Type_commit(&filetype); + MPI_Type_commit(&filetype); - to1 = MPI_Wtime(); - MPI_File_open(new_comm, argv[1], MPI_MODE_WRONLY | MPI_MODE_CREATE, info, &thefile); - to2 = MPI_Wtime(); + to1 = MPI_Wtime(); + MPI_File_open(new_comm, argv[1], MPI_MODE_WRONLY | MPI_MODE_CREATE, info, &thefile); + to2 = MPI_Wtime(); - MPI_File_set_size(thefile, offset); + MPI_File_set_size(thefile, offset); - MPI_File_set_view(thefile, offset, MPI_INT, filetype, "native", MPI_INFO_NULL); + MPI_File_set_view(thefile, offset, MPI_INT, filetype, "native", MPI_INFO_NULL); - t1 = MPI_Wtime(); - for ( i=0; i<LOOP; i++) - { - MPI_File_write_all(thefile, buf, ng, MPI_INT, &status); + t1 = MPI_Wtime(); + for (i = 0; i < LOOP; i++) { + MPI_File_write_all(thefile, buf, ng, MPI_INT, &status); } - t2 = MPI_Wtime(); + t2 = MPI_Wtime(); - tc1 = MPI_Wtime(); - MPI_File_close(&thefile); - tc2 = MPI_Wtime(); + tc1 = MPI_Wtime(); + MPI_File_close(&thefile); + tc2 = MPI_Wtime(); - et = (t2 - t1)/LOOP; - eto = (to2 - to1)/LOOP; - etc = (tc2 - tc1)/LOOP; + et = (t2 - t1) / LOOP; + eto = (to2 - to1) / LOOP; + etc = (tc2 - tc1) / LOOP; - mbs = (((double)(LOOP*X*Y*Z)*sizeof(int)))/(1000000.0*(t2-t1)); + mbs = (((double) (LOOP * X * Y * Z) * sizeof(int))) / (1000000.0 * (t2 - t1)); -/*printf(" %s[%3d] ET %8.2f %8.2f %8.2f %8.1f mbs\n", process_name, rank, t1, t2, t2-t1, mbs);*/ + /*printf(" %s[%3d] ET %8.2f %8.2f %8.2f %8.1f mbs\n", process_name, rank, t1, t2, + * t2-t1, mbs);*/ - MPI_Barrier(MPI_COMM_WORLD); + MPI_Barrier(MPI_COMM_WORLD); - MPI_Reduce(&mbs, &avg_mbs, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&mbs, &min_mbs, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&mbs, &max_mbs, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &avg_mbs, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &min_mbs, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&mbs, &max_mbs, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &avg_et, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &min_et, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&et, &max_et, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &avg_et, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &min_et, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&et, &max_et, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &avg_eto, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &min_eto, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&eto, &max_eto, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &avg_eto, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &min_eto, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&eto, &max_eto, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &avg_etc, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &min_etc, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); - MPI_Reduce(&etc, &max_etc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &avg_etc, 1, MPI_DOUBLE, MPI_SUM, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &min_etc, 1, MPI_DOUBLE, MPI_MIN, 0, MPI_COMM_WORLD); + MPI_Reduce(&etc, &max_etc, 1, MPI_DOUBLE, MPI_MAX, 0, MPI_COMM_WORLD); - fflush(stdout); + fflush(stdout); - if ( rank == 0 ) - { - mbs = avg_mbs/npes; - printf("\n average write rate: %9.1f mbs\n", mbs); - printf(" minimum write rate: %9.1f mbs\n", min_mbs); - printf(" maximum write rate: %9.1f mbs\n\n", max_mbs); - avg_eto = avg_eto/npes; - avg_et = avg_et/npes; - avg_etc = avg_etc/npes; - printf(" open time: %9.3f min %9.3f avg %9.3f max\n",min_eto,avg_eto,max_eto); - printf(" write time: %9.3f min %9.3f avg %9.3f max\n",min_et,avg_et,max_et); - printf(" close time: %9.3f min %9.3f avg %9.3f max\n\n",min_etc,avg_etc,max_etc); - fflush(stdout); + if (rank == 0) { + mbs = avg_mbs / npes; + printf("\n average write rate: %9.1f mbs\n", mbs); + printf(" minimum write rate: %9.1f mbs\n", min_mbs); + printf(" maximum write rate: %9.1f mbs\n\n", max_mbs); + avg_eto = avg_eto / npes; + avg_et = avg_et / npes; + avg_etc = avg_etc / npes; + printf(" open time: %9.3f min %9.3f avg %9.3f max\n", min_eto, avg_eto, max_eto); + printf(" write time: %9.3f min %9.3f avg %9.3f max\n", min_et, avg_et, max_et); + printf(" close time: %9.3f min %9.3f avg %9.3f max\n\n", min_etc, avg_etc, max_etc); + fflush(stdout); } - MPI_Finalize(); + MPI_Finalize(); - return 0; + return 0; } diff --git a/test/simple/parallel_w8.c b/test/simple/parallel_w8.c index 49fc00a10d..87eb41f696 100644 --- a/test/simple/parallel_w8.c +++ b/test/simple/parallel_w8.c @@ -4,91 +4,83 @@ #include <stdio.h> #include <string.h> -#define D 3 /* dimensions */ +#define D 3 /* dimensions */ -#define X 256 /* global x grid size */ -#define Y 256 /* global y grid size */ -#define Z 256 /* global z grid size */ +#define X 256 /* global x grid size */ +#define Y 256 /* global y grid size */ +#define Z 256 /* global z grid size */ -#define nx 128 /* local x grid size */ -#define ny 128 /* local y grid size */ -#define nz 128 /* local z grid size */ +#define nx 128 /* local x grid size */ +#define ny 128 /* local y grid size */ +#define nz 128 /* local z grid size */ -#define ng (nx*ny*nz) /* local grid (cube) size */ +#define ng (nx * ny * nz) /* local grid (cube) size */ -#define npx 2 /* number of PE's in x direction */ -#define npy 2 /* number of PE's in y direction */ -#define npz 2 /* number of PE's in z direction */ +#define npx 2 /* number of PE's in x direction */ +#define npy 2 /* number of PE's in y direction */ +#define npz 2 /* number of PE's in z direction */ -#define np (npx*npy*npz) /* total PE count */ +#define np (npx * npy * npz) /* total PE count */ #define LOOP 1 #define MAX_RR_NAME 7 -int -main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - int i, rank, npes, bug=0; + int i, rank, npes, bug = 0; int buf[ng]; - MPI_File thefile; - MPI_Status status; + MPI_File thefile; + MPI_Status status; MPI_Datatype filetype; - MPI_Comm new_comm; - MPI_Offset offset=0; - MPI_Info info=MPI_INFO_NULL; - int gsize[D],distrib[D],dargs[D],psize[D]; - int dims[D],periods[D],reorder; - double t1,t2,mbs; - double to1,to2,tc1,tc2; - double et,eto,etc; - double max_mbs,min_mbs,avg_mbs; - double max_et,min_et,avg_et; - double max_eto,min_eto,avg_eto; - double max_etc,min_etc,avg_etc; + MPI_Comm new_comm; + MPI_Offset offset = 0; + MPI_Info info = MPI_INFO_NULL; + int gsize[D], distrib[D], dargs[D], psize[D]; + int dims[D], periods[D], reorder; + double t1, t2, mbs; + double to1, to2, tc1, tc2; + double et, eto, etc; + double max_mbs, min_mbs, avg_mbs; + double max_et, min_et, avg_et; + double max_eto, min_eto, avg_eto; + double max_etc, min_etc, avg_etc; char process_name[MPI_MAX_PROCESSOR_NAME + 1]; char rr_blank[] = {" "}; char rr_empty[] = {"???????"}; - int count; + int count; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &npes); - if ( rank == 0 ) - { - if ( argc < 2 ) - { + if (rank == 0) { + if (argc < 2) { printf(" ERROR: no filename given\n"); bug++; } - if ( npes == np ) - { - printf(" file name: %s\n",argv[1]); - printf(" total number of PE's: %3d\n",np); - printf(" number of PE's in x direction: %4d\n",npx); - printf(" number of PE's in y direction: %4d\n",npy); - printf(" number of PE's in z direction: %4d\n",npz); - printf(" global grid size: %dx%dx%d 4 byte integers (total %lu)\n",X,Y,Z,(unsigned long)X*Y*Z); - printf(" local grid size: %dx%dx%d 4 byte integers (total %d)\n",nx,ny,nz,ng); - } - else - { - printf(" ERROR: total number of PE's must be %d\n",np); - printf(" actual number of PE's was %d\n",npes); + if (npes == np) { + printf(" file name: %s\n", argv[1]); + printf(" total number of PE's: %3d\n", np); + printf(" number of PE's in x direction: %4d\n", npx); + printf(" number of PE's in y direction: %4d\n", npy); + printf(" number of PE's in z direction: %4d\n", npz); + printf(" global grid size: %dx%dx%d 4 byte integers (total %lu)\n", X, Y, Z, + (unsigned long) X * Y * Z); + printf(" local grid size: %dx%dx%d 4 byte integers (total %d)\n", nx, ny, nz, ng); + } else { + printf(" ERROR: total number of PE's must be %d\n", np); + printf(" actual number of PE's was %d\n", npes); bug++; } - if ( bug ) - { - MPI_Abort(MPI_COMM_WORLD,-1); + if (bug) { + MPI_Abort(MPI_COMM_WORLD, -1); } } - if ( MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) - { + if (MPI_Get_processor_name(process_name, &count) != MPI_SUCCESS) { sprintf(process_name, "%s", rr_empty); - } - else - { - if (count < MAX_RR_NAME) strncat(&process_name[count],rr_blank,MAX_RR_NAME-count); + } else { + if (count < MAX_RR_NAME) + strncat(&process_name[count], rr_blank, MAX_RR_NAME - count); process_name[MAX_RR_NAME] = '\0'; } @@ -117,15 +109,14 @@ main(int argc, char* argv[]) sprintf(awpa,"%d",i); MPI_Info_set (info,"cb_nodes",awpa);*/ + for (i = 0; i < ng; i++) + buf[i] = rank * 10000 + (i + 1) % 1024; - for ( i=0; i<ng; i++ ) buf[i] = rank*10000 + (i+1)%1024; - - for ( i=0; i<D; i++ ) - { - periods[i] = 1; /* true */ + for (i = 0; i < D; i++) { + periods[i] = 1; /* true */ } - reorder = 1; /* true */ + reorder = 1; /* true */ dims[0] = npx; dims[1] = npy; @@ -133,10 +124,9 @@ main(int argc, char* argv[]) MPI_Cart_create(MPI_COMM_WORLD, D, dims, periods, reorder, &new_comm); - for ( i=0; i<D; i++ ) - { + for (i = 0; i < D; i++) { distrib[i] = MPI_DISTRIBUTE_BLOCK; - dargs[i] = MPI_DISTRIBUTE_DFLT_DARG; + dargs[i] = MPI_DISTRIBUTE_DFLT_DARG; /* psize[i] = 0; */ } @@ -154,8 +144,10 @@ main(int argc, char* argv[]) printf("psize %d %d %d\n",psize[0],psize[1],psize[2]); */ - MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_FORTRAN, MPI_INT, &filetype); - /*MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_C, MPI_INT, &filetype); don't do this */ + MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_FORTRAN, MPI_INT, + &filetype); + /*MPI_Type_create_darray(npes, rank, D, gsize, distrib, dargs, psize, MPI_ORDER_C, MPI_INT, + * &filetype); don't do this */ MPI_Type_commit(&filetype); @@ -168,8 +160,7 @@ main(int argc, char* argv[]) MPI_File_set_view(thefile, offset, MPI_INT, filetype, "native", MPI_INFO_NULL); t1 = MPI_Wtime(); - for ( i=0; i<LOOP; i++) - { + for (i = 0; i < LOOP; i++) { MPI_File_write_all(thefile, buf, ng, MPI_INT, &status); } t2 = MPI_Wtime(); @@ -178,13 +169,14 @@ main(int argc, char* argv[]) MPI_File_close(&thefile); tc2 = MPI_Wtime(); - et = (t2 - t1)/LOOP; - eto = (to2 - to1)/LOOP; - etc = (tc2 - tc1)/LOOP; + et = (t2 - t1) / LOOP; + eto = (to2 - to1) / LOOP; + etc = (tc2 - tc1) / LOOP; - mbs = (((double)(LOOP*X*Y*Z)*sizeof(int)))/(1000000.0*(t2-t1)); + mbs = (((double) (LOOP * X * Y * Z) * sizeof(int))) / (1000000.0 * (t2 - t1)); - /*printf(" %s[%3d] ET %8.2f %8.2f %8.2f %8.1f mbs\n", process_name, rank, t1, t2, t2-t1, mbs);*/ + /*printf(" %s[%3d] ET %8.2f %8.2f %8.2f %8.1f mbs\n", process_name, rank, t1, t2, + * t2-t1, mbs);*/ MPI_Barrier(MPI_COMM_WORLD); @@ -206,18 +198,17 @@ main(int argc, char* argv[]) fflush(stdout); - if ( rank == 0 ) - { - mbs = avg_mbs/npes; + if (rank == 0) { + mbs = avg_mbs / npes; printf("\n average write rate: %9.1f mbs\n", mbs); printf(" minimum write rate: %9.1f mbs\n", min_mbs); printf(" maximum write rate: %9.1f mbs\n\n", max_mbs); - avg_eto = avg_eto/npes; - avg_et = avg_et/npes; - avg_etc = avg_etc/npes; - printf(" open time: %9.3f min %9.3f avg %9.3f max\n",min_eto,avg_eto,max_eto); - printf(" write time: %9.3f min %9.3f avg %9.3f max\n",min_et,avg_et,max_et); - printf(" close time: %9.3f min %9.3f avg %9.3f max\n\n",min_etc,avg_etc,max_etc); + avg_eto = avg_eto / npes; + avg_et = avg_et / npes; + avg_etc = avg_etc / npes; + printf(" open time: %9.3f min %9.3f avg %9.3f max\n", min_eto, avg_eto, max_eto); + printf(" write time: %9.3f min %9.3f avg %9.3f max\n", min_et, avg_et, max_et); + printf(" close time: %9.3f min %9.3f avg %9.3f max\n\n", min_etc, avg_etc, max_etc); fflush(stdout); } diff --git a/test/simple/pinterlib.c b/test/simple/pinterlib.c index 40d7f8846a..f6e1519022 100644 --- a/test/simple/pinterlib.c +++ b/test/simple/pinterlib.c @@ -5,10 +5,10 @@ * The most basic of MPI applications */ -#include <stdio.h> -#include <pthread.h> #include "mpi.h" #include "pmix.h" +#include <pthread.h> +#include <stdio.h> typedef struct { pthread_mutex_t mutex; @@ -17,77 +17,72 @@ typedef struct { pmix_status_t status; } mylock_t; -#define MY_CONSTRUCT_LOCK(l) \ - do { \ - pthread_mutex_init(&(l)->mutex, NULL); \ - pthread_cond_init(&(l)->cond, NULL); \ - (l)->active = true; \ - (l)->status = PMIX_SUCCESS; \ - } while(0) +#define MY_CONSTRUCT_LOCK(l) \ + do { \ + pthread_mutex_init(&(l)->mutex, NULL); \ + pthread_cond_init(&(l)->cond, NULL); \ + (l)->active = true; \ + (l)->status = PMIX_SUCCESS; \ + } while (0) -#define MY_DESTRUCT_LOCK(l) \ +#define MY_DESTRUCT_LOCK(l) \ do { \ pthread_mutex_destroy(&(l)->mutex); \ pthread_cond_destroy(&(l)->cond); \ - } while(0) - -#define MY_WAIT_THREAD(lck) \ - do { \ - pthread_mutex_lock(&(lck)->mutex); \ - while ((lck)->active) { \ - pthread_cond_wait(&(lck)->cond, &(lck)->mutex); \ - } \ - pthread_mutex_unlock(&(lck)->mutex); \ - } while(0) - -#define MY_WAKEUP_THREAD(lck) \ - do { \ - pthread_mutex_lock(&(lck)->mutex); \ - (lck)->active = false; \ - pthread_cond_broadcast(&(lck)->cond); \ - pthread_mutex_unlock(&(lck)->mutex); \ - } while(0) - + } while (0) + +#define MY_WAIT_THREAD(lck) \ + do { \ + pthread_mutex_lock(&(lck)->mutex); \ + while ((lck)->active) { \ + pthread_cond_wait(&(lck)->cond, &(lck)->mutex); \ + } \ + pthread_mutex_unlock(&(lck)->mutex); \ + } while (0) + +#define MY_WAKEUP_THREAD(lck) \ + do { \ + pthread_mutex_lock(&(lck)->mutex); \ + (lck)->active = false; \ + pthread_cond_broadcast(&(lck)->cond); \ + pthread_mutex_unlock(&(lck)->mutex); \ + } while (0) static size_t interlibhandler_id = SIZE_MAX; static mylock_t thread_complete; static pmix_proc_t myproc; -static void model_registration_callback(pmix_status_t status, - size_t errhandler_ref, - void *cbdata) +static void model_registration_callback(pmix_status_t status, size_t errhandler_ref, void *cbdata) { - mylock_t *lock = (mylock_t*)cbdata; + mylock_t *lock = (mylock_t *) cbdata; interlibhandler_id = errhandler_ref; MY_WAKEUP_THREAD(lock); } -static void model_callback(size_t evhdlr_registration_id, - pmix_status_t status, - const pmix_proc_t *source, - pmix_info_t info[], size_t ninfo, +static void model_callback(size_t evhdlr_registration_id, pmix_status_t status, + const pmix_proc_t *source, pmix_info_t info[], size_t ninfo, pmix_info_t *results, size_t nresults, - pmix_event_notification_cbfunc_fn_t cbfunc, - void *cbdata) + pmix_event_notification_cbfunc_fn_t cbfunc, void *cbdata) { size_t n; /* we can ignore our own callback as we obviously * know that we are OpenMP */ if (NULL != info) { - for (n=0; n < ninfo; n++) { - if (0 == strcmp(info[n].key, PMIX_PROGRAMMING_MODEL) && - 0 == strcmp(info[n].value.data.string, "OpenMP")) { + for (n = 0; n < ninfo; n++) { + if (0 == strcmp(info[n].key, PMIX_PROGRAMMING_MODEL) + && 0 == strcmp(info[n].value.data.string, "OpenMP")) { goto cback; } if (PMIX_STRING == info[n].value.type) { - fprintf(stderr, "Thread Model Callback Key: %s Val %s\n", info[n].key, info[n].value.data.string); + fprintf(stderr, "Thread Model Callback Key: %s Val %s\n", info[n].key, + info[n].value.data.string); } } } /* otherwise, do something clever here */ - cback: +cback: /* we must NOT tell the event handler state machine that we * are the last step as that will prevent it from notifying * anyone else that might be listening for declarations */ @@ -99,20 +94,17 @@ static void model_callback(size_t evhdlr_registration_id, static void opcbfunc(pmix_status_t status, void *cbdata) { - mylock_t *lock = (mylock_t*)cbdata; + mylock_t *lock = (mylock_t *) cbdata; MY_WAKEUP_THREAD(lock); } -static void infocb(pmix_status_t status, - pmix_info_t *info, size_t ninfo, - void *cbdata, - pmix_release_cbfunc_t release_fn, - void *release_cbdata) +static void infocb(pmix_status_t status, pmix_info_t *info, size_t ninfo, void *cbdata, + pmix_release_cbfunc_t release_fn, void *release_cbdata) { - mylock_t *lock = (mylock_t*)cbdata; + mylock_t *lock = (mylock_t *) cbdata; size_t n; - for (n=0; n < ninfo; n++) { + for (n = 0; n < ninfo; n++) { fprintf(stderr, "QUERY DATA KEY: %s VALUE %s\n", info[n].key, info[n].value.data.string); } if (NULL != release_fn) { @@ -155,10 +147,8 @@ static void *mylib(void *ptr) /* it is, so let's just use the event notification * API to let everyone know we are here */ MY_CONSTRUCT_LOCK(&lock); - ret = PMIx_Notify_event(code, &myproc, - PMIX_RANGE_PROC_LOCAL, - info, 5, - opcbfunc, (void*)&lock); + ret = PMIx_Notify_event(code, &myproc, PMIX_RANGE_PROC_LOCAL, info, 5, opcbfunc, + (void *) &lock); MY_WAIT_THREAD(&lock); MY_DESTRUCT_LOCK(&lock); } else { @@ -178,10 +168,8 @@ static void *mylib(void *ptr) * the event stipulates its range as proc_local. We rely * on that here */ MY_CONSTRUCT_LOCK(&lock); - PMIx_Register_event_handler(&code, 1, directives, 1, - model_callback, - model_registration_callback, - (void*)&lock); + PMIx_Register_event_handler(&code, 1, directives, 1, model_callback, + model_registration_callback, (void *) &lock); MY_WAIT_THREAD(&lock); MY_DESTRUCT_LOCK(&lock); PMIX_INFO_FREE(directives, 1); @@ -235,7 +223,7 @@ static void *mylib(void *ptr) return NULL; } -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size, rc; pid_t pid; @@ -295,7 +283,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "Error joining thread\n"); } - done: +done: MPI_Finalize(); return 0; } diff --git a/test/simple/pmix.c b/test/simple/pmix.c index 3ee3f2fcce..859bb8f0ac 100644 --- a/test/simple/pmix.c +++ b/test/simple/pmix.c @@ -10,29 +10,28 @@ */ /* * To compile test: - * mpicc -I$src_dir -I$src_dir/opal/include -I$src_dir/orte/include -I$src_dir/ompi/include -DOMPI_BUILDING=1 pmix.c -o pmix - * To run test: - * mpirun -np 2 <any mca params> ./pmix - * Test should print "Passed" in case of success and print pmix time intervals at process with rank 0. + * mpicc -I$src_dir -I$src_dir/opal/include -I$src_dir/orte/include -I$src_dir/ompi/include + * -DOMPI_BUILDING=1 pmix.c -o pmix To run test: mpirun -np 2 <any mca params> ./pmix Test should + * print "Passed" in case of success and print pmix time intervals at process with rank 0. * */ -#include <stdio.h> -#include <unistd.h> #include <mpi.h> -#include <time.h> +#include <stdio.h> #include <sys/time.h> +#include <time.h> +#include <unistd.h> +#include "ompi/proc/proc.h" #include "opal/class/opal_list.h" #include "opal/mca/pmix/pmix.h" -#include "ompi/proc/proc.h" -#define DO_FINALIZE(rc,flag,format,args...) \ - do { \ - if (flag) { \ - fprintf(stderr, format, args); \ - } \ - MPI_Finalize(); \ - return rc; \ - } while(0); +#define DO_FINALIZE(rc, flag, format, args...) \ + do { \ + if (flag) { \ + fprintf(stderr, format, args); \ + } \ + MPI_Finalize(); \ + return rc; \ + } while (0); static int my_rank; static volatile bool waiting = true; @@ -44,10 +43,8 @@ static double get_timestamp(void) return ((tv.tv_sec) + (tv.tv_usec) * 1.0e-6); } -static void evhandler(int status, - const opal_process_name_t *source, - opal_list_t *info, opal_list_t *results, - opal_pmix_notification_complete_fn_t cbfunc, +static void evhandler(int status, const opal_process_name_t *source, opal_list_t *info, + opal_list_t *results, opal_pmix_notification_complete_fn_t cbfunc, void *cbdata) { fprintf(stderr, "%d: received notification status %d\n", my_rank, status); @@ -57,7 +54,7 @@ static void evhandler(int status, waiting = false; } -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rc; int recv_data; @@ -90,12 +87,12 @@ int main(int argc, char* argv[]) opal_pmix.commit(); opal_pmix.fence(NULL, 1); t3 = get_timestamp(); - procs = ompi_proc_world ( &numprocs ); + procs = ompi_proc_world(&numprocs); ptr = &recv_data; t4 = get_timestamp(); - for ( i = 0; i < numprocs; i++ ) { + for (i = 0; i < numprocs; i++) { thisproc = procs[i]; - OPAL_MODEX_RECV_VALUE(rc, "MY_RANK", &thisproc->super.proc_name, (void**)&ptr, OPAL_INT); + OPAL_MODEX_RECV_VALUE(rc, "MY_RANK", &thisproc->super.proc_name, (void **) &ptr, OPAL_INT); /* check return status and received data */ if (OPAL_SUCCESS != rc || i != recv_data) { rc = OPAL_ERROR; @@ -109,13 +106,13 @@ int main(int argc, char* argv[]) t6 = get_timestamp(); fprintf(stderr, "[%d] Test passed.\n", my_rank); - fprintf(stderr, "[%d] \"MODEX_SEND\" %f\n", my_rank, t1-t0); - fprintf(stderr, "[%d] \"FENCE\" %f\n", my_rank, t3-t2); - fprintf(stderr, "[%d] \"MODEX_RECV\" %f\n", my_rank, t5-t4); - fprintf(stderr, "[%d] \"BARRIER\" %f\n", my_rank, t6-t5); - fprintf(stderr, "[%d] \"TOTAL\" %f\n", my_rank, t6-t0); + fprintf(stderr, "[%d] \"MODEX_SEND\" %f\n", my_rank, t1 - t0); + fprintf(stderr, "[%d] \"FENCE\" %f\n", my_rank, t3 - t2); + fprintf(stderr, "[%d] \"MODEX_RECV\" %f\n", my_rank, t5 - t4); + fprintf(stderr, "[%d] \"BARRIER\" %f\n", my_rank, t6 - t5); + fprintf(stderr, "[%d] \"TOTAL\" %f\n", my_rank, t6 - t0); - fprintf(stderr, "[%d] Pid %d waiting for notification\n", my_rank, (int)getpid()); + fprintf(stderr, "[%d] Pid %d waiting for notification\n", my_rank, (int) getpid()); /* now wait for notification of someone failing */ tp.tv_sec = 0; diff --git a/test/simple/pubsub.c b/test/simple/pubsub.c index f5ce1e966d..792eb28d3b 100644 --- a/test/simple/pubsub.c +++ b/test/simple/pubsub.c @@ -5,17 +5,17 @@ * The most basic of MPI applications */ -#include <stdio.h> +#include "mpi.h" #include <stdbool.h> +#include <stdio.h> #include <string.h> -#include "mpi.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; MPI_Info info, srch; char port[MPI_MAX_PORT_NAME]; - bool local=false; + bool local = false; if (1 < argc) { if (0 == strcmp("local", argv[1])) { diff --git a/test/simple/reduce-hang.c b/test/simple/reduce-hang.c index 3a1e70c1ac..20cb6c479e 100644 --- a/test/simple/reduce-hang.c +++ b/test/simple/reduce-hang.c @@ -8,8 +8,8 @@ int main(int argc, char *argv[]) int i = 8, j; int self; int do_barrier = 0; -int k; -double pi; + int k; + double pi; if (getenv("DO_BARRIER")) { do_barrier = 1; diff --git a/test/simple/ring.c b/test/simple/ring.c index f452fd466b..a86a323440 100644 --- a/test/simple/ring.c +++ b/test/simple/ring.c @@ -1,9 +1,9 @@ -#include <stdlib.h> -#include <stdio.h> #include <mpi.h> +#include <stdio.h> +#include <stdlib.h> -#define SIZE 20 -#define POS 10 +#define SIZE 20 +#define POS 10 #define INITIAL_VALUE 10 int main(int argc, char *argv[]) @@ -32,14 +32,12 @@ int main(int argc, char *argv[]) if (0 == rank) { send_array[pos] = INITIAL_VALUE; - MPI_Send(send_array, array_size, MPI_INT, next, tag, - MPI_COMM_WORLD); + MPI_Send(send_array, array_size, MPI_INT, next, tag, MPI_COMM_WORLD); } while (1) { recv_array[pos] = -1; - MPI_Recv(recv_array, array_size, MPI_INT, prev, tag, - MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(recv_array, array_size, MPI_INT, prev, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); send_array[pos] = recv_array[pos]; if (rank == 0) { --send_array[pos]; @@ -51,8 +49,7 @@ int main(int argc, char *argv[]) } if (rank == 0) { - MPI_Recv(recv_array, array_size, MPI_INT, prev, tag, - MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(recv_array, array_size, MPI_INT, prev, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } fprintf(stderr, "Rank %d has completed ring\n", rank); diff --git a/test/simple/segv.c b/test/simple/segv.c index cde8badb93..4e816e9f26 100644 --- a/test/simple/segv.c +++ b/test/simple/segv.c @@ -5,14 +5,14 @@ * The most basic of MPI applications */ +#include "mpi.h" #include <stdio.h> #include <unistd.h> -#include "mpi.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; - char *foo=0; + char *foo = 0; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); diff --git a/test/simple/sendrecv_blaster.c b/test/simple/sendrecv_blaster.c index e60ea468fe..0143054c9b 100644 --- a/test/simple/sendrecv_blaster.c +++ b/test/simple/sendrecv_blaster.c @@ -3,55 +3,56 @@ #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> -#include <time.h> #include <sys/time.h> +#include <time.h> +#include <unistd.h> #include "mpi.h" int main(int argc, char *argv[]) { - MPI_Status status; /* MPI status */ - int mpierr; /* MPI function return code */ - int rank; /* Process rank within MPI_COMM_WORLD */ - int size; - int dest, src; - int tag0=41; /* MPI message tag */ - - int inject; - int report; - int iterations; - int n_bytes; - unsigned char* send_buff; - unsigned char* recv_buff; - char* tmp; - - int i, j, count; + MPI_Status status; /* MPI status */ + int mpierr; /* MPI function return code */ + int rank; /* Process rank within MPI_COMM_WORLD */ + int size; + int dest, src; + int tag0 = 41; /* MPI message tag */ + + int inject; + int report; + int iterations; + int n_bytes; + unsigned char *send_buff; + unsigned char *recv_buff; + char *tmp; + + int i, j, count; float fraction, randval; struct timeval tp; if (1 < argc) { - if (0 == strncmp(argv[1], "-h", 2) || - 0 == strncmp(argv[1], "--h", 3)) { - printf("Usage: mpirun --options-- ./sendrecv_blaster <options> where options are:\n" - "\tpattern=[self | pair | ring] where\n" - "\t\tself => sendrecv with self\n" - "\t\tpair => sendrecv with a complementary partner [0 <-> N-1, 1 <-> N-2...]\n" - "\t\tring [default] => sendrecv around a ring [0 recvs from N-1 and sends to 1]\n" - "\tsize=[value < 0 => max message size in kbytes, value > 0 => max message size in Mbytes (default=1MByte)]\n" - "\tinject=[value = #iterations before injecting MPI_Sendrecv to self (default: never)]\n" - "\treport=[value = #iterations/reporting point (default: 1000)\n" - "\titerations=[value = #iterations before stopping (default: 1000000)\n"); + if (0 == strncmp(argv[1], "-h", 2) || 0 == strncmp(argv[1], "--h", 3)) { + printf( + "Usage: mpirun --options-- ./sendrecv_blaster <options> where options are:\n" + "\tpattern=[self | pair | ring] where\n" + "\t\tself => sendrecv with self\n" + "\t\tpair => sendrecv with a complementary partner [0 <-> N-1, 1 <-> N-2...]\n" + "\t\tring [default] => sendrecv around a ring [0 recvs from N-1 and sends to 1]\n" + "\tsize=[value < 0 => max message size in kbytes, value > 0 => max message size in " + "Mbytes (default=1MByte)]\n" + "\tinject=[value = #iterations before injecting MPI_Sendrecv to self (default: " + "never)]\n" + "\treport=[value = #iterations/reporting point (default: 1000)\n" + "\titerations=[value = #iterations before stopping (default: 1000000)\n"); return 0; } } mpierr = MPI_Init(&argc, &argv); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr, "MPI Error %d (MPI_Init)\n",mpierr); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Init)\n", mpierr); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } @@ -59,23 +60,21 @@ int main(int argc, char *argv[]) MPI_Comm_set_errhandler(MPI_COMM_WORLD, MPI_ERRORS_RETURN); mpierr = MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if (mpierr != MPI_SUCCESS || rank < 0) - { - fprintf(stderr, "MPI Error %d (MPI_Comm_rank)\n",mpierr); + if (mpierr != MPI_SUCCESS || rank < 0) { + fprintf(stderr, "MPI Error %d (MPI_Comm_rank)\n", mpierr); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } mpierr = MPI_Comm_size(MPI_COMM_WORLD, &size); - if (mpierr != MPI_SUCCESS || size < 0) - { - fprintf(stderr, "MPI Error %d (MPI_Comm_size)\n",mpierr); + if (mpierr != MPI_SUCCESS || size < 0) { + fprintf(stderr, "MPI Error %d (MPI_Comm_size)\n", mpierr); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } /* setup defaults in lieu of args */ - n_bytes = 1024*1024; + n_bytes = 1024 * 1024; inject = -1; report = 1000; iterations = 1000000; @@ -85,11 +84,11 @@ int main(int argc, char *argv[]) src = size - 1; } dest = rank + 1; - if (dest > size-1) { + if (dest > size - 1) { dest = 0; } - for (i=1; i < argc; i++) { + for (i = 1; i < argc; i++) { fprintf(stderr, "got %s\n", argv[i]); if (0 == strncmp(argv[i], "pattern", strlen("pattern"))) { tmp = strchr(argv[i], '='); @@ -100,7 +99,7 @@ int main(int argc, char *argv[]) dest = rank; } else if (0 == strcmp(tmp, "pair")) { /* do it pair-wise */ - src = (size-1) - rank; + src = (size - 1) - rank; dest = src; } else { /* do a ring */ @@ -109,7 +108,7 @@ int main(int argc, char *argv[]) src = size - 1; } dest = rank + 1; - if (dest > size-1) { + if (dest > size - 1) { dest = 0; } } @@ -120,7 +119,7 @@ int main(int argc, char *argv[]) if (n_bytes < 0) { n_bytes = -1 * n_bytes * 1024; } else { - n_bytes = n_bytes * 1024*1024; + n_bytes = n_bytes * 1024 * 1024; } } else if (0 == strncmp(argv[i], "inject", strlen("inject"))) { tmp = strchr(argv[i], '='); @@ -141,41 +140,39 @@ int main(int argc, char *argv[]) recv_buff = (unsigned char *) valloc(n_bytes); /* seed the random number generator */ - gettimeofday (&tp, NULL); - srand (tp.tv_usec); + gettimeofday(&tp, NULL); + srand(tp.tv_usec); - for ( i=0; i<n_bytes; i++ ) - { - send_buff[i] = i%128; + for (i = 0; i < n_bytes; i++) { + send_buff[i] = i % 128; } fprintf(stderr, "Rank %d: recving from src %d sending to dest %d with max buff size %dKbytes\n", - rank, src, dest, n_bytes/1024); + rank, src, dest, n_bytes / 1024); - i=0; - while (i < iterations) - { + i = 0; + while (i < iterations) { randval = rand(); - fraction = randval/RAND_MAX; + fraction = randval / RAND_MAX; count = fraction * n_bytes; - mpierr = MPI_Sendrecv(send_buff, count, MPI_CHAR, dest, tag0, - recv_buff, n_bytes, MPI_CHAR, src, tag0, MPI_COMM_WORLD, &status); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Sendrecv) [%d,%d] at iteration %d\n",mpierr,src,dest,i); + mpierr = MPI_Sendrecv(send_buff, count, MPI_CHAR, dest, tag0, recv_buff, n_bytes, MPI_CHAR, + src, tag0, MPI_COMM_WORLD, &status); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Sendrecv) [%d,%d] at iteration %d\n", mpierr, src, + dest, i); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } i++; if (0 == (i % report)) { - fprintf(stderr, "Rank %d has completed %dk iterations\n", rank, i/1000); + fprintf(stderr, "Rank %d has completed %dk iterations\n", rank, i / 1000); } if (0 < inject && 0 == (i % inject)) { - mpierr = MPI_Sendrecv(send_buff, count, MPI_CHAR, rank, tag0, - recv_buff, n_bytes, MPI_CHAR, rank, tag0, MPI_COMM_WORLD, &status); - if (mpierr != MPI_SUCCESS) - { - fprintf(stderr,"MPI Error %d (MPI_Sendrecv) [%d,%d] at iteration %d\n",mpierr,rank,rank,i); + mpierr = MPI_Sendrecv(send_buff, count, MPI_CHAR, rank, tag0, recv_buff, n_bytes, + MPI_CHAR, rank, tag0, MPI_COMM_WORLD, &status); + if (mpierr != MPI_SUCCESS) { + fprintf(stderr, "MPI Error %d (MPI_Sendrecv) [%d,%d] at iteration %d\n", mpierr, + rank, rank, i); fflush(stderr); MPI_Abort(MPI_COMM_WORLD, -1); } else { diff --git a/test/simple/server.c b/test/simple/server.c index c5f8ec16b4..60e9a6ff10 100644 --- a/test/simple/server.c +++ b/test/simple/server.c @@ -1,55 +1,50 @@ +#include "mpi.h" +#include <errno.h> #include <stdio.h> #include <stdlib.h> -#include <errno.h> -#include "mpi.h" #define MAX_DATA 100 -int main( int argc, char **argv ) +int main(int argc, char **argv) { - MPI_Comm client; - MPI_Status status; - char port_name[MPI_MAX_PORT_NAME]; - double buf[MAX_DATA]; - int size, again; + MPI_Comm client; + MPI_Status status; + char port_name[MPI_MAX_PORT_NAME]; + double buf[MAX_DATA]; + int size, again; - MPI_Init( &argc, &argv ); - MPI_Comm_size(MPI_COMM_WORLD, &size); - if (size != 1) { - fprintf(stderr, "Server too big - need only 1 rank\n"); - exit(1); - } - MPI_Open_port(MPI_INFO_NULL, port_name); - printf("server available at %s\n",port_name); + MPI_Init(&argc, &argv); + MPI_Comm_size(MPI_COMM_WORLD, &size); + if (size != 1) { + fprintf(stderr, "Server too big - need only 1 rank\n"); + exit(1); + } + MPI_Open_port(MPI_INFO_NULL, port_name); + printf("server available at %s\n", port_name); - while (1) - { - MPI_Comm_accept( port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &client ); - again = 1; + while (1) { + MPI_Comm_accept(port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &client); + again = 1; - while (again) - { - fprintf(stderr, "Server loop %d\n", again); - MPI_Recv( buf, MAX_DATA, MPI_DOUBLE, MPI_ANY_SOURCE, -MPI_ANY_TAG, client, &status ); + while (again) { + fprintf(stderr, "Server loop %d\n", again); + MPI_Recv(buf, MAX_DATA, MPI_DOUBLE, MPI_ANY_SOURCE, MPI_ANY_TAG, client, &status); - switch (status.MPI_TAG) - { - case 0: - fprintf(stderr, "Server recvd terminate cmd\n"); - MPI_Comm_disconnect( &client ); - MPI_Close_port(port_name); - MPI_Finalize(); - return 0; - case 2: /* do something */ - fprintf( stderr, "Do something ...\n" ); - break; - default: - /* Unexpected message type */ - MPI_Abort( MPI_COMM_WORLD, 1 ); - } - ++again; - } - } + switch (status.MPI_TAG) { + case 0: + fprintf(stderr, "Server recvd terminate cmd\n"); + MPI_Comm_disconnect(&client); + MPI_Close_port(port_name); + MPI_Finalize(); + return 0; + case 2: /* do something */ + fprintf(stderr, "Do something ...\n"); + break; + default: + /* Unexpected message type */ + MPI_Abort(MPI_COMM_WORLD, 1); + } + ++again; + } + } } - diff --git a/test/simple/simple_spawn.c b/test/simple/simple_spawn.c index c8d1093ba9..d71f579ee9 100644 --- a/test/simple/simple_spawn.c +++ b/test/simple/simple_spawn.c @@ -1,27 +1,26 @@ #include <stdio.h> #include <stdlib.h> +#include <sys/param.h> #include <sys/types.h> #include <unistd.h> -#include <sys/param.h> - #include <mpi.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int msg, rc; MPI_Comm parent, child; int rank, size; char hostname[1024]; pid_t pid; - char *env_rank,*env_nspace; + char *env_rank, *env_nspace; env_rank = getenv("PMIX_RANK"); env_nspace = getenv("PMIX_NAMESPACE"); pid = getpid(); gethostname(hostname, 1024); - printf("[%s:%s pid %ld] starting up on node %s!\n", env_nspace, env_rank, (long)pid, hostname); + printf("[%s:%s pid %ld] starting up on node %s!\n", env_nspace, env_rank, (long) pid, hostname); MPI_Init(NULL, NULL); MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -31,9 +30,9 @@ int main(int argc, char* argv[]) /* If we get COMM_NULL back, then we're the parent */ if (MPI_COMM_NULL == parent) { pid = getpid(); - printf("Parent [pid %ld] about to spawn!\n", (long)pid); - rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, MPI_INFO_NULL, - 0, MPI_COMM_WORLD, &child, MPI_ERRCODES_IGNORE); + printf("Parent [pid %ld] about to spawn!\n", (long) pid); + rc = MPI_Comm_spawn(argv[0], MPI_ARGV_NULL, 3, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &child, + MPI_ERRCODES_IGNORE); if (MPI_SUCCESS != rc) { printf("Child failed to spawn\n"); return rc; @@ -52,7 +51,7 @@ int main(int argc, char* argv[]) MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); pid = getpid(); - printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long)pid); + printf("Hello from the child %d of %d on host %s pid %ld\n", rank, 3, hostname, (long) pid); if (0 == rank) { MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE); printf("Child %d received msg: %d\n", rank, msg); diff --git a/test/simple/singleton_client_server.c b/test/simple/singleton_client_server.c index 796e30bd5b..08e68e5cc3 100644 --- a/test/simple/singleton_client_server.c +++ b/test/simple/singleton_client_server.c @@ -2,12 +2,12 @@ #include "opal/runtime/opal.h" +#include <errno.h> +#include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <errno.h> #include <unistd.h> -#include <mpi.h> /* @@ -35,178 +35,164 @@ #define TAG 0 -#define CHK(code) do \ - { \ - int retval = code ; \ - if (retval != MPI_SUCCESS) \ - { \ - fprintf(stderr, "Error: " #code "\n") ; \ - exit(1) ; \ - } \ - } while(0) +#define CHK(code) \ + do { \ + int retval = code; \ + if (retval != MPI_SUCCESS) { \ + fprintf(stderr, "Error: " #code "\n"); \ + exit(1); \ + } \ + } while (0) int main(int argc, char *argv[]) { - const char *hostname ; - char buff[255] ; - - int role ; - int num_clients ; - int size, rank ; - int temp_errno ; - - FILE *fp ; - char server_port_name[MPI_MAX_PORT_NAME] ; - - MPI_Comm intercomm, intracomm ; - MPI_Status status ; - int msg_count ; - int i ; - - /* sanity check the args */ - if(argc != 3) - { - fprintf(stderr, "usage %s <num clients> <1:server | 0:client>\n", argv[0]) ; - exit(1) ; - } - - num_clients = atoi(argv[1]) ; - role = atoi(argv[2]) ; - - if (num_clients <= 0 || (role != 0 && role != 1)) - { - fprintf(stderr, "usage %s <num clients> <1:server | 0:client>\n", argv[0]) ; - exit(1) ; - } - - /* initialize MPI */ - CHK(MPI_Init(&argc, &argv)) ; - - /* get the node name */ - /* The opal_gethostname() function is just a wrapper that returns a global - variable value that is set earlier, so we don't check for errors here */ - hostname = opal_gethostname(); - - /* server */ - if(role == 1) - { - printf("SERVER: on node '%s'\n", hostname) ; - - /* open port to establish connections */ - CHK(MPI_Open_port(MPI_INFO_NULL, server_port_name)) ; - - printf("SERVER: opened port=%s\n", server_port_name) ; - - /* store the port name */ - fp = fopen("server_port_name.txt", "w") ; - if(fp == NULL) - { - fprintf(stderr, "fopen failed: %s\n", strerror(errno)) ; - exit(1) ; + const char *hostname; + char buff[255]; + + int role; + int num_clients; + int size, rank; + int temp_errno; + + FILE *fp; + char server_port_name[MPI_MAX_PORT_NAME]; + + MPI_Comm intercomm, intracomm; + MPI_Status status; + int msg_count; + int i; + + /* sanity check the args */ + if (argc != 3) { + fprintf(stderr, "usage %s <num clients> <1:server | 0:client>\n", argv[0]); + exit(1); } - fprintf(fp, "%s", server_port_name) ; - fclose(fp) ; - /* the server accepts connections from all the clients */ - for(i = 0 ; i < num_clients ; i++ ) - { - /* accept connections at this port */ - CHK(MPI_Comm_accept(server_port_name, MPI_INFO_NULL, 0, - i == 0 ? MPI_COMM_WORLD : intracomm, - &intercomm)) ; + num_clients = atoi(argv[1]); + role = atoi(argv[2]); + + if (num_clients <= 0 || (role != 0 && role != 1)) { + fprintf(stderr, "usage %s <num clients> <1:server | 0:client>\n", argv[0]); + exit(1); + } - printf("SERVER: accepted connection from client %d\n", i+1) ; + /* initialize MPI */ + CHK(MPI_Init(&argc, &argv)); - /* merge, to form one intra communicator */ - CHK(MPI_Intercomm_merge(intercomm, 0, &intracomm)) ; + /* get the node name */ + /* The opal_gethostname() function is just a wrapper that returns a global + variable value that is set earlier, so we don't check for errors here */ + hostname = opal_gethostname(); - printf("SERVER: merged with client %d\n", i+1) ; + /* server */ + if (role == 1) { + printf("SERVER: on node '%s'\n", hostname); - CHK(MPI_Comm_size(intracomm, &size)) ; - CHK(MPI_Comm_rank(intracomm, &rank)) ; + /* open port to establish connections */ + CHK(MPI_Open_port(MPI_INFO_NULL, server_port_name)); - printf("SERVER: after merging with client %d: size=%d rank=%d\n", i+1, size, rank) ; - } - } /* end server */ - - /* client */ - if(role == 0) - { - printf("CLIENT: on node '%s'\n", hostname) ; - - fp = fopen("server_port_name.txt", "r") ; - if(fp == NULL) - { - fprintf(stderr, "fopen failed: %s\n", strerror(errno)) ; - exit(1) ; - } - fscanf(fp, "%s", server_port_name) ; - fclose(fp) ; + printf("SERVER: opened port=%s\n", server_port_name); - printf("CLIENT: attempting to connect to server on port=%s\n", server_port_name) ; + /* store the port name */ + fp = fopen("server_port_name.txt", "w"); + if (fp == NULL) { + fprintf(stderr, "fopen failed: %s\n", strerror(errno)); + exit(1); + } + fprintf(fp, "%s", server_port_name); + fclose(fp); - /* connect to the server */ - CHK(MPI_Comm_connect (server_port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm)) ; + /* the server accepts connections from all the clients */ + for (i = 0; i < num_clients; i++) { + /* accept connections at this port */ + CHK(MPI_Comm_accept(server_port_name, MPI_INFO_NULL, 0, + i == 0 ? MPI_COMM_WORLD : intracomm, &intercomm)); - printf("CLIENT: connected to server on port\n") ; + printf("SERVER: accepted connection from client %d\n", i + 1); - /* merge the server and client to one intra communicator */ - CHK(MPI_Intercomm_merge(intercomm, 1, &intracomm)) ; + /* merge, to form one intra communicator */ + CHK(MPI_Intercomm_merge(intercomm, 0, &intracomm)); - printf("CLIENT: merged with existing intracomm\n") ; + printf("SERVER: merged with client %d\n", i + 1); - CHK(MPI_Comm_size(intracomm, &size)) ; - CHK(MPI_Comm_rank(intracomm, &rank)) ; + CHK(MPI_Comm_size(intracomm, &size)); + CHK(MPI_Comm_rank(intracomm, &rank)); - printf("CLIENT: after merging, new comm: size=%d rank=%d\n", size, rank) ; + printf("SERVER: after merging with client %d: size=%d rank=%d\n", i + 1, size, rank); + } + } /* end server */ - for (i = rank ; i < num_clients ; i++) - { - /* client performs a collective accept */ - CHK(MPI_Comm_accept(server_port_name, MPI_INFO_NULL, 0, intracomm, &intercomm)) ; + /* client */ + if (role == 0) { + printf("CLIENT: on node '%s'\n", hostname); - printf("CLIENT: connected to server on port\n") ; + fp = fopen("server_port_name.txt", "r"); + if (fp == NULL) { + fprintf(stderr, "fopen failed: %s\n", strerror(errno)); + exit(1); + } + fscanf(fp, "%s", server_port_name); + fclose(fp); - /* merge the two intra comms back to one communicator */ - CHK(MPI_Intercomm_merge(intercomm, 0, &intracomm)) ; + printf("CLIENT: attempting to connect to server on port=%s\n", server_port_name); - printf("CLIENT: merged with existing members\n") ; + /* connect to the server */ + CHK(MPI_Comm_connect(server_port_name, MPI_INFO_NULL, 0, MPI_COMM_WORLD, &intercomm)); - CHK(MPI_Comm_size(intracomm, &size)) ; - CHK(MPI_Comm_rank(intracomm, &rank)) ; + printf("CLIENT: connected to server on port\n"); - printf("CLIENT: new size after merging with existing members: size=%d rank=%d\n", size, rank) ; - } + /* merge the server and client to one intra communicator */ + CHK(MPI_Intercomm_merge(intercomm, 1, &intracomm)); - } /* end client */ + printf("CLIENT: merged with existing intracomm\n"); - CHK(MPI_Comm_size(intracomm, &size)) ; - CHK(MPI_Comm_rank(intracomm, &rank)) ; + CHK(MPI_Comm_size(intracomm, &size)); + CHK(MPI_Comm_rank(intracomm, &rank)); - printf("After fusion: size=%d rank=%d\n", size, rank) ; + printf("CLIENT: after merging, new comm: size=%d rank=%d\n", size, rank); - if(rank == 0) - { - msg_count = num_clients ; + for (i = rank; i < num_clients; i++) { + /* client performs a collective accept */ + CHK(MPI_Comm_accept(server_port_name, MPI_INFO_NULL, 0, intracomm, &intercomm)); - while(msg_count) - { - CHK(MPI_Recv(buff, 255, MPI_CHAR, MPI_ANY_SOURCE, - MPI_ANY_TAG, intracomm, &status)) ; + printf("CLIENT: connected to server on port\n"); - printf("Received hello msg from '%s'\n", buff) ; - msg_count-- ; - } - } - else - { - /* all ranks > 0 */ + /* merge the two intra comms back to one communicator */ + CHK(MPI_Intercomm_merge(intercomm, 0, &intracomm)); - CHK(MPI_Send(hostname, strlen(hostname) + 1, MPI_CHAR, 0, TAG, intracomm)) ; - } + printf("CLIENT: merged with existing members\n"); + + CHK(MPI_Comm_size(intracomm, &size)); + CHK(MPI_Comm_rank(intracomm, &rank)); + + printf("CLIENT: new size after merging with existing members: size=%d rank=%d\n", size, + rank); + } + + } /* end client */ + + CHK(MPI_Comm_size(intracomm, &size)); + CHK(MPI_Comm_rank(intracomm, &rank)); + + printf("After fusion: size=%d rank=%d\n", size, rank); + + if (rank == 0) { + msg_count = num_clients; + + while (msg_count) { + CHK(MPI_Recv(buff, 255, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, intracomm, &status)); + + printf("Received hello msg from '%s'\n", buff); + msg_count--; + } + } else { + /* all ranks > 0 */ + + CHK(MPI_Send(hostname, strlen(hostname) + 1, MPI_CHAR, 0, TAG, intracomm)); + } - CHK(MPI_Finalize()) ; + CHK(MPI_Finalize()); - fprintf(stderr, "Rank %d is exiting\n", rank); - return 0 ; + fprintf(stderr, "Rank %d is exiting\n", rank); + return 0; } diff --git a/test/simple/sio.c b/test/simple/sio.c index bddd532029..e500bb8c20 100644 --- a/test/simple/sio.c +++ b/test/simple/sio.c @@ -5,16 +5,16 @@ * The most basic of MPI applications */ -#include <stdio.h> #include "mpi.h" +#include <stdio.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int i; MPI_Init(&argc, &argv); - for (i=0; i < 100; i++) { + for (i = 0; i < 100; i++) { printf("some output from mpitest to test the xml problem: %d\n", i); } diff --git a/test/simple/slave.c b/test/simple/slave.c index 54561c6d57..a00add41cf 100644 --- a/test/simple/slave.c +++ b/test/simple/slave.c @@ -5,17 +5,17 @@ * The most basic of MPI applications */ +#include "mpi.h" #include <stdio.h> #include <unistd.h> -#include "mpi.h" -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int rank, size; MPI_Comm parent; int msg; - printf("Slave [pid %ld] starting up!\n", (long)getpid()); + printf("Slave [pid %ld] starting up!\n", (long) getpid()); MPI_Init(&argc, &argv); diff --git a/test/simple/spawn-problem/ch_rec.c b/test/simple/spawn-problem/ch_rec.c index 982c1d91e7..0ffa446146 100644 --- a/test/simple/spawn-problem/ch_rec.c +++ b/test/simple/spawn-problem/ch_rec.c @@ -1,52 +1,50 @@ -#include <stdlib.h> +#include <mpi.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <mpi.h> -int main (int argc, char **argv){ - char buff[30]; - MPI_Status st; - MPI_Comm comm[2], parent; - MPI_Request req[2]; - int errcodes[1]; - int level; - int x = 6, i, j; +int main(int argc, char **argv) +{ + char buff[30]; + MPI_Status st; + MPI_Comm comm[2], parent; + MPI_Request req[2]; + int errcodes[1]; + int level; + int x = 6, i, j; - MPI_Init(&argc, &argv); - MPI_Comm_get_parent(&parent); - argv++; - level = atoi(argv[0]); - printf("level = %d\n",level); + MPI_Init(&argc, &argv); + MPI_Comm_get_parent(&parent); + argv++; + level = atoi(argv[0]); + printf("level = %d\n", level); - MPI_Recv(&buff, sizeof(char)*30, MPI_CHAR, MPI_ANY_SOURCE, - MPI_ANY_TAG, parent, &st); - printf("Parent sent: %s\n", buff); + MPI_Recv(&buff, sizeof(char) * 30, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, parent, &st); + printf("Parent sent: %s\n", buff); - if(level < x){ - sprintf(argv[0], "%d", level+1); - MPI_Comm_spawn("ch_rec", argv, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, - &comm[0], errcodes); - sprintf(buff,"level %d (pid:%d)", level, getpid()); - MPI_Send(&buff, sizeof(char)*30, MPI_CHAR, 0, 100, comm[0]); - MPI_Irecv(&buff, sizeof(char)*30, MPI_CHAR, MPI_ANY_SOURCE, - MPI_ANY_TAG, comm[0], &req[0]); + if (level < x) { + sprintf(argv[0], "%d", level + 1); + MPI_Comm_spawn("ch_rec", argv, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm[0], errcodes); + sprintf(buff, "level %d (pid:%d)", level, getpid()); + MPI_Send(&buff, sizeof(char) * 30, MPI_CHAR, 0, 100, comm[0]); + MPI_Irecv(&buff, sizeof(char) * 30, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, comm[0], + &req[0]); - //sleep(2); - sprintf(argv[0], "%d", (level+1)); - MPI_Comm_spawn("ch_rec", argv, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, - &comm[1], errcodes); - sprintf(buff,"level %d (pid:%d)", level, getpid()); - MPI_Send(&buff, sizeof(char)*30, MPI_CHAR, 0, 100, comm[1]); - MPI_Irecv(&buff, sizeof(char)*30, MPI_CHAR, MPI_ANY_SOURCE, - MPI_ANY_TAG, comm[1], &req[1]); + // sleep(2); + sprintf(argv[0], "%d", (level + 1)); + MPI_Comm_spawn("ch_rec", argv, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm[1], errcodes); + sprintf(buff, "level %d (pid:%d)", level, getpid()); + MPI_Send(&buff, sizeof(char) * 30, MPI_CHAR, 0, 100, comm[1]); + MPI_Irecv(&buff, sizeof(char) * 30, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, comm[1], + &req[1]); - for(i=0; i<2; i++){ - MPI_Waitany(2, req, &j, MPI_STATUS_IGNORE); - printf("Child %d sent: %s\n", j, buff); - } - } - sprintf(buff,"level %d (pid:%d)", level, getpid()); - MPI_Send(&buff, sizeof(char)*30, MPI_CHAR, 0, 100, parent); - MPI_Finalize(); - return 0; + for (i = 0; i < 2; i++) { + MPI_Waitany(2, req, &j, MPI_STATUS_IGNORE); + printf("Child %d sent: %s\n", j, buff); + } + } + sprintf(buff, "level %d (pid:%d)", level, getpid()); + MPI_Send(&buff, sizeof(char) * 30, MPI_CHAR, 0, 100, parent); + MPI_Finalize(); + return 0; } diff --git a/test/simple/spawn-problem/start.c b/test/simple/spawn-problem/start.c index 5a281ab5bb..897786d22a 100644 --- a/test/simple/spawn-problem/start.c +++ b/test/simple/spawn-problem/start.c @@ -1,28 +1,27 @@ -#include <stdlib.h> +#include <mpi.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <mpi.h> -int main (int argc, char **argv){ - char buff[30]; - MPI_Status st; - MPI_Comm comm; - int errcodes[1]; +int main(int argc, char **argv) +{ + char buff[30]; + MPI_Status st; + MPI_Comm comm; + int errcodes[1]; - MPI_Init(&argc, &argv); - int level = 0; - printf("level %d\n", level); + MPI_Init(&argc, &argv); + int level = 0; + printf("level %d\n", level); - sprintf(argv[0], "%d", level+1); - MPI_Comm_spawn("ch_rec", argv, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, - &comm, errcodes); - sprintf(buff,"level %d (pid:%d)", level, getpid()); - MPI_Send(&buff, sizeof(char)*30, MPI_CHAR, 0, 100, comm); + sprintf(argv[0], "%d", level + 1); + MPI_Comm_spawn("ch_rec", argv, 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &comm, errcodes); + sprintf(buff, "level %d (pid:%d)", level, getpid()); + MPI_Send(&buff, sizeof(char) * 30, MPI_CHAR, 0, 100, comm); - MPI_Recv(&buff, sizeof(char)*30, MPI_CHAR, MPI_ANY_SOURCE, - MPI_ANY_TAG, comm, &st); - printf("Child sent: %s\n", buff); + MPI_Recv(&buff, sizeof(char) * 30, MPI_CHAR, MPI_ANY_SOURCE, MPI_ANY_TAG, comm, &st); + printf("Child sent: %s\n", buff); - MPI_Finalize(); - return 0; + MPI_Finalize(); + return 0; } diff --git a/test/simple/spawn_multiple.c b/test/simple/spawn_multiple.c index 7607a59983..f586e9c19e 100644 --- a/test/simple/spawn_multiple.c +++ b/test/simple/spawn_multiple.c @@ -8,7 +8,7 @@ #include <mpi.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int msg; MPI_Comm parent, child; @@ -17,11 +17,11 @@ int main(int argc, char* argv[]) pid_t pid; int i; char *cmds[2]; - char *argv0[] = { "foo", NULL }; - char *argv1[] = { "bar", NULL }; + char *argv0[] = {"foo", NULL}; + char *argv1[] = {"bar", NULL}; char **spawn_argv[2]; - int maxprocs[] = { 1, 1 }; - MPI_Info info[] = { MPI_INFO_NULL, MPI_INFO_NULL }; + int maxprocs[] = {1, 1}; + MPI_Info info[] = {MPI_INFO_NULL, MPI_INFO_NULL}; cmds[1] = cmds[0] = argv[0]; spawn_argv[0] = argv0; @@ -34,10 +34,9 @@ int main(int argc, char* argv[]) /* If we get COMM_NULL back, then we're the parent */ if (MPI_COMM_NULL == parent) { pid = getpid(); - printf("Parent [pid %ld] about to spawn!\n", (long)pid); - MPI_Comm_spawn_multiple(2, cmds, spawn_argv, maxprocs, - info, 0, MPI_COMM_WORLD, - &child, MPI_ERRCODES_IGNORE); + printf("Parent [pid %ld] about to spawn!\n", (long) pid); + MPI_Comm_spawn_multiple(2, cmds, spawn_argv, maxprocs, info, 0, MPI_COMM_WORLD, &child, + MPI_ERRCODES_IGNORE); printf("Parent done with spawn\n"); if (0 == rank) { msg = 38; @@ -54,7 +53,8 @@ int main(int argc, char* argv[]) MPI_Comm_size(MPI_COMM_WORLD, &size); hostname = opal_gethostname(); pid = getpid(); - printf("Hello from the child %d of %d on host %s pid %ld: argv[1] = %s\n", rank, size, hostname, (long)pid, argv[1]); + printf("Hello from the child %d of %d on host %s pid %ld: argv[1] = %s\n", rank, size, + hostname, (long) pid, argv[1]); MPI_Recv(&msg, 1, MPI_INT, 0, 1, parent, MPI_STATUS_IGNORE); printf("Child %d received msg: %d\n", rank, msg); MPI_Comm_disconnect(&parent); diff --git a/test/simple/spawn_tree.c b/test/simple/spawn_tree.c index 123d7d3063..5dd512e175 100644 --- a/test/simple/spawn_tree.c +++ b/test/simple/spawn_tree.c @@ -2,14 +2,15 @@ #include "opal/runtime/opal.h" +#include <math.h> +#include <mpi.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <math.h> #include <unistd.h> -#include <mpi.h> -int main(int argc, char ** argv){ +int main(int argc, char **argv) +{ int i; int rank, size, child_rank; @@ -18,7 +19,6 @@ int main(int argc, char ** argv){ int erro; int level, curr_level; - if (argc < 2) { fprintf(stderr, "Usage: spawn_tree <#levels>\n"); exit(1); @@ -27,47 +27,41 @@ int main(int argc, char ** argv){ MPI_Init(&argc, &argv); - MPI_Comm_get_parent(&parent); - if(parent == MPI_COMM_NULL){ - rank=0; - } - else{ + if (parent == MPI_COMM_NULL) { + rank = 0; + } else { MPI_Recv(&rank, 1, MPI_INT, 0, 0, parent, MPI_STATUS_IGNORE); } - curr_level = (int) log2(rank+1); + curr_level = (int) log2(rank + 1); printf(" --> rank: %d and curr_level: %d\n", rank, curr_level); // Node propagation - if(curr_level < level){ + if (curr_level < level) { // 2^(curr_level+1) - 1 + 2*(rank - 2^curr_level - 1) = 2*rank + 1 - child_rank = 2*rank + 1; + child_rank = 2 * rank + 1; printf("(%d) Before create rank %d\n", rank, child_rank); - MPI_Comm_spawn(argv[0], &argv[1], 1, MPI_INFO_NULL, 0, - MPI_COMM_SELF, &intercomm1, &erro); + MPI_Comm_spawn(argv[0], &argv[1], 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm1, &erro); printf("(%d) After create rank %d\n", rank, child_rank); MPI_Send(&child_rank, 1, MPI_INT, 0, 0, intercomm1); - //sleep(1); + // sleep(1); child_rank = child_rank + 1; printf("(%d) Before create rank %d\n", rank, child_rank); - MPI_Comm_spawn(argv[0], &argv[1], 1, MPI_INFO_NULL, 0, - MPI_COMM_SELF, &intercomm2, &erro); + MPI_Comm_spawn(argv[0], &argv[1], 1, MPI_INFO_NULL, 0, MPI_COMM_SELF, &intercomm2, &erro); printf("(%d) After create rank %d\n", rank, child_rank); MPI_Send(&child_rank, 1, MPI_INT, 0, 0, intercomm2); - } nomehost = opal_gethostname(); printf("(%d) in %s\n", rank, nomehost); MPI_Finalize(); - return(0); - + return (0); } diff --git a/test/simple/thread_init.c b/test/simple/thread_init.c index 6021c4674e..d610f4d2b4 100644 --- a/test/simple/thread_init.c +++ b/test/simple/thread_init.c @@ -1,11 +1,11 @@ #include <mpi.h> #include <stdio.h> -int main(int argc, const char* argv[]) { - int provided = -1; - printf("Calling MPI_Init_thread...\n"); - MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, &provided); - printf("MPI_Init_thread returned, provided = %d\n", provided); - MPI_Finalize(); - return 0; +int main(int argc, const char *argv[]) +{ + int provided = -1; + printf("Calling MPI_Init_thread...\n"); + MPI_Init_thread(NULL, NULL, MPI_THREAD_MULTIPLE, &provided); + printf("MPI_Init_thread returned, provided = %d\n", provided); + MPI_Finalize(); + return 0; } - diff --git a/test/simple/xlib.c b/test/simple/xlib.c index e75a874fab..aa146794c8 100644 --- a/test/simple/xlib.c +++ b/test/simple/xlib.c @@ -1,10 +1,10 @@ -#include <stdlib.h> -#include <stdio.h> #include <mpi.h> #include <pmix.h> +#include <stdio.h> +#include <stdlib.h> -#define SIZE 20 -#define POS 10 +#define SIZE 20 +#define POS 10 #define INITIAL_VALUE 10 static pmix_proc_t myproc; @@ -13,13 +13,10 @@ static pmix_proc_t myproc; * when registering for general events - i.e.,, the default * handler. We don't technically need to register one, but it * is usually good practice to catch any events that occur */ -static void notification_fn(size_t evhdlr_registration_id, - pmix_status_t status, - const pmix_proc_t *source, - pmix_info_t info[], size_t ninfo, +static void notification_fn(size_t evhdlr_registration_id, pmix_status_t status, + const pmix_proc_t *source, pmix_info_t info[], size_t ninfo, pmix_info_t results[], size_t nresults, - pmix_event_notification_cbfunc_fn_t cbfunc, - void *cbdata) + pmix_event_notification_cbfunc_fn_t cbfunc, void *cbdata) { /* this example doesn't do anything with default events */ fprintf(stderr, "Default event handler called with status %s\n", PMIx_Error_string(status)); @@ -36,20 +33,18 @@ static void notification_fn(size_t evhdlr_registration_id, * to declare a use-specific notification callback point. In this case, * we are asking to know whenever a programming model library is * instantiated */ -static void model_callback(size_t evhdlr_registration_id, - pmix_status_t status, - const pmix_proc_t *source, - pmix_info_t info[], size_t ninfo, +static void model_callback(size_t evhdlr_registration_id, pmix_status_t status, + const pmix_proc_t *source, pmix_info_t info[], size_t ninfo, pmix_info_t results[], size_t nresults, - pmix_event_notification_cbfunc_fn_t cbfunc, - void *cbdata) + pmix_event_notification_cbfunc_fn_t cbfunc, void *cbdata) { size_t n; - fprintf(stderr, "Model event handler called with status %d(%s)\n", status, PMIx_Error_string(status)); + fprintf(stderr, "Model event handler called with status %d(%s)\n", status, + PMIx_Error_string(status)); /* check to see what model declared itself */ - for (n=0; n < ninfo; n++) { + for (n = 0; n < ninfo; n++) { if (PMIX_STRING == info[n].value.type) { fprintf(stderr, "\t%s:\t%s\n", info[n].key, info[n].value.data.string); } @@ -70,15 +65,13 @@ static void model_callback(size_t evhdlr_registration_id, * to the registered event. The index is used later on to deregister * an event handler - if we don't explicitly deregister it, then the * PMIx server will do so when it see us exit */ -static void model_registration_callback(pmix_status_t status, - size_t evhandler_ref, - void *cbdata) +static void model_registration_callback(pmix_status_t status, size_t evhandler_ref, void *cbdata) { - volatile int *active = (volatile int*)cbdata; + volatile int *active = (volatile int *) cbdata; if (PMIX_SUCCESS != status) { fprintf(stderr, "Client %s:%d EVENT HANDLER REGISTRATION FAILED WITH STATUS %d, ref=%lu\n", - myproc.nspace, myproc.rank, status, (unsigned long)evhandler_ref); + myproc.nspace, myproc.rank, status, (unsigned long) evhandler_ref); } *active = status; } @@ -96,7 +89,6 @@ int main(int argc, char *argv[]) pmix_status_t rc; volatile int active; - if (1 < argc) { fprintf(stderr, "Declaring ourselves\n"); /* declare ourselves as a non-MPI library prior to MPI_Init */ @@ -117,8 +109,8 @@ int main(int argc, char *argv[]) ninfo = 1; PMIX_INFO_CREATE(info, ninfo); PMIX_INFO_LOAD(&info[0], PMIX_EVENT_HDLR_NAME, "APP-MODEL", PMIX_STRING); - PMIx_Register_event_handler(&code, 1, info, ninfo, - model_callback, model_registration_callback, (void*)&active); + PMIx_Register_event_handler(&code, 1, info, ninfo, model_callback, + model_registration_callback, (void *) &active); while (-1 == active) { usleep(10); } @@ -140,8 +132,8 @@ int main(int argc, char *argv[]) PMIX_INFO_CREATE(info, ninfo); PMIX_INFO_LOAD(&info[0], PMIX_EVENT_HDLR_NAME, "APP-MODEL", PMIX_STRING); - PMIx_Register_event_handler(&code, 1, info, ninfo, - model_callback, model_registration_callback, (void*)&active); + PMIx_Register_event_handler(&code, 1, info, ninfo, model_callback, + model_registration_callback, (void *) &active); while (-1 == active) { usleep(10); } @@ -165,8 +157,7 @@ int main(int argc, char *argv[]) if (0 == rank) { send_array[pos] = INITIAL_VALUE; - MPI_Send(send_array, array_size, MPI_INT, next, tag, - MPI_COMM_WORLD); + MPI_Send(send_array, array_size, MPI_INT, next, tag, MPI_COMM_WORLD); } /* if we didn't already do it, declare another model now */ @@ -189,8 +180,7 @@ int main(int argc, char *argv[]) while (1) { recv_array[pos] = -1; - MPI_Recv(recv_array, array_size, MPI_INT, prev, tag, - MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(recv_array, array_size, MPI_INT, prev, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); send_array[pos] = recv_array[pos]; if (rank == 0) { --send_array[pos]; @@ -202,8 +192,7 @@ int main(int argc, char *argv[]) } if (rank == 0) { - MPI_Recv(recv_array, array_size, MPI_INT, prev, tag, - MPI_COMM_WORLD, MPI_STATUS_IGNORE); + MPI_Recv(recv_array, array_size, MPI_INT, prev, tag, MPI_COMM_WORLD, MPI_STATUS_IGNORE); } fprintf(stderr, "Rank %d has completed ring\n", rank); diff --git a/test/simple/ziaprobe.c b/test/simple/ziaprobe.c index c9bea29374..38da892294 100644 --- a/test/simple/ziaprobe.c +++ b/test/simple/ziaprobe.c @@ -10,17 +10,17 @@ * $HEADER$ * */ -#include <stdio.h> #include <stdbool.h> -#include <sys/types.h> -#include <unistd.h> +#include <stdio.h> #include <stdlib.h> -#include <time.h> #include <sys/time.h> +#include <sys/types.h> +#include <time.h> +#include <unistd.h> #include <mpi.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int msg; int rank, size, my_twin; @@ -54,8 +54,10 @@ int main(int argc, char* argv[]) /* this program requires that the size be an integer multiple of ppn */ if (0 != (size % ppn)) { if (0 == rank) { - fprintf(stderr, "The number of procs must be an integer multiple of the ppn\n" - "Given: num_procs %d ppn %d\n", size, ppn); + fprintf(stderr, + "The number of procs must be an integer multiple of the ppn\n" + "Given: num_procs %d ppn %d\n", + size, ppn); MPI_Abort(MPI_COMM_WORLD, 1); } else { goto cleanup; @@ -84,7 +86,7 @@ int main(int argc, char* argv[]) /* first, determine if my node is odd or even */ my_node = rank / ppn; - if (0 != (my_node % 2)) { + if (0 != (my_node % 2)) { /* compute my twin's rank - as I am an odd numbered node, my * twin will be on the node below me. Thus, its rank will be * my rank - ppn @@ -145,8 +147,7 @@ int main(int argc, char* argv[]) MPI_Abort(MPI_COMM_WORLD, 1); } } - MPI_Gather(&my_timestamp, 2, MPI_LONG, - timestamps, 2, MPI_LONG, 0, MPI_COMM_WORLD); + MPI_Gather(&my_timestamp, 2, MPI_LONG, timestamps, 2, MPI_LONG, 0, MPI_COMM_WORLD); if (0 == rank) { /* The "timestamps" array will now have everyone's timestamp (i.e., rank 0's timestamp will be in pos 0 & 1,, rank 1's timestamp @@ -155,17 +156,16 @@ int main(int argc, char* argv[]) maxsec = start_sec; maxusec = start_usec; maxrank = -1; - for (i=0; i < 2*size; i+=2) { + for (i = 0; i < 2 * size; i += 2) { if (timestamps[i] < maxsec) { continue; } - if (timestamps[i] == maxsec && - timestamps[i+1] < maxusec) { + if (timestamps[i] == maxsec && timestamps[i + 1] < maxusec) { continue; } maxsec = timestamps[i]; - maxusec = timestamps[i+1]; - maxrank = i/2; + maxusec = timestamps[i + 1]; + maxrank = i / 2; } free(timestamps); /* subtract starting time to get time in microsecs for test */ @@ -181,9 +181,9 @@ int main(int argc, char* argv[]) minutes = seconds / 60l; seconds = seconds % 60l; if (0 == minutes && 0 == seconds) { - fsecs = ((float)(maxsec)*1000000.0 + (float)maxusec) / 1000.0; - fprintf(stderr, "Time test was completed in %8.2f millisecs\nSlowest rank: %d\n", - fsecs, maxrank); + fsecs = ((float) (maxsec) *1000000.0 + (float) maxusec) / 1000.0; + fprintf(stderr, "Time test was completed in %8.2f millisecs\nSlowest rank: %d\n", fsecs, + maxrank); } else { fprintf(stderr, "Time test was completed in %3lu:%02lu min:sec\nSlowest rank: %d\n", minutes, seconds, maxrank); diff --git a/test/simple/ziatest.c b/test/simple/ziatest.c index 63c6cb722f..a0c94ef698 100644 --- a/test/simple/ziatest.c +++ b/test/simple/ziatest.c @@ -11,17 +11,17 @@ * $HEADER$ * */ -#include <stdio.h> #include <stdbool.h> -#include <sys/types.h> -#include <unistd.h> +#include <stdio.h> #include <stdlib.h> -#include <time.h> #include <sys/time.h> +#include <sys/types.h> +#include <time.h> +#include <unistd.h> #include <mpi.h> -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int nppn; struct timeval tv; @@ -41,8 +41,8 @@ int main(int argc, char* argv[]) gettimeofday(&tv, NULL); /* form the command */ - opal_asprintf(&cmd, "mpirun -npernode %d ./ziaprobe %ld %d", - nppn, (long) tv.tv_sec, tv.tv_usec); + opal_asprintf(&cmd, "mpirun -npernode %d ./ziaprobe %ld %d", nppn, (long) tv.tv_sec, + tv.tv_usec); /* execute it */ system(cmd); diff --git a/test/spc/spc_test.c b/test/spc/spc_test.c index 290b58eeda..e9fe839b0c 100644 --- a/test/spc/spc_test.c +++ b/test/spc/spc_test.c @@ -20,16 +20,16 @@ static void message_exchange(int num_messages, int message_size) { int i, rank; /* Use calloc to initialize data to 0's */ - char *data = (char*)calloc(message_size, sizeof(char)); + char *data = (char *) calloc(message_size, sizeof(char)); MPI_Status status; MPI_Comm_rank(MPI_COMM_WORLD, &rank); - if(rank == 0) { - for(i = 0; i < num_messages; i++) + if (rank == 0) { + for (i = 0; i < num_messages; i++) MPI_Send(data, message_size, MPI_BYTE, 1, 123, MPI_COMM_WORLD); - } else if(rank == 1) { - for(i = 0; i < num_messages; i++) + } else if (rank == 1) { + for (i = 0; i < num_messages; i++) MPI_Recv(data, message_size, MPI_BYTE, 0, 123, MPI_COMM_WORLD, &status); } @@ -38,25 +38,26 @@ static void message_exchange(int num_messages, int message_size) int main(int argc, char **argv) { - int i, rank, size, provided, num, name_len, desc_len, verbosity, bind, var_class, readonly, continuous, atomic, count, index, MPI_result; + int i, rank, size, provided, num, name_len, desc_len, verbosity, bind, var_class, readonly, + continuous, atomic, count, index, MPI_result; MPI_Datatype datatype; MPI_T_enum enumtype; char name[256], description[256]; /* Counter names to be read by ranks 0 and 1 */ - char *counter_names[] = { "runtime_spc_OMPI_SPC_BYTES_SENT_USER", - "runtime_spc_OMPI_SPC_BYTES_RECEIVED_USER" }; + char *counter_names[] = {"runtime_spc_OMPI_SPC_BYTES_SENT_USER", + "runtime_spc_OMPI_SPC_BYTES_RECEIVED_USER"}; MPI_Init(NULL, NULL); MPI_result = MPI_T_init_thread(MPI_THREAD_SINGLE, &provided); - if(MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_SUCCESS) { fprintf(stderr, "Failed to initialize MPI_T thread.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - if(size != 2) { + if (size != 2) { fprintf(stderr, "ERROR: This test should be run with two MPI processes.\n"); MPI_Abort(MPI_COMM_WORLD, -1); } @@ -64,26 +65,26 @@ int main(int argc, char **argv) /* Determine the MPI_T pvar indices for the OMPI_BYTES_SENT/RECIEVED_USER SPCs */ index = -1; MPI_result = MPI_T_pvar_get_num(&num); - if(MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_SUCCESS) { fprintf(stderr, "Failed to get the number of pvars.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } - for(i = 0; i < num; i++) { + for (i = 0; i < num; i++) { name_len = desc_len = 256; - MPI_result = MPI_T_pvar_get_info(i, name, &name_len, &verbosity, - &var_class, &datatype, &enumtype, description, &desc_len, &bind, - &readonly, &continuous, &atomic); + MPI_result = MPI_T_pvar_get_info(i, name, &name_len, &verbosity, &var_class, &datatype, + &enumtype, description, &desc_len, &bind, &readonly, + &continuous, &atomic); if (MPI_result == MPI_T_ERR_INVALID) { // skip invalidated MPI_T pvars continue; } - if(MPI_result != MPI_SUCCESS || MPI_result == MPI_T_ERR_PVAR_NO_STARTSTOP) { + if (MPI_result != MPI_SUCCESS || MPI_result == MPI_T_ERR_PVAR_NO_STARTSTOP) { fprintf(stderr, "Failed to get pvar info.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } - if(strcmp(name, counter_names[rank]) == 0) { + if (strcmp(name, counter_names[rank]) == 0) { index = i; printf("[%d] %s -> %s\n", rank, name, description); break; @@ -91,7 +92,7 @@ int main(int argc, char **argv) } /* Make sure we found the counters */ - if(index == -1) { + if (index == -1) { fprintf(stderr, "ERROR: Couldn't find the appropriate SPC counter in the MPI_T pvars.\n"); MPI_Abort(MPI_COMM_WORLD, -1); } @@ -102,45 +103,47 @@ int main(int argc, char **argv) MPI_T_pvar_handle handle; /* Create the MPI_T sessions/handles for the counters and start the counters */ MPI_result = MPI_T_pvar_session_create(&session); - if(MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_SUCCESS) { fprintf(stderr, "Failed to create MPI_T pvar session.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } MPI_result = MPI_T_pvar_handle_alloc(session, index, NULL, &handle, &count); - if(MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_SUCCESS) { fprintf(stderr, "Failed to allocate the pvar handle.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } MPI_result = MPI_T_pvar_start(session, handle); - if(MPI_result != MPI_SUCCESS) { - if(MPI_result != MPI_T_ERR_PVAR_NO_STARTSTOP) { + if (MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_T_ERR_PVAR_NO_STARTSTOP) { fprintf(stderr, "Failed to start the pvar session.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } } int message_size = 1, expected_bytes = 0; - while(message_size <= MAX_SIZE) { + while (message_size <= MAX_SIZE) { expected_bytes += message_size; message_exchange(1, message_size); message_size *= 10; } MPI_result = MPI_T_pvar_read(session, handle, &value); - if(MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_SUCCESS) { fprintf(stderr, "Failed to read the pvar.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } /* Print the counter values in order by rank */ - for(i = 0; i < 2; i++) { - if(i == rank) { + for (i = 0; i < 2; i++) { + if (i == rank) { printf("[%d] Value Read: %lld\n", rank, value); fflush(stdout); - if(value != expected_bytes){ - fprintf(stderr, "The counter value is inaccurate! It is '%lld'. It should be '%d'\n", value, expected_bytes); + if (value != expected_bytes) { + fprintf(stderr, + "The counter value is inaccurate! It is '%lld'. It should be '%d'\n", + value, expected_bytes); MPI_Abort(MPI_COMM_WORLD, MPI_ERR_OTHER); } } @@ -148,27 +151,27 @@ int main(int argc, char **argv) } /* Stop the MPI_T session, free the handle, and then free the session */ MPI_result = MPI_T_pvar_stop(session, handle); - if(MPI_result != MPI_SUCCESS) { - if(MPI_result != MPI_T_ERR_PVAR_NO_STARTSTOP) { + if (MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_T_ERR_PVAR_NO_STARTSTOP) { fprintf(stderr, "Failed to stop the pvar session.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } } MPI_result = MPI_T_pvar_handle_free(session, &handle); - if(MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_SUCCESS) { fprintf(stderr, "Failed to free the pvar handle.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } MPI_result = MPI_T_pvar_session_free(&session); - if(MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_SUCCESS) { fprintf(stderr, "Failed to free the pvar session.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } MPI_result = MPI_T_finalize(); - if(MPI_result != MPI_SUCCESS) { + if (MPI_result != MPI_SUCCESS) { fprintf(stderr, "Failed to finalize MPI_T.\n"); MPI_Abort(MPI_COMM_WORLD, MPI_result); } diff --git a/test/support/support.c b/test/support/support.c index e7411e06fd..0bf45e085a 100644 --- a/test/support/support.c +++ b/test/support/support.c @@ -18,10 +18,10 @@ */ #include "opal_config.h" -#include <stdlib.h> -#include <string.h> #include <assert.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> #include "support.h" @@ -52,17 +52,14 @@ void test_init(const char *a) opal_n_failures = 0; return; - } - void test_success(void) { opal_n_tests++; opal_n_success++; } - void test_failure(const char *a) { opal_n_tests++; @@ -74,7 +71,6 @@ void test_failure(const char *a) fflush(stderr); } - int test_verify_str(const char *expected_result, const char *test_result) { size_t len_expect, len_result; @@ -84,8 +80,7 @@ int test_verify_str(const char *expected_result, const char *test_result) len_expect = expected_result ? strlen(expected_result) : 0; len_result = test_result ? strlen(test_result) : 0; - if ((!(len_expect == len_result)) || - (0 != strcmp(expected_result, test_result))) { + if ((!(len_expect == len_result)) || (0 != strcmp(expected_result, test_result))) { test_failure("Comparison failure"); fprintf(stderr, " Expected result: %s\n", expected_result); fprintf(stderr, " Test result: %s\n", test_result); @@ -98,7 +93,6 @@ int test_verify_str(const char *expected_result, const char *test_result) return return_value; } - int test_verify_int(int expected_result, int test_result) { int return_value; @@ -117,7 +111,6 @@ int test_verify_int(int expected_result, int test_result) return return_value; } - int test_finalize(void) { int return_value; @@ -125,13 +118,12 @@ int test_finalize(void) return_value = 0; if (opal_n_tests == opal_n_success) { - fprintf(stderr, "SUPPORT: OMPI Test Passed: %s: (%d tests)\n", - opal_description, opal_n_tests); + fprintf(stderr, "SUPPORT: OMPI Test Passed: %s: (%d tests)\n", opal_description, + opal_n_tests); fflush(stderr); } else { - fprintf(stderr, - "SUPPORT: OMPI Test failed: %s (%d of %d failed)\n", - opal_description, opal_n_failures, opal_n_tests); + fprintf(stderr, "SUPPORT: OMPI Test failed: %s (%d of %d failed)\n", opal_description, + opal_n_failures, opal_n_tests); fflush(stderr); return_value = 1; } @@ -142,14 +134,12 @@ int test_finalize(void) return return_value; } - /* note this is for additional output that does NOT go to STDERR but STDOUT */ -void test_comment (const char* userstr) +void test_comment(const char *userstr) { - fprintf(stdout, "%s:%s\n", opal_description, userstr); + fprintf(stdout, "%s:%s\n", opal_description, userstr); } - void test_fail_stop(const char *msg, int status) { test_failure(msg); diff --git a/test/support/support.h b/test/support/support.h index c5995aa11d..7b4a9491bf 100644 --- a/test/support/support.h +++ b/test/support/support.h @@ -22,9 +22,11 @@ #include <stdio.h> #include <stdlib.h> -#define TEST_AND_REPORT(res, exp_res, str) \ - if( res == exp_res ) test_success(); \ - else test_failure(str); +#define TEST_AND_REPORT(res, exp_res, str) \ + if (res == exp_res) \ + test_success(); \ + else \ + test_failure(str); void test_init(const char *a); void test_success(void); @@ -32,26 +34,22 @@ void test_failure(const char *a); int test_verify_str(const char *expected_result, const char *test_result); int test_verify_int(int expected_result, int test_result); int test_finalize(void); -void test_comment (const char* userstr); +void test_comment(const char *userstr); void test_fail_stop(const char *msg, int status); - - /* * test_verify: Non-fatal assertion macro. */ -#define test_verify(MESSAGE, EXPR) \ - do { \ - if (!(EXPR)) { \ - char s[256]; \ - sprintf(s, "%s:%d: %s: %s\n", \ - __FILE__, __LINE__, MESSAGE, # EXPR); \ - test_failure(s); \ - } else { \ - test_success(); \ - } \ +#define test_verify(MESSAGE, EXPR) \ + do { \ + if (!(EXPR)) { \ + char s[256]; \ + sprintf(s, "%s:%d: %s: %s\n", __FILE__, __LINE__, MESSAGE, #EXPR); \ + test_failure(s); \ + } else { \ + test_success(); \ + } \ } while (0) #endif /* OMPI_SUPPORT_H */ - diff --git a/test/threads/opal_atomic_thread_bench.c b/test/threads/opal_atomic_thread_bench.c index 2989be55db..21bde63b86 100644 --- a/test/threads/opal_atomic_thread_bench.c +++ b/test/threads/opal_atomic_thread_bench.c @@ -10,227 +10,230 @@ #include <stdio.h> #include <time.h> -#include "support.h" -#include "opal/runtime/opal.h" #include "opal/constants.h" -#include "opal/mca/threads/threads.h" #include "opal/mca/threads/condition.h" +#include "opal/mca/threads/threads.h" +#include "opal/runtime/opal.h" #include "opal/sys/atomic.h" - +#include "support.h" #define OPAL_TEST_THREAD_COUNT 8 -#define ITERATIONS 1000000 -#define ITEM_COUNT 100 +#define ITERATIONS 1000000 +#define ITEM_COUNT 100 static opal_atomic_int64_t var_64 = 0; static opal_atomic_int32_t var_32 = 0; -static pthread_barrier_t barrier; +static pthread_barrier_t barrier; #if !defined(timersub) -#define timersub(a, b, r) \ - do { \ - (r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - if ((a)->tv_usec < (b)->tv_usec) { \ - (r)->tv_sec--; \ - (a)->tv_usec += 1000000; \ - } \ - (r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - } while (0) +# define timersub(a, b, r) \ + do { \ + (r)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + if ((a)->tv_usec < (b)->tv_usec) { \ + (r)->tv_sec--; \ + (a)->tv_usec += 1000000; \ + } \ + (r)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + } while (0) #endif - #if !defined(OPAL_TEST_DONE) -#define OPAL_TEST_DONE(func, val) { \ - gettimeofday (&stop, NULL); \ - timersub(&stop, &start, &total); \ - timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) / (double) ITERATIONS; \ - printf ("%s() thread finished. Time: %d s %d us %d nsec/per\n", func, (int) total.tv_sec, \ - (int)total.tv_usec, (int)(timing / 1e-9)); \ - memset(&stop, 0, sizeof(struct timeval)); \ - memset(&start, 0, sizeof(struct timeval)); \ - memset(&total, 0, sizeof(struct timeval)); \ - /* printf("%ld\n", val); */ \ - fflush(stdout); \ - pthread_barrier_wait (&barrier); \ -} +# define OPAL_TEST_DONE(func, val) \ + { \ + gettimeofday(&stop, NULL); \ + timersub(&stop, &start, &total); \ + timing = ((double) total.tv_sec + (double) total.tv_usec * 1e-6) \ + / (double) ITERATIONS; \ + printf("%s() thread finished. Time: %d s %d us %d nsec/per\n", func, \ + (int) total.tv_sec, (int) total.tv_usec, (int) (timing / 1e-9)); \ + memset(&stop, 0, sizeof(struct timeval)); \ + memset(&start, 0, sizeof(struct timeval)); \ + memset(&total, 0, sizeof(struct timeval)); \ + /* printf("%ld\n", val); */ \ + fflush(stdout); \ + pthread_barrier_wait(&barrier); \ + } #endif #if !defined(OPAL_RESET_VAR) -#define OPAL_RESET_VAR(var) { \ - var = 0; \ - pthread_barrier_wait (&barrier); \ -} +# define OPAL_RESET_VAR(var) \ + { \ + var = 0; \ + pthread_barrier_wait(&barrier); \ + } #endif -static void *thread_test (void *arg) { +static void *thread_test(void *arg) +{ struct timeval start, stop, total; double timing; - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_compare_exchange_strong_64(&var_64, &i, i+1); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_compare_exchange_strong_64(&var_64, &i, i + 1); } OPAL_TEST_DONE("opal_atomic_compare_exchange_strong_64", var_64); OPAL_RESET_VAR(var_64); - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_compare_exchange_strong_rel_64(&var_64, &i, i+1); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_compare_exchange_strong_rel_64(&var_64, &i, i + 1); } OPAL_TEST_DONE("opal_atomic_compare_exchange_strong_rel_64", var_64); OPAL_RESET_VAR(var_64); - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_compare_exchange_strong_acq_64(&var_64, &i, i+1); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_compare_exchange_strong_acq_64(&var_64, &i, i + 1); } OPAL_TEST_DONE("opal_atomic_compare_exchange_strong_acq_64", var_64); OPAL_RESET_VAR(var_64); - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_fetch_add_64(&var_64, 1); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_fetch_add_64(&var_64, 1); } OPAL_TEST_DONE("opal_atomic_fetch_add_64", var_64); OPAL_RESET_VAR(var_64); - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_fetch_sub_64(&var_64, 1); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_fetch_sub_64(&var_64, 1); } OPAL_TEST_DONE("opal_atomic_fetch_sub_64", var_64); OPAL_RESET_VAR(var_64); - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_fetch_xor_64(&var_64, i); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_fetch_xor_64(&var_64, i); } OPAL_TEST_DONE("opal_atomic_fetch_xor_64", var_64); OPAL_RESET_VAR(var_64); - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_swap_64(&var_64, i); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_swap_64(&var_64, i); } OPAL_TEST_DONE("opal_atomic_swap_64", var_64); OPAL_RESET_VAR(var_64); #if OPAL_HAVE_ATOMIC_LLSC_64 - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - int ret; - opal_atomic_sc_64(&var_64, i, ret); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + int ret; + opal_atomic_sc_64(&var_64, i, ret); } OPAL_TEST_DONE("opal_atomic_sc_64", var_64); OPAL_RESET_VAR(var_64); - gettimeofday (&start, NULL); - for (int64_t i = 0 ; i < ITERATIONS ; ++i) { - int ret; - opal_atomic_sc_64(&var_64, i, ret); + gettimeofday(&start, NULL); + for (int64_t i = 0; i < ITERATIONS; ++i) { + int ret; + opal_atomic_sc_64(&var_64, i, ret); } OPAL_TEST_DONE("opal_atomic_ll_64", var_64); OPAL_RESET_VAR(var_64); #endif - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_compare_exchange_strong_32(&var_32, &i, i+1); + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_compare_exchange_strong_32(&var_32, &i, i + 1); } OPAL_TEST_DONE("opal_atomic_compare_exchange_strong_32", var_32); OPAL_RESET_VAR(var_32); - - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_compare_exchange_strong_rel_32(&var_32, &i, i+1); + + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_compare_exchange_strong_rel_32(&var_32, &i, i + 1); } OPAL_TEST_DONE("opal_atomic_compare_exchange_strong_rel_32", var_32); OPAL_RESET_VAR(var_32); - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_compare_exchange_strong_acq_32(&var_32, &i, i+1); + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_compare_exchange_strong_acq_32(&var_32, &i, i + 1); } OPAL_TEST_DONE("opal_atomic_compare_exchange_strong_acq_32", var_32); OPAL_RESET_VAR(var_32); - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_fetch_add_32(&var_32, 1); + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_fetch_add_32(&var_32, 1); } OPAL_TEST_DONE("opal_atomic_fetch_add_32", var_32); OPAL_RESET_VAR(var_32); - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_fetch_sub_32(&var_32, 1); + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_fetch_sub_32(&var_32, 1); } OPAL_TEST_DONE("opal_atomic_fetch_sub_32", var_32); OPAL_RESET_VAR(var_32); - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_fetch_xor_32(&var_32, i); + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_fetch_xor_32(&var_32, i); } OPAL_TEST_DONE("opal_atomic_fetch_xor_32", var_32); OPAL_RESET_VAR(var_32); - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - opal_atomic_swap_32(&var_32, i); + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + opal_atomic_swap_32(&var_32, i); } OPAL_TEST_DONE("opal_atomic_swap_32", var_32); OPAL_RESET_VAR(var_32); #if OPAL_HAVE_ATOMIC_LLSC_32 - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - int ret; - opal_atomic_sc_32(&var_32, i, ret); + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + int ret; + opal_atomic_sc_32(&var_32, i, ret); } OPAL_TEST_DONE("opal_atomic_sc_32", var_32); OPAL_RESET_VAR(var_32); - gettimeofday (&start, NULL); - for (int32_t i = 0 ; i < ITERATIONS ; ++i) { - int ret; - opal_atomic_sc_32(&var_32, i, ret); + gettimeofday(&start, NULL); + for (int32_t i = 0; i < ITERATIONS; ++i) { + int ret; + opal_atomic_sc_32(&var_32, i, ret); } OPAL_TEST_DONE("opal_atomic_ll_32", var_32); OPAL_RESET_VAR(var_32); #endif - + return NULL; } -int main(void) { - - pthread_barrier_init (&barrier, NULL, OPAL_TEST_THREAD_COUNT); +int main(void) +{ + + pthread_barrier_init(&barrier, NULL, OPAL_TEST_THREAD_COUNT); pthread_t ts[OPAL_TEST_THREAD_COUNT]; - for(int i = 0; i < OPAL_TEST_THREAD_COUNT; i++) { - pthread_create(&ts[i], NULL, &thread_test, NULL); + for (int i = 0; i < OPAL_TEST_THREAD_COUNT; i++) { + pthread_create(&ts[i], NULL, &thread_test, NULL); } - for(int i = 0; i < OPAL_TEST_THREAD_COUNT; i++) { + for (int i = 0; i < OPAL_TEST_THREAD_COUNT; i++) { pthread_join(ts[i], NULL); } return 0; diff --git a/test/threads/opal_condition.c b/test/threads/opal_condition.c index cacb3acc5f..fb5e2a2a41 100644 --- a/test/threads/opal_condition.c +++ b/test/threads/opal_condition.c @@ -22,12 +22,12 @@ #include <stdio.h> #include <time.h> -#include "support.h" -#include "opal/runtime/opal.h" #include "opal/constants.h" -#include "opal/mca/threads/threads.h" #include "opal/mca/threads/condition.h" +#include "opal/mca/threads/threads.h" +#include "opal/runtime/opal.h" #include "opal/sys/atomic.h" +#include "support.h" static opal_mutex_t mutex; static opal_condition_t thr1_cond; @@ -36,50 +36,47 @@ static opal_condition_t thr2_cond; static volatile int thr1_count = 0; static volatile int thr2_count = 0; - #define TEST_COUNT 100000 - -static void* thr1_run(opal_object_t* obj) +static void *thr1_run(opal_object_t *obj) { int i; clock_t c1, c2; opal_mutex_lock(&mutex); c1 = clock(); - for(i=0; i<TEST_COUNT; i++) { + for (i = 0; i < TEST_COUNT; i++) { opal_condition_wait(&thr1_cond, &mutex); opal_condition_signal(&thr2_cond); thr1_count++; } c2 = clock(); opal_mutex_unlock(&mutex); - fprintf(stderr, "thr1: time per iteration: %ld usec\n", (long)((c2 - c1) / TEST_COUNT)); + fprintf(stderr, "thr1: time per iteration: %ld usec\n", (long) ((c2 - c1) / TEST_COUNT)); return NULL; } -static void* thr2_run(opal_object_t* obj) +static void *thr2_run(opal_object_t *obj) { int i; clock_t c1, c2; opal_mutex_lock(&mutex); c1 = clock(); - for(i=0; i<TEST_COUNT; i++) { + for (i = 0; i < TEST_COUNT; i++) { opal_condition_signal(&thr1_cond); opal_condition_wait(&thr2_cond, &mutex); thr2_count++; } c2 = clock(); opal_mutex_unlock(&mutex); - fprintf(stderr, "thr2: time per iteration: %ld usec\n", (long)((c2 - c1) / TEST_COUNT)); + fprintf(stderr, "thr2: time per iteration: %ld usec\n", (long) ((c2 - c1) / TEST_COUNT)); return NULL; } - -int main(int argc, char** argv) +int main(int argc, char **argv) { int rc; - opal_thread_t* thr1; - opal_thread_t* thr2; + opal_thread_t *thr1; + opal_thread_t *thr2; test_init("opal_condition_t"); diff --git a/test/threads/opal_thread.c b/test/threads/opal_thread.c index f7f66130d8..c58d8e7876 100644 --- a/test/threads/opal_thread.c +++ b/test/threads/opal_thread.c @@ -13,30 +13,28 @@ #include <stdio.h> -#include "support.h" #include "opal/constants.h" #include "opal/mca/threads/threads.h" #include "opal/sys/atomic.h" - +#include "support.h" /* Only have the body of this test if we have thread support */ static opal_atomic_int_t count = 0; - -static void* thr1_run(opal_object_t* obj) +static void *thr1_run(opal_object_t *obj) { - opal_atomic_add (&count, 1); + opal_atomic_add(&count, 1); return NULL; } -static void* thr2_run(opal_object_t* obj) +static void *thr2_run(opal_object_t *obj) { - opal_atomic_add (&count, 2); + opal_atomic_add(&count, 2); return NULL; } -int main(int argc, char** argv) +int main(int argc, char **argv) { int rc; opal_thread_t thr1; diff --git a/test/util/bipartite_graph.c b/test/util/bipartite_graph.c index e5dd8710ea..adf1174be6 100644 --- a/test/util/bipartite_graph.c +++ b/test/util/bipartite_graph.c @@ -12,62 +12,59 @@ #include <stdlib.h> #include <sys/time.h> -#include "opal/constants.h" #include "opal/class/opal_list.h" #include "opal/class/opal_pointer_array.h" +#include "opal/constants.h" #include "opal/util/bipartite_graph.h" #include "opal/util/bipartite_graph_internal.h" -# define test_out(...) fprintf(stderr, __VA_ARGS__) -# define check(a) \ +#define test_out(...) fprintf(stderr, __VA_ARGS__) +#define check(a) \ do { \ if (!(a)) { \ test_out("%s:%d: check failed, '%s'\n", __func__, __LINE__, #a); \ - return 1; \ + return 1; \ } \ } while (0) -# define check_str_eq(a,b) \ - do { \ - const char *a_ = (a); \ - const char *b_ = (b); \ - if (0 != strcmp(a_,b_)) { \ - test_out("%s:%d: check failed, \"%s\" != \"%s\"\n", \ - __func__, __LINE__, a_, b_); \ - return 1; \ - } \ +#define check_str_eq(a, b) \ + do { \ + const char *a_ = (a); \ + const char *b_ = (b); \ + if (0 != strcmp(a_, b_)) { \ + test_out("%s:%d: check failed, \"%s\" != \"%s\"\n", __func__, __LINE__, a_, b_); \ + return 1; \ + } \ } while (0) -# define check_int_eq(got, expected) \ - do { \ - if ((got) != (expected)) { \ - test_out("%s:%d: check failed, \"%s\" != \"%s\", got %d\n", \ - __func__, __LINE__, #got, #expected, (got)); \ - return 1; \ - } \ +#define check_int_eq(got, expected) \ + do { \ + if ((got) != (expected)) { \ + test_out("%s:%d: check failed, \"%s\" != \"%s\", got %d\n", __func__, __LINE__, #got, \ + #expected, (got)); \ + return 1; \ + } \ } while (0) /* just use check_int_eq for now, no public error code to string routine * exists (opal_err2str is static) */ -# define check_err_code(got, expected) \ - check_int_eq(got, expected) -# define check_msg(a, msg) \ - do { \ - if (!(a)) { \ - test_out("%s:%d: check failed, \"%s\" (%s)\n", \ - __func__, __LINE__, #a, (msg)); \ - return 1; \ - } \ +#define check_err_code(got, expected) check_int_eq(got, expected) +#define check_msg(a, msg) \ + do { \ + if (!(a)) { \ + test_out("%s:%d: check failed, \"%s\" (%s)\n", __func__, __LINE__, #a, (msg)); \ + return 1; \ + } \ } while (0) -#define check_graph_is_consistent(g) \ - do { \ +#define check_graph_is_consistent(g) \ + do { \ check(opal_bp_graph_order(g) <= opal_pointer_array_get_size(&g->vertices)); \ check(g->source_idx >= -1 || g->source_idx < opal_bp_graph_order(g)); \ check(g->sink_idx >= -1 || g->sink_idx < opal_bp_graph_order(g)); \ } while (0) -#define check_has_in_out_degree(g, u, expected_indegree, expected_outdegree) \ - do { \ - check_int_eq(opal_bp_graph_indegree(g, (u)), expected_indegree); \ - check_int_eq(opal_bp_graph_outdegree(g, (u)), expected_outdegree); \ +#define check_has_in_out_degree(g, u, expected_indegree, expected_outdegree) \ + do { \ + check_int_eq(opal_bp_graph_indegree(g, (u)), expected_indegree); \ + check_int_eq(opal_bp_graph_outdegree(g, (u)), expected_outdegree); \ } while (0) /* Check the given path for sanity and that it does not have a cycle. Uses @@ -81,7 +78,7 @@ check(pred[i_] < n); \ } \ i_ = (sink); \ - j_ = pred[(sink)]; \ + j_ = pred[(sink)]; \ while (i_ != -1 && j_ != -1) { \ check_msg(i_ != j_, "CYCLE DETECTED"); \ i_ = pred[i_]; \ @@ -109,23 +106,19 @@ static void e_cleanup(void *e_data) * list returned by opal_bp_graph_solve_bipartite_assignment */ static int cmp_int_pair(const void *a, const void *b) { - int *ia = (int *)a; - int *ib = (int *)b; + int *ia = (int *) a; + int *ib = (int *) b; if (ia[0] < ib[0]) { return -1; - } - else if (ia[0] > ib[0]) { + } else if (ia[0] > ib[0]) { return 1; - } - else { /* ia[0] == ib[0] */ + } else { /* ia[0] == ib[0] */ if (ia[1] < ib[1]) { return -1; - } - else if (ia[1] > ib[1]) { + } else if (ia[1] > ib[1]) { return 1; - } - else { + } else { return 0; } } @@ -139,7 +132,7 @@ static double gettime(void) struct timeval tv; gettimeofday(&tv, NULL); wtime = tv.tv_sec; - wtime += (double)tv.tv_usec / 1000000.0; + wtime += (double) tv.tv_usec / 1000000.0; return wtime; } @@ -195,7 +188,7 @@ static int test_graph_create(void *ctx) check(opal_bp_graph_order(g) == 5); check_graph_is_consistent(g); err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/1, - /*capacity=*/2, &user_data); + /*capacity=*/2, &user_data); check_graph_is_consistent(g); check(v_cleanup_count == 0); check(e_cleanup_count == 0); @@ -234,11 +227,11 @@ static int test_graph_clone(void *ctx) /* and two edges */ err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/1, - /*capacity=*/2, &user_data); + /*capacity=*/2, &user_data); check_err_code(err, OPAL_SUCCESS); check_graph_is_consistent(g); err = opal_bp_graph_add_edge(g, /*u=*/3, /*v=*/1, /*cost=*/2, - /*capacity=*/100, &user_data); + /*capacity=*/100, &user_data); check_err_code(err, OPAL_SUCCESS); check_graph_is_consistent(g); @@ -283,17 +276,17 @@ static int test_graph_accessors(void *ctx) check(opal_bp_graph_order(g) == 4); err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/1, /*cost=*/2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); - check(opal_bp_graph_indegree(g, 0) == 0); + check(opal_bp_graph_indegree(g, 0) == 0); check(opal_bp_graph_outdegree(g, 0) == 2); - check(opal_bp_graph_indegree(g, 1) == 1); + check(opal_bp_graph_indegree(g, 1) == 1); check(opal_bp_graph_outdegree(g, 1) == 0); - check(opal_bp_graph_indegree(g, 2) == 1); + check(opal_bp_graph_indegree(g, 2) == 1); check(opal_bp_graph_outdegree(g, 2) == 0); - check(opal_bp_graph_indegree(g, 3) == 0); + check(opal_bp_graph_indegree(g, 3) == 0); check(opal_bp_graph_outdegree(g, 3) == 0); err = opal_bp_graph_free(g); @@ -327,25 +320,22 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/3, /*cost=*/2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 2); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); check(me[0] == 0 && me[1] == 2); check(me[2] == 1 && me[3] == 3); err = opal_bp_graph_free(g); check_err_code(err, OPAL_SUCCESS); - /* TEST CASE: left side has more vertices than the right side * * 0 --> 3 @@ -362,23 +352,21 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/4, /*cost=*/2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 2); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); check(me[0] == 0 && me[1] == 3); check(me[2] == 2 && me[3] == 4); free(me); @@ -386,7 +374,6 @@ static int test_graph_assignment_solver(void *ctx) err = opal_bp_graph_free(g); check_err_code(err, OPAL_SUCCESS); - /* test Christian's case: * 0 --> 2 * 0 --> 3 @@ -404,23 +391,21 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/3, /*cost=*/5, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 2); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); check(me[0] == 0 && me[1] == 2); check(me[2] == 1 && me[3] == 3); free(me); @@ -445,23 +430,21 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/2, /*cost=*/1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/3, /*cost=*/5, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 2); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); check(me[0] == 0 && me[1] == 2); check(me[2] == 1 && me[3] == 3); free(me); @@ -486,23 +469,21 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/-1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/-10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/3, /*cost=*/-5, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 2); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); check(me[0] == 0 && me[1] == 2); check(me[2] == 1 && me[3] == 3); free(me); @@ -510,7 +491,6 @@ static int test_graph_assignment_solver(void *ctx) err = opal_bp_graph_free(g); check_err_code(err, OPAL_SUCCESS); - /* TEST CASE: add some disconnected vertices * 0 --> 2 * 0 --> 3 @@ -529,23 +509,21 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/-1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/-10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/3, /*cost=*/-5, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 2); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); check(me[0] == 0 && me[1] == 2); check(me[2] == 1 && me[3] == 3); free(me); @@ -571,26 +549,24 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/-4294967296, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/2, /*cost=*/-4294967296, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/-4294967296, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/3, /*cost=*/-4294967296, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 2); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); if (me[1] == 2) { check(me[0] == 0 && me[1] == 2); check(me[2] == 1 && me[3] == 3); @@ -603,7 +579,6 @@ static int test_graph_assignment_solver(void *ctx) err = opal_bp_graph_free(g); check_err_code(err, OPAL_SUCCESS); - /* TEST CASE: check that simple cases are solved correctly * * 0 --> 2 @@ -619,24 +594,21 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/-100, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/2, /*cost=*/-100, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 1); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); check((me[0] == 0 || me[0] == 1) && me[1] == 2); err = opal_bp_graph_free(g); check_err_code(err, OPAL_SUCCESS); - /* TEST CASE: performance sanity check * * Construct this graph and ensure that it doesn't take too long on a large @@ -658,23 +630,21 @@ static int test_graph_assignment_solver(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/4, /*cost=*/2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); me = NULL; - err = opal_bp_graph_solve_bipartite_assignment(g, - &nme, - &me); + err = opal_bp_graph_solve_bipartite_assignment(g, &nme, &me); check_err_code(err, OPAL_SUCCESS); check_int_eq(nme, 2); check(me != NULL); - qsort(me, nme, 2*sizeof(int), &cmp_int_pair); + qsort(me, nme, 2 * sizeof(int), &cmp_int_pair); check(me[0] == 0 && me[1] == 3); check(me[2] == 2 && me[3] == 4); free(me); @@ -720,25 +690,25 @@ static int test_graph_bellman_ford(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/2, /*cost=*/10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/3, /*cost=*/2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/4, /*v=*/0, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/4, /*v=*/1, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/5, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/3, /*v=*/5, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); - pred = malloc(6*sizeof(*pred)); + pred = malloc(6 * sizeof(*pred)); check(pred != NULL); path_found = opal_bp_graph_bellman_ford(g, /*source=*/4, /*target=*/5, pred); check(path_found); @@ -751,7 +721,6 @@ static int test_graph_bellman_ford(void *ctx) err = opal_bp_graph_free(g); check_err_code(err, OPAL_SUCCESS); - /* TEST CASE: left side has more vertices than the right side, then * convert to a flow network * @@ -769,19 +738,19 @@ static int test_graph_bellman_ford(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/4, /*cost=*/2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_bipartite_to_flow(g); check_err_code(err, OPAL_SUCCESS); - pred = malloc(7*sizeof(*pred)); + pred = malloc(7 * sizeof(*pred)); check(pred != NULL); path_found = opal_bp_graph_bellman_ford(g, /*source=*/5, /*target=*/6, pred); check(path_found); @@ -812,20 +781,20 @@ static int test_graph_bellman_ford(void *ctx) check_err_code(err, OPAL_SUCCESS); } - err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/INT32_MAX+10LL, - /*capacity=*/1, NULL); + err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/INT32_MAX + 10LL, + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); - err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/4, /*cost=*/INT32_MAX+2LL, - /*capacity=*/1, NULL); + err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/4, /*cost=*/INT32_MAX + 2LL, + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); - err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/INT32_MAX+1LL, - /*capacity=*/1, NULL); + err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/INT32_MAX + 1LL, + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_bipartite_to_flow(g); check_err_code(err, OPAL_SUCCESS); - pred = malloc(7*sizeof(*pred)); + pred = malloc(7 * sizeof(*pred)); check(pred != NULL); path_found = opal_bp_graph_bellman_ford(g, /*source=*/5, /*target=*/6, pred); check(path_found); @@ -858,19 +827,19 @@ static int test_graph_bellman_ford(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/-1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/4, /*cost=*/-2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/-10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_bipartite_to_flow(g); check_err_code(err, OPAL_SUCCESS); - pred = malloc(7*sizeof(*pred)); + pred = malloc(7 * sizeof(*pred)); check(pred != NULL); path_found = opal_bp_graph_bellman_ford(g, /*source=*/5, /*target=*/6, pred); check(path_found); @@ -911,13 +880,13 @@ static int test_graph_flow_conversion(void *ctx) } err = opal_bp_graph_add_edge(g, /*u=*/0, /*v=*/3, /*cost=*/10, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/1, /*v=*/4, /*cost=*/2, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/1, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); check_int_eq(opal_bp_graph_order(g), 5); @@ -943,7 +912,6 @@ static int test_graph_flow_conversion(void *ctx) err = opal_bp_graph_free(g); check_err_code(err, OPAL_SUCCESS); - /* TEST CASE: empty graph * * there's no reason that the code should bother to support this, it's not @@ -973,7 +941,7 @@ static int test_graph_param_checking(void *ctx) /* try with no vertices */ err = opal_bp_graph_add_edge(g, /*u=*/3, /*v=*/5, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_ERR_BAD_PARAM); for (i = 0; i < 6; ++i) { @@ -983,34 +951,34 @@ static int test_graph_param_checking(void *ctx) /* try u out of range */ err = opal_bp_graph_add_edge(g, /*u=*/9, /*v=*/5, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_ERR_BAD_PARAM); err = opal_bp_graph_add_edge(g, /*u=*/6, /*v=*/5, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_ERR_BAD_PARAM); /* try v out of range */ err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/8, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_ERR_BAD_PARAM); err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/6, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_ERR_BAD_PARAM); /* try adding an edge that already exists */ err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/4, /*cost=*/0, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_EXISTS); /* try an edge with an out of range cost */ err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/3, /*cost=*/INT64_MAX, - /*capacity=*/1, NULL); + /*capacity=*/1, NULL); check_err_code(err, OPAL_ERR_BAD_PARAM); - err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/3, /*cost=*/INT64_MAX-1, - /*capacity=*/1, NULL); + err = opal_bp_graph_add_edge(g, /*u=*/2, /*v=*/3, /*cost=*/INT64_MAX - 1, + /*capacity=*/1, NULL); check_err_code(err, OPAL_SUCCESS); err = opal_bp_graph_free(g); @@ -1040,7 +1008,8 @@ static int test_graph_helper_macros(void *ctx) /* TEST CASE: make sure that an empty path does not cause any edges to be * visited */ RESET_ARRAYS(6, pred, visited); - FOREACH_UV_ON_PATH(pred, 3, 5, u, v) { + FOREACH_UV_ON_PATH(pred, 3, 5, u, v) + { visited[u][v] = true; } for (u = 0; u < 6; ++u) { @@ -1054,17 +1023,15 @@ static int test_graph_helper_macros(void *ctx) pred[5] = 2; pred[2] = 1; pred[1] = 3; - FOREACH_UV_ON_PATH(pred, 3, 5, u, v) { + FOREACH_UV_ON_PATH(pred, 3, 5, u, v) + { visited[u][v] = true; } for (u = 0; u < 6; ++u) { for (v = 0; v < 6; ++v) { - if ((u == 2 && v == 5) || - (u == 1 && v == 2) || - (u == 3 && v == 1)) { + if ((u == 2 && v == 5) || (u == 1 && v == 2) || (u == 3 && v == 1)) { check(visited[u][v] == true); - } - else { + } else { check(visited[u][v] == false); } } @@ -1074,24 +1041,34 @@ static int test_graph_helper_macros(void *ctx) /* not technically a macro, but make sure that the pair comparison function * isn't broken (because it was in an earlier revision...) */ - pair1[0] = 0; pair1[1] = 1; - pair2[0] = 0; pair2[1] = 1; + pair1[0] = 0; + pair1[1] = 1; + pair2[0] = 0; + pair2[1] = 1; check(cmp_int_pair(&pair1[0], &pair2[0]) == 0); - pair1[0] = 1; pair1[1] = 1; - pair2[0] = 0; pair2[1] = 1; + pair1[0] = 1; + pair1[1] = 1; + pair2[0] = 0; + pair2[1] = 1; check(cmp_int_pair(pair1, pair2) > 0); - pair1[0] = 0; pair1[1] = 1; - pair2[0] = 1; pair2[1] = 1; + pair1[0] = 0; + pair1[1] = 1; + pair2[0] = 1; + pair2[1] = 1; check(cmp_int_pair(pair1, pair2) < 0); - pair1[0] = 1; pair1[1] = 0; - pair2[0] = 1; pair2[1] = 1; + pair1[0] = 1; + pair1[1] = 0; + pair2[0] = 1; + pair2[1] = 1; check(cmp_int_pair(pair1, pair2) < 0); - pair1[0] = 1; pair1[1] = 1; - pair2[0] = 1; pair2[1] = 0; + pair1[0] = 1; + pair1[1] = 1; + pair2[0] = 1; + pair2[1] = 0; check(cmp_int_pair(pair1, pair2) > 0); return 0; diff --git a/test/util/ompi_numtostr.c b/test/util/ompi_numtostr.c index 9a45b6a470..16861cb91f 100644 --- a/test/util/ompi_numtostr.c +++ b/test/util/ompi_numtostr.c @@ -1,16 +1,15 @@ #include "ompi_config.h" #include "opal/util/numtostr.h" -#include <string.h> #include <stdio.h> +#include <string.h> #include "support.h" -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { - char * tst; - char * expected; + char *tst; + char *expected; test_init("ompi_numtostr_t"); @@ -18,10 +17,9 @@ main(int argc, char *argv[]) expected = malloc(sizeof(long) * 8); snprintf(expected, sizeof(long) * 8, "%d", 10); if (strcmp(tst, expected) != 0) { - test_failure("opal_ltostr test failed"); - } - else { - test_success(); + test_failure("opal_ltostr test failed"); + } else { + test_success(); } free(tst); @@ -31,10 +29,9 @@ main(int argc, char *argv[]) expected = malloc(sizeof(long) * 8); snprintf(expected, sizeof(long) * 8, "%f", 5.32); if (strcmp(tst, expected) != 0) { - test_failure("opal_dtostr test failed"); - } - else { - test_success(); + test_failure("opal_dtostr test failed"); + } else { + test_success(); } test_finalize(); diff --git a/test/util/opal_argv.c b/test/util/opal_argv.c index 63bb3413da..11044d590e 100644 --- a/test/util/opal_argv.c +++ b/test/util/opal_argv.c @@ -18,12 +18,12 @@ #include "ompi_config.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> -#include "support.h" #include "opal/constants.h" #include "opal/util/argv.h" +#include "support.h" static bool test1(void); static bool test2(void); @@ -36,330 +36,342 @@ static bool test8(void); static bool test9(void); static bool test10(void); - -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - test_init("opal_argv_t"); - - if( test1() ) test_success(); - else test_failure("test1 argv test failed"); - - if( test2() ) test_success(); - else test_failure("test2 argv test failed"); - - if( test3() ) test_success(); - else test_failure("test3 argv test failed"); - - if( test4() ) test_success(); - else test_failure("test4 argv test failed"); + test_init("opal_argv_t"); + + if (test1()) + test_success(); + else + test_failure("test1 argv test failed"); + + if (test2()) + test_success(); + else + test_failure("test2 argv test failed"); + + if (test3()) + test_success(); + else + test_failure("test3 argv test failed"); + + if (test4()) + test_success(); + else + test_failure("test4 argv test failed"); + + if (test5()) + test_success(); + else + test_failure("test5 argv test failed"); + + if (test6()) + test_success(); + else + test_failure("test6 argv test failed"); + + if (test7()) + test_success(); + else + test_failure("test7 argv test failed"); + + if (test8()) + test_success(); + else + test_failure("test8 argv test failed"); + + if (test9()) { + test_success(); + } else { + test_failure("test9 argv test failed"); + } - if( test5() ) test_success(); - else test_failure("test5 argv test failed"); + if (test10()) { + test_success(); + } else { + test_failure("test10 argv test failed"); + } - if( test6() ) test_success(); - else test_failure("test6 argv test failed"); + /* All done */ + return test_finalize(); +} - if( test7() ) test_success(); - else test_failure("test7 argv test failed"); +static bool test1(void) +{ + char *a[] = {"argv1", "argv2", "argv3", NULL}; + char **argv = NULL; + int i, j, argc = 28; + + /* Test basic functionality. Start with a NULL argv and add the + contents of the a array. + + Set argc to be an initiall bogus number -- opal_argv_add() should + reset it back to zero after the first iteration. + + After adding the a[i], ensure that argv[0 - (i-1)] are the same + as a[0 - (i-1)]. + + Also ensure that a[i + 1] == NULL and that argc is the proper + value. */ + + for (i = 0; a[i] != NULL; ++i) { + if (opal_argv_append(&argc, &argv, a[i]) != OPAL_SUCCESS) { + return false; + } + for (j = 0; j <= i; ++j) { + if (strcmp(argv[j], a[j]) != 0) { + return false; + } + } + if (NULL != argv[i + 1]) { + return false; + } + if (argc != i + 1) { + return false; + } + } + opal_argv_free(argv); - if( test8() ) test_success(); - else test_failure("test8 argv test failed"); + return true; +} - if (test9()) { - test_success(); - } else { - test_failure("test9 argv test failed"); - } +static bool test2(void) +{ + int i, j; + char **argv = NULL; + int argc; + char *a[] = {"aaa", "bbb", "ccc", NULL}; + char *b[4]; + + /* Similar test to above, but ensure that opal_argv_add is actually + *copying* the string by value, not by reference. So copy the a + array into b, and then opal_argv_add() from b. After that, + scribble in the first character of the b[] string that we just + added, and compare all entries in a to argv -- they should be + identical (even though b is now corrupted). */ + + for (i = 0; a[i] != NULL; ++i) { + b[i] = strdup(a[i]); + } + b[i] = NULL; + + for (i = 0; b[i] != NULL; ++i) { + if (opal_argv_append(&argc, &argv, b[i]) != OPAL_SUCCESS) { + return false; + } + ++b[i][0]; + for (j = 0; j <= i; ++j) { + if (strcmp(argv[j], a[j]) != 0) { + return false; + } + } + if (NULL != argv[i + 1]) { + return false; + } + if (argc != i + 1) { + return false; + } + } - if (test10()) { - test_success(); - } else { - test_failure("test10 argv test failed"); - } + opal_argv_free(argv); + for (i = 0; b[i] != NULL; ++i) { + free(b[i]); + } - /* All done */ - return test_finalize(); + return true; } - -static bool test1(void) +static bool test3(void) { - char *a[] = { "argv1", "argv2", "argv3", NULL }; - char **argv = NULL; - int i, j, argc = 28; - - /* Test basic functionality. Start with a NULL argv and add the - contents of the a array. + int i; + int argc; + char **argv = NULL; + char *a[] = {"aaa", "bbb", "ccc", NULL}; + char *b[4]; - Set argc to be an initiall bogus number -- opal_argv_add() should - reset it back to zero after the first iteration. + /* Try to free a null argv -- should be harmless (we'll seg fault if + it's not!) */ - After adding the a[i], ensure that argv[0 - (i-1)] are the same - as a[0 - (i-1)]. + opal_argv_free(argv); - Also ensure that a[i + 1] == NULL and that argc is the proper - value. */ + /* Now add some stuff and try to free it. We'll seg fault if + anything goes wrong. a is on the stack, so if it mistakenly + tries to free it, we should get a seg fault. */ - for (i = 0; a[i] != NULL; ++i) { - if (opal_argv_append(&argc, &argv, a[i]) != OPAL_SUCCESS) { - return false; - } - for (j = 0; j <= i; ++j) { - if (strcmp(argv[j], a[j]) != 0) { - return false; - } - } - if (NULL != argv[i + 1]) { - return false; - } - if (argc != i + 1) { - return false; + for (i = 0; a[i] != NULL; ++i) { + if (opal_argv_append(&argc, &argv, a[i]) != OPAL_SUCCESS) { + return false; + } } - } - opal_argv_free(argv); - - return true; -} + opal_argv_free(argv); + /* Do the same thing but guarantee that the copied array was from + the heap and was freed before we call opal_argv_free(). */ -static bool test2(void) -{ - int i, j; - char **argv = NULL; - int argc; - char *a[] = { "aaa", "bbb", "ccc", NULL }; - char *b[4]; - - /* Similar test to above, but ensure that opal_argv_add is actually - *copying* the string by value, not by reference. So copy the a - array into b, and then opal_argv_add() from b. After that, - scribble in the first character of the b[] string that we just - added, and compare all entries in a to argv -- they should be - identical (even though b is now corrupted). */ - - for (i = 0; a[i] != NULL; ++i) { - b[i] = strdup(a[i]); - } - b[i] = NULL; - - for (i = 0; b[i] != NULL; ++i) { - if (opal_argv_append(&argc, &argv, b[i]) != OPAL_SUCCESS) { - return false; - } - ++b[i][0]; - for (j = 0; j <= i; ++j) { - if (strcmp(argv[j], a[j]) != 0) { - return false; - } + argc = 0; + argv = NULL; + for (i = 0; a[i] != NULL; ++i) { + b[i] = strdup(a[i]); } - if (NULL != argv[i + 1]) { - return false; + b[i] = NULL; + for (i = 0; b[i] != NULL; ++i) { + if (opal_argv_append(&argc, &argv, b[i]) != OPAL_SUCCESS) { + return false; + } } - if (argc != i + 1) { - return false; + for (i = 0; b[i] != NULL; ++i) { + free(b[i]); } - } - - opal_argv_free(argv); - for (i = 0; b[i] != NULL; ++i) { - free(b[i]); - } - - return true; -} + opal_argv_free(argv); + /* All done */ -static bool test3(void) -{ - int i; - int argc; - char **argv = NULL; - char *a[] = { "aaa", "bbb", "ccc", NULL }; - char *b[4]; - - /* Try to free a null argv -- should be harmless (we'll seg fault if - it's not!) */ - - opal_argv_free(argv); - - /* Now add some stuff and try to free it. We'll seg fault if - anything goes wrong. a is on the stack, so if it mistakenly - tries to free it, we should get a seg fault. */ - - for (i = 0; a[i] != NULL; ++i) { - if (opal_argv_append(&argc, &argv, a[i]) != OPAL_SUCCESS) { - return false; - } - } - opal_argv_free(argv); - - /* Do the same thing but guarantee that the copied array was from - the heap and was freed before we call opal_argv_free(). */ - - argc = 0; - argv = NULL; - for (i = 0; a[i] != NULL; ++i) { - b[i] = strdup(a[i]); - } - b[i] = NULL; - for (i = 0; b[i] != NULL; ++i) { - if (opal_argv_append(&argc, &argv, b[i]) != OPAL_SUCCESS) { - return false; - } - } - for (i = 0; b[i] != NULL; ++i) { - free(b[i]); - } - opal_argv_free(argv); - - /* All done */ - - return true; + return true; } - static bool test4(void) { - size_t i, count; - char *a = strdup("the quick brown fox jumped over the lazy dog a_really_long_argument_to_force_a_long_copy_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"); - char **b; - char *start; - - /* split a string into an argv, and compare it against the original - string. Add double spaces into the string; opal_argv_split() - should skip them. */ - - b = opal_argv_split(a, ' '); - - for (count = i = 1; i < strlen(a); ++i) { - if (a[i] != ' ' && a[i - 1] == ' ') { - ++count; - } - } - for (i = 0; b[i] != NULL; ++i) { - continue; - } - if (i != count) { - return false; - } - - /* now do the same thing and compare each token in b */ - - for (start = a, count = i = 0; i < strlen(a); ++i) { - if (a[i] == ' ' && a[i - 1] != ' ') { - a[i] = '\0'; - if (strcmp(start, b[count]) != 0) { + size_t i, count; + char *a = strdup("the quick brown fox jumped over the lazy dog " + "a_really_long_argument_to_force_a_long_copy_" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"); + char **b; + char *start; + + /* split a string into an argv, and compare it against the original + string. Add double spaces into the string; opal_argv_split() + should skip them. */ + + b = opal_argv_split(a, ' '); + + for (count = i = 1; i < strlen(a); ++i) { + if (a[i] != ' ' && a[i - 1] == ' ') { + ++count; + } + } + for (i = 0; b[i] != NULL; ++i) { + continue; + } + if (i != count) { return false; - } - ++count; - a[i] = ' '; } - if (a[i] == ' ' && a[i + 1] != ' ') { - start = a + i + 1; + + /* now do the same thing and compare each token in b */ + + for (start = a, count = i = 0; i < strlen(a); ++i) { + if (a[i] == ' ' && a[i - 1] != ' ') { + a[i] = '\0'; + if (strcmp(start, b[count]) != 0) { + return false; + } + ++count; + a[i] = ' '; + } + if (a[i] == ' ' && a[i + 1] != ' ') { + start = a + i + 1; + } + } + if (strcmp(start, b[count]) != 0) { + return false; } - } - if (strcmp(start, b[count]) != 0) { - return false; - } - /* all done */ + /* all done */ - opal_argv_free(b); - free(a); - return true; + opal_argv_free(b); + free(a); + return true; } - static bool test5(void) { - char *a[] = { "aaa", "bbb", "ccc", NULL }; + char *a[] = {"aaa", "bbb", "ccc", NULL}; - return (opal_argv_count(NULL) == 0 && opal_argv_count(a) == 3); + return (opal_argv_count(NULL) == 0 && opal_argv_count(a) == 3); } - static bool test6(void) { - char *a = "the quick brown fox jumped over the lazy dog a_really_long_argument_to_force_a_long_copy_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"; - char **b; - char *c; + char *a = "the quick brown fox jumped over the lazy dog " + "a_really_long_argument_to_force_a_long_copy_" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"; + char **b; + char *c; - /* split the string above and then join it -- the joined version - should be just like the original */ + /* split the string above and then join it -- the joined version + should be just like the original */ - b = opal_argv_split(a, ' '); - c = opal_argv_join(b, ' '); + b = opal_argv_split(a, ' '); + c = opal_argv_join(b, ' '); - if (strcmp(a, c) != 0) { - return false; - } + if (strcmp(a, c) != 0) { + return false; + } - /* All done */ + /* All done */ - free(c); - opal_argv_free(b); - return true; + free(c); + opal_argv_free(b); + return true; } - static bool test7(void) { - char *a[] = { "a", "b", "c", NULL }; - size_t a_len = (1 + 1 + sizeof(char *)) * 3 + sizeof(char **); + char *a[] = {"a", "b", "c", NULL}; + size_t a_len = (1 + 1 + sizeof(char *)) * 3 + sizeof(char **); - /* check a NULL pointer first -- should return 0 */ + /* check a NULL pointer first -- should return 0 */ - if (opal_argv_len(NULL) != (size_t) 0) { - return false; - } + if (opal_argv_len(NULL) != (size_t) 0) { + return false; + } - /* now check a real string */ - /* size should be (sizeof(char **) + (sizeof(char) + sizeof('\0') + - sizeof(char*)) * 3) */ + /* now check a real string */ + /* size should be (sizeof(char **) + (sizeof(char) + sizeof('\0') + + sizeof(char*)) * 3) */ - if (opal_argv_len(a) != a_len) { - return false; - } + if (opal_argv_len(a) != a_len) { + return false; + } - /* All done */ + /* All done */ - return true; + return true; } - static bool test8(void) { - char *a[] = { "aaa", "bbbbbbbb", "cccccccccc", NULL }; - int i; - char **b; + char *a[] = {"aaa", "bbbbbbbb", "cccccccccc", NULL}; + int i; + char **b; - /* bozo case */ + /* bozo case */ - if (NULL != opal_argv_copy(NULL)) { - return false; - } + if (NULL != opal_argv_copy(NULL)) { + return false; + } - /* dup the a array and compare it (array length, contents, etc.) */ + /* dup the a array and compare it (array length, contents, etc.) */ - b = opal_argv_copy(a); + b = opal_argv_copy(a); - if (opal_argv_count(a) != opal_argv_count(b)) { - return false; - } - for (i = 0; a[i] != NULL; ++i) { - if (0 != strcmp(a[i], b[i])) { - return false; + if (opal_argv_count(a) != opal_argv_count(b)) { + return false; + } + for (i = 0; a[i] != NULL; ++i) { + if (0 != strcmp(a[i], b[i])) { + return false; + } } - } - /* All done */ + /* All done */ - opal_argv_free(b); - return true; + opal_argv_free(b); + return true; } - static bool test9(void) { char **a = NULL; @@ -374,8 +386,7 @@ static bool test9(void) a = NULL; argc = 0; opal_argv_append(&argc, &a, "foo"); - if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 7, 1) || - 1 != opal_argv_count(a)) { + if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 7, 1) || 1 != opal_argv_count(a)) { return false; } opal_argv_free(a); @@ -383,8 +394,7 @@ static bool test9(void) a = NULL; argc = 0; opal_argv_append(&argc, &a, "foo"); - if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 0, 0) || - 1 != opal_argv_count(a)) { + if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 0, 0) || 1 != opal_argv_count(a)) { return false; } opal_argv_free(a); @@ -400,13 +410,9 @@ static bool test9(void) opal_argv_append(&argc, &a, "d"); opal_argv_append(&argc, &a, "e"); opal_argv_append(&argc, &a, "f"); - if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 0, 1) || - 5 != opal_argv_count(a) || - 0 != strcmp(a[0], "b") || - 0 != strcmp(a[1], "c") || - 0 != strcmp(a[2], "d") || - 0 != strcmp(a[3], "e") || - 0 != strcmp(a[4], "f")) { + if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 0, 1) || 5 != opal_argv_count(a) + || 0 != strcmp(a[0], "b") || 0 != strcmp(a[1], "c") || 0 != strcmp(a[2], "d") + || 0 != strcmp(a[3], "e") || 0 != strcmp(a[4], "f")) { return false; } opal_argv_free(a); @@ -421,12 +427,9 @@ static bool test9(void) opal_argv_append(&argc, &a, "d"); opal_argv_append(&argc, &a, "e"); opal_argv_append(&argc, &a, "f"); - if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 0, 2) || - 4 != opal_argv_count(a) || - 0 != strcmp(a[0], "c") || - 0 != strcmp(a[1], "d") || - 0 != strcmp(a[2], "e") || - 0 != strcmp(a[3], "f")) { + if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 0, 2) || 4 != opal_argv_count(a) + || 0 != strcmp(a[0], "c") || 0 != strcmp(a[1], "d") || 0 != strcmp(a[2], "e") + || 0 != strcmp(a[3], "f")) { return false; } opal_argv_free(a); @@ -441,13 +444,9 @@ static bool test9(void) opal_argv_append(&argc, &a, "d"); opal_argv_append(&argc, &a, "e"); opal_argv_append(&argc, &a, "f"); - if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 1, 1) || - 5 != opal_argv_count(a) || - 0 != strcmp(a[0], "a") || - 0 != strcmp(a[1], "c") || - 0 != strcmp(a[2], "d") || - 0 != strcmp(a[3], "e") || - 0 != strcmp(a[4], "f")) { + if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 1, 1) || 5 != opal_argv_count(a) + || 0 != strcmp(a[0], "a") || 0 != strcmp(a[1], "c") || 0 != strcmp(a[2], "d") + || 0 != strcmp(a[3], "e") || 0 != strcmp(a[4], "f")) { return false; } opal_argv_free(a); @@ -462,12 +461,9 @@ static bool test9(void) opal_argv_append(&argc, &a, "d"); opal_argv_append(&argc, &a, "e"); opal_argv_append(&argc, &a, "f"); - if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 1, 2) || - 4 != opal_argv_count(a) || - 0 != strcmp(a[0], "a") || - 0 != strcmp(a[1], "d") || - 0 != strcmp(a[2], "e") || - 0 != strcmp(a[3], "f")) { + if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 1, 2) || 4 != opal_argv_count(a) + || 0 != strcmp(a[0], "a") || 0 != strcmp(a[1], "d") || 0 != strcmp(a[2], "e") + || 0 != strcmp(a[3], "f")) { return false; } opal_argv_free(a); @@ -478,8 +474,7 @@ static bool test9(void) argc = 0; opal_argv_append(&argc, &a, "a"); opal_argv_append(&argc, &a, "b"); - if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 0, 99) || - 0 != opal_argv_count(a)) { + if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 0, 99) || 0 != opal_argv_count(a)) { return false; } opal_argv_free(a); @@ -490,9 +485,8 @@ static bool test9(void) argc = 0; opal_argv_append(&argc, &a, "a"); opal_argv_append(&argc, &a, "b"); - if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 1, 99) || - 1 != opal_argv_count(a) || - 0 != strcmp(a[0], "a")) { + if (OPAL_SUCCESS != opal_argv_delete(&argc, &a, 1, 99) || 1 != opal_argv_count(a) + || 0 != strcmp(a[0], "a")) { return false; } opal_argv_free(a); @@ -502,7 +496,6 @@ static bool test9(void) return true; } - static bool test10(void) { char **orig; @@ -541,14 +534,10 @@ static bool test10(void) opal_argv_append(&o, &orig, "orig a"); opal_argv_append(&o, &orig, "orig b"); opal_argv_append(&o, &orig, "orig c"); - if (OPAL_SUCCESS != opal_argv_insert(&orig, 99, insert) || - 6 != opal_argv_count(orig) || - 0 != strcmp(orig[0], "orig a") || - 0 != strcmp(orig[1], "orig b") || - 0 != strcmp(orig[2], "orig c") || - 0 != strcmp(orig[3], "insert a") || - 0 != strcmp(orig[4], "insert b") || - 0 != strcmp(orig[5], "insert c")) { + if (OPAL_SUCCESS != opal_argv_insert(&orig, 99, insert) || 6 != opal_argv_count(orig) + || 0 != strcmp(orig[0], "orig a") || 0 != strcmp(orig[1], "orig b") + || 0 != strcmp(orig[2], "orig c") || 0 != strcmp(orig[3], "insert a") + || 0 != strcmp(orig[4], "insert b") || 0 != strcmp(orig[5], "insert c")) { return false; } opal_argv_free(orig); @@ -566,14 +555,10 @@ static bool test10(void) opal_argv_append(&o, &orig, "orig a"); opal_argv_append(&o, &orig, "orig b"); opal_argv_append(&o, &orig, "orig c"); - if (OPAL_SUCCESS != opal_argv_insert(&orig, 0, insert) || - 6 != opal_argv_count(orig) || - 0 != strcmp(orig[3], "orig a") || - 0 != strcmp(orig[4], "orig b") || - 0 != strcmp(orig[5], "orig c") || - 0 != strcmp(orig[0], "insert a") || - 0 != strcmp(orig[1], "insert b") || - 0 != strcmp(orig[2], "insert c")) { + if (OPAL_SUCCESS != opal_argv_insert(&orig, 0, insert) || 6 != opal_argv_count(orig) + || 0 != strcmp(orig[3], "orig a") || 0 != strcmp(orig[4], "orig b") + || 0 != strcmp(orig[5], "orig c") || 0 != strcmp(orig[0], "insert a") + || 0 != strcmp(orig[1], "insert b") || 0 != strcmp(orig[2], "insert c")) { return false; } opal_argv_free(orig); @@ -591,14 +576,10 @@ static bool test10(void) opal_argv_append(&o, &orig, "orig a"); opal_argv_append(&o, &orig, "orig b"); opal_argv_append(&o, &orig, "orig c"); - if (OPAL_SUCCESS != opal_argv_insert(&orig, 1, insert) || - 6 != opal_argv_count(orig) || - 0 != strcmp(orig[0], "orig a") || - 0 != strcmp(orig[4], "orig b") || - 0 != strcmp(orig[5], "orig c") || - 0 != strcmp(orig[1], "insert a") || - 0 != strcmp(orig[2], "insert b") || - 0 != strcmp(orig[3], "insert c")) { + if (OPAL_SUCCESS != opal_argv_insert(&orig, 1, insert) || 6 != opal_argv_count(orig) + || 0 != strcmp(orig[0], "orig a") || 0 != strcmp(orig[4], "orig b") + || 0 != strcmp(orig[5], "orig c") || 0 != strcmp(orig[1], "insert a") + || 0 != strcmp(orig[2], "insert b") || 0 != strcmp(orig[3], "insert c")) { return false; } opal_argv_free(orig); @@ -619,17 +600,12 @@ static bool test10(void) opal_argv_append(&o, &orig, "orig d"); opal_argv_append(&o, &orig, "orig e"); opal_argv_append(&o, &orig, "orig f"); - if (OPAL_SUCCESS != opal_argv_insert(&orig, 1, insert) || - 9 != opal_argv_count(orig) || - 0 != strcmp(orig[0], "orig a") || - 0 != strcmp(orig[4], "orig b") || - 0 != strcmp(orig[5], "orig c") || - 0 != strcmp(orig[6], "orig d") || - 0 != strcmp(orig[7], "orig e") || - 0 != strcmp(orig[8], "orig f") || - 0 != strcmp(orig[1], "insert a") || - 0 != strcmp(orig[2], "insert b") || - 0 != strcmp(orig[3], "insert c")) { + if (OPAL_SUCCESS != opal_argv_insert(&orig, 1, insert) || 9 != opal_argv_count(orig) + || 0 != strcmp(orig[0], "orig a") || 0 != strcmp(orig[4], "orig b") + || 0 != strcmp(orig[5], "orig c") || 0 != strcmp(orig[6], "orig d") + || 0 != strcmp(orig[7], "orig e") || 0 != strcmp(orig[8], "orig f") + || 0 != strcmp(orig[1], "insert a") || 0 != strcmp(orig[2], "insert b") + || 0 != strcmp(orig[3], "insert c")) { return false; } opal_argv_free(orig); diff --git a/test/util/opal_basename.c b/test/util/opal_basename.c index e76a656448..65de549ccc 100644 --- a/test/util/opal_basename.c +++ b/test/util/opal_basename.c @@ -20,37 +20,34 @@ #include "ompi_config.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> -#include "support.h" #include "opal/util/basename.h" #include "opal/util/printf.h" +#include "support.h" +static void test(const char *in, const char *out); -static void test(const char* in, const char* out); - - -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { - test_init("opal_basename()"); + test_init("opal_basename()"); - test("foo.txt", "foo.txt"); - test("/foo/bar/baz", "baz"); - test("/yow.c", "yow.c"); - test("/", "/"); + test("foo.txt", "foo.txt"); + test("/foo/bar/baz", "baz"); + test("/yow.c", "yow.c"); + test("/", "/"); - test("foo.txt/", "foo.txt"); - test("/foo/bar/baz/", "baz"); - test("/yow.c/", "yow.c"); - test("//", "/"); + test("foo.txt/", "foo.txt"); + test("/foo/bar/baz/", "baz"); + test("/yow.c/", "yow.c"); + test("//", "/"); - /* All done */ - return test_finalize(); + /* All done */ + return test_finalize(); } - -void test(const char* in, const char* out) +void test(const char *in, const char *out) { char *msg; char *ret = opal_basename(in); @@ -58,8 +55,7 @@ void test(const char* in, const char* out) if (0 == strcmp(ret, out)) { test_success(); } else { - opal_asprintf(&msg, "Mismatch: input \"%s\", expected \"%s\", got \"%s\"\n", - in, out, ret); + opal_asprintf(&msg, "Mismatch: input \"%s\", expected \"%s\", got \"%s\"\n", in, out, ret); test_failure(msg); free(msg); } @@ -67,5 +63,3 @@ void test(const char* in, const char* out) free(ret); } } - - diff --git a/test/util/opal_bit_ops.c b/test/util/opal_bit_ops.c index b915b2b242..17618d8bd2 100644 --- a/test/util/opal_bit_ops.c +++ b/test/util/opal_bit_ops.c @@ -23,10 +23,10 @@ #include <stdio.h> #include <string.h> -#include "support.h" #include "opal/util/bit_ops.h" #include "opal/util/output.h" #include "opal/util/printf.h" +#include "support.h" /* #define DEBUG @@ -37,38 +37,52 @@ static int test_cube_dim(int value); static int test_next_poweroftwo(int value); static int test_next_poweroftwo_inclusive(int value); -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int i; - int vals[] = {0, 1, 2, 3, 4, 5, 127, 128, 129, (1 << 29) -1, (1 << 29), (1 << 29) +1, (1 << 30) -1, (1 << 30) /* And NOT (1 << 30) +1 */}; + int vals[] = { + 0, + 1, + 2, + 3, + 4, + 5, + 127, + 128, + 129, + (1 << 29) - 1, + (1 << 29), + (1 << 29) + 1, + (1 << 30) - 1, + (1 << 30), /* And NOT (1 << 30) +1 */ + }; test_init("opal_bit_ops()"); #ifdef DEBUG - printf ("Test usage: ./opal_bit_ops [VALUES]\n"); + printf("Test usage: ./opal_bit_ops [VALUES]\n"); #endif if (1 < argc) { for (i = 1; i < argc; i++) { int value; - value = atoi (argv[i]); - printf ("Testing %d. argument test_next_poweroftwo(%d): %s\n", - i, value, test_next_poweroftwo(value) ? "correct" : "wrong"); + value = atoi(argv[i]); + printf("Testing %d. argument test_next_poweroftwo(%d): %s\n", i, value, + test_next_poweroftwo(value) ? "correct" : "wrong"); } } - for (i = 0; i < (int)(sizeof(vals)/sizeof(vals[0])); i++) { - test_hibit (vals[i], 8 * sizeof(int) -2); - test_hibit (vals[i], 3); - test_cube_dim (vals[i]); - test_next_poweroftwo (vals[i]); - test_next_poweroftwo_inclusive (vals[i]); + for (i = 0; i < (int) (sizeof(vals) / sizeof(vals[0])); i++) { + test_hibit(vals[i], 8 * sizeof(int) - 2); + test_hibit(vals[i], 3); + test_cube_dim(vals[i]); + test_next_poweroftwo(vals[i]); + test_next_poweroftwo_inclusive(vals[i]); } /* All done */ return test_finalize(); } - /* REFERENCE FUNCTION */ static int hibit(int value, int start) { @@ -89,33 +103,32 @@ static int hibit(int value, int start) static int test_hibit(int value, int start) { int out; - int bit = hibit (value, start); + int bit = hibit(value, start); #ifdef DEBUG - printf ("test_hibit(): value:%d expect:%d\n", - value, bit); + printf("test_hibit(): value:%d expect:%d\n", value, bit); #endif - if (bit == (out = opal_hibit (value, start))) { + if (bit == (out = opal_hibit(value, start))) { test_success(); return 1; } else { - char * msg; + char *msg; opal_asprintf(&msg, "Mismatch for hibit (w/ start:%d): value:%d, expected:%d got:%d\n", - start, value, bit, out); + start, value, bit, out); test_failure(msg); free(msg); } return 0; } - /* REFERENCE FUNCTION */ static int cube_dim(int value) { int dim, size; - for (dim = 0, size = 1; size < value; ++dim, size <<= 1); + for (dim = 0, size = 1; size < value; ++dim, size <<= 1) + ; return dim; } @@ -123,69 +136,64 @@ static int cube_dim(int value) static int test_cube_dim(int value) { int out; - int dim = cube_dim (value); + int dim = cube_dim(value); #ifdef DEBUG - printf ("test_cube_dim(): value:%d expect:%d\n", - value, dim); + printf("test_cube_dim(): value:%d expect:%d\n", value, dim); #endif - if (dim == (out = opal_cube_dim (value))) { + if (dim == (out = opal_cube_dim(value))) { test_success(); return 1; } else { - char * msg; - opal_asprintf(&msg, "Mismatch for cube_dim: value:%d, expected:%d got:%d\n", - value, dim, out); + char *msg; + opal_asprintf(&msg, "Mismatch for cube_dim: value:%d, expected:%d got:%d\n", value, dim, + out); test_failure(msg); free(msg); } return 0; } - /* REFERENCE FUNCTION */ static int next_poweroftwo(int value) { int power2; - for (power2 = 1; value; value >>=1, power2 <<=1) /* empty */; + for (power2 = 1; value; value >>= 1, power2 <<= 1) /* empty */ + ; return power2; } - static int test_next_poweroftwo(int value) { int out; - int power2 = next_poweroftwo (value); + int power2 = next_poweroftwo(value); #ifdef DEBUG - printf ("test_next_poweroftwo(): value:%d expect:%d\n", - value, power2); + printf("test_next_poweroftwo(): value:%d expect:%d\n", value, power2); #endif - if (power2 == (out = opal_next_poweroftwo (value))) { + if (power2 == (out = opal_next_poweroftwo(value))) { test_success(); return 1; } else { - char * msg; - opal_asprintf(&msg, "Mismatch for power-of-two: value:%d, expected:%d got:%d\n", - value, power2, out); + char *msg; + opal_asprintf(&msg, "Mismatch for power-of-two: value:%d, expected:%d got:%d\n", value, + power2, out); test_failure(msg); free(msg); } return 0; } - - /* REFERENCE FUNCTION */ static int next_poweroftwo_inclusive(int value) { int power2 = 1; - while ( power2 < value ) + while (power2 < value) power2 <<= 1; return power2; @@ -194,27 +202,22 @@ static int next_poweroftwo_inclusive(int value) static int test_next_poweroftwo_inclusive(int value) { int out; - int power2 = next_poweroftwo_inclusive (value); + int power2 = next_poweroftwo_inclusive(value); #ifdef DEBUG - printf ("test_next_poweroftwo(): value:%d expect:%d\n", - value, power2); + printf("test_next_poweroftwo(): value:%d expect:%d\n", value, power2); #endif - if (power2 == (out = opal_next_poweroftwo_inclusive (value))) { + if (power2 == (out = opal_next_poweroftwo_inclusive(value))) { test_success(); return 1; } else { - char * msg; + char *msg; opal_asprintf(&msg, "Mismatch for power-of-two-inclusive: value:%d, expected:%d got:%d\n", - value, power2, out); + value, power2, out); test_failure(msg); free(msg); } return 0; } - - - - diff --git a/test/util/opal_error.c b/test/util/opal_error.c index f815dd9f0b..c452441e41 100644 --- a/test/util/opal_error.c +++ b/test/util/opal_error.c @@ -19,43 +19,44 @@ #include "ompi_config.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> +# include <sys/param.h> #endif #ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> +# include <netinet/in.h> #endif #ifdef HAVE_UNISTD_H -#include <unistd.h> +# include <unistd.h> #endif #ifdef HAVE_NETDB_H -#include <netdb.h> +# include <netdb.h> #endif #include <errno.h> -#include "opal/util/error.h" #include "opal/constants.h" #include "opal/runtime/opal.h" +#include "opal/util/error.h" #include "orte/constants.h" -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { int i; - int errors[] = { OPAL_SUCCESS, - OPAL_ERROR, - OPAL_ERR_OUT_OF_RESOURCE, - OPAL_ERR_NOT_FOUND, - OPAL_ERR_BAD_PARAM, - OPAL_ERR_MAX + 10, /* bad value */ - 1 }; /* sentinal */ + int errors[] = { + OPAL_SUCCESS, + OPAL_ERROR, + OPAL_ERR_OUT_OF_RESOURCE, + OPAL_ERR_NOT_FOUND, + OPAL_ERR_BAD_PARAM, + OPAL_ERR_MAX + 10, /* bad value */ + 1, /* sentinal */ + }; char buf[1024]; opal_init(&argc, &argv); - for (i = 0 ; errors[i] <= 0 ; ++i) { + for (i = 0; errors[i] <= 0; ++i) { printf("--> error code: %d\n", errors[i]); opal_perror(errors[i], "perror test"); printf("strerror test: %s\n", opal_strerror(errors[i])); diff --git a/test/util/opal_if.c b/test/util/opal_if.c index 7bb6feec78..20d5def9ca 100644 --- a/test/util/opal_if.c +++ b/test/util/opal_if.c @@ -21,29 +21,27 @@ #include "ompi_config.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> +# include <sys/param.h> #endif #ifdef HAVE_NETINET_IN_H -#include <netinet/in.h> +# include <netinet/in.h> #endif #ifdef HAVE_UNISTD_H -#include <unistd.h> +# include <unistd.h> #endif #ifdef HAVE_NETDB_H -#include <netdb.h> +# include <netdb.h> #endif -#include "support.h" +#include "opal/constants.h" #include "opal/runtime/opal.h" #include "opal/util/if.h" -#include "opal/constants.h" - +#include "support.h" -static bool -test_ifaddrtoname(char *addr) +static bool test_ifaddrtoname(char *addr) { int ret; char addrname[100]; @@ -58,8 +56,7 @@ test_ifaddrtoname(char *addr) } } -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { const char *hostname; diff --git a/test/util/opal_os_create_dirpath.c b/test/util/opal_os_create_dirpath.c index 394e724ddd..ac9a26fe5a 100644 --- a/test/util/opal_os_create_dirpath.c +++ b/test/util/opal_os_create_dirpath.c @@ -19,32 +19,31 @@ #include "orte_config.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #ifdef HAVE_UNISTD_H -#include <unistd.h> +# include <unistd.h> #endif #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> +# include <sys/param.h> #endif #include <sys/stat.h> -#include "support.h" -#include "opal/runtime/opal.h" #include "opal/constants.h" -#include "opal/util/os_path.h" +#include "opal/runtime/opal.h" #include "opal/util/os_dirpath.h" +#include "opal/util/os_path.h" +#include "support.h" #define PATH_SEP "/" static const char *path_sep = PATH_SEP; -static bool test1(void); /* trivial test */ -static bool test2(void); /* test existing path, both with and without correct mode */ -static bool test3(void); /* test making a directory tree */ +static bool test1(void); /* trivial test */ +static bool test2(void); /* test existing path, both with and without correct mode */ +static bool test3(void); /* test making a directory tree */ - -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { opal_init(&argc, &argv); @@ -54,23 +53,20 @@ int main(int argc, char* argv[]) if (test1()) { test_success(); - } - else { - test_failure("opal_os_create_dirpath test1 failed"); + } else { + test_failure("opal_os_create_dirpath test1 failed"); } if (test2()) { test_success(); - } - else { - test_failure("opal_os_create_dirpath test2 failed"); + } else { + test_failure("opal_os_create_dirpath test2 failed"); } if (test3()) { test_success(); - } - else { - test_failure("opal_os_create_dirpath test3 failed"); + } else { + test_failure("opal_os_create_dirpath test3 failed"); } test_finalize(); @@ -79,19 +75,17 @@ int main(int argc, char* argv[]) return 0; } - static bool test1(void) { /* Test trivial functionality. Program should return OPAL_ERROR when called with NULL path. */ if (OPAL_SUCCESS == opal_os_dirpath_create(NULL, S_IRWXU)) - return(false); + return false; return true; } - static bool test2(void) { char *tmp; @@ -99,30 +93,30 @@ static bool test2(void) if (NULL == path_sep) { printf("test2 cannot be run\n"); - return(false); + return false; } tmp = opal_os_path(true, "tmp", NULL); if (0 != mkdir(tmp, S_IRWXU)) { printf("test2 could not be run - directory could not be made\n"); - return(false); + return false; } if (OPAL_SUCCESS != opal_os_dirpath_create(tmp, S_IRWXU)) { rmdir(tmp); - return(false); + return false; } chmod(tmp, S_IRUSR); if (OPAL_SUCCESS != opal_os_dirpath_create(tmp, S_IRWXU)) { rmdir(tmp); - return(false); + return false; } stat(tmp, &buf); if (S_IRWXU != (S_IRWXU & buf.st_mode)) { rmdir(tmp); - return(false); + return false; } rmdir(tmp); @@ -131,16 +125,15 @@ static bool test2(void) return true; } - static bool test3(void) { char *out; struct stat buf; - char *a[] = { "aaa", "bbb", "ccc", NULL }; + char *a[] = {"aaa", "bbb", "ccc", NULL}; if (NULL == path_sep) { printf("test3 cannot be run\n"); - return(false); + return false; } out = opal_os_path(true, a[0], a[1], a[2], NULL); @@ -154,10 +147,10 @@ static bool test3(void) out = opal_os_path(true, a[0], NULL); if (0 == stat(out, &buf)) rmdir(out); - return(false); + return false; } free(out); - return(true); + return true; } diff --git a/test/util/opal_os_path.c b/test/util/opal_os_path.c index 67a5a16975..334574f0fc 100644 --- a/test/util/opal_os_path.c +++ b/test/util/opal_os_path.c @@ -18,10 +18,10 @@ #include "orte_config.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> +# include <sys/param.h> #endif #include "opal/runtime/opal.h" @@ -32,13 +32,12 @@ static const char *path_sep = PATH_SEP; -static bool test1(void); /* trivial answer test */ -static bool test2(void); /* relative path test */ -static bool test3(void); /* absolute path test */ -static bool test4(void); /* missing path separator test */ - +static bool test1(void); /* trivial answer test */ +static bool test2(void); /* relative path test */ +static bool test3(void); /* absolute path test */ +static bool test4(void); /* missing path separator test */ -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { opal_init(&argc, &argv); @@ -46,30 +45,26 @@ int main(int argc, char* argv[]) if (test1()) { test_success(); - } - else { - test_failure("opal_os_path_t test1 failed"); + } else { + test_failure("opal_os_path_t test1 failed"); } if (test2()) { test_success(); - } - else { - test_failure("opal_os_path_t test2 failed"); + } else { + test_failure("opal_os_path_t test2 failed"); } if (test3()) { test_success(); - } - else { - test_failure("opal_os_path_t test3 failed"); + } else { + test_failure("opal_os_path_t test3 failed"); } if (test4()) { test_success(); - } - else { - test_failure("opal_os_path_t test4 failed"); + } else { + test_failure("opal_os_path_t test4 failed"); } opal_finalize(); @@ -78,40 +73,38 @@ int main(int argc, char* argv[]) return 0; } - static bool test1(void) { char *out, answer[100]; /* Test trivial functionality. Program should return ".[separator]" when called in relative * mode, and the separator character when called in absolute mode. */ - if (NULL != (out = opal_os_path(true,NULL))) { + if (NULL != (out = opal_os_path(true, NULL))) { answer[0] = '\0'; strcat(answer, "."); strcat(answer, path_sep); if (0 != strcmp(answer, out)) - return(false); + return false; free(out); } - if (NULL != (out = opal_os_path(false,NULL))) { + if (NULL != (out = opal_os_path(false, NULL))) { if (0 != strcmp(path_sep, out)) - return(false); + return false; free(out); } return true; } - static bool test2(void) { char out[1024]; char *tmp; - char *a[] = { "aaa", "bbb", "ccc", NULL }; + char *a[] = {"aaa", "bbb", "ccc", NULL}; if (NULL == path_sep) { printf("test2 cannot be run\n"); - return(false); + return false; } /* Construct a relative path name and see if it comes back correctly. Check multiple depths. */ @@ -122,36 +115,35 @@ static bool test2(void) tmp = opal_os_path(true, a[0], NULL); if (0 != strcmp(out, tmp)) - return(false); + return false; free(tmp); strcat(out, path_sep); strcat(out, a[1]); tmp = opal_os_path(true, a[0], a[1], NULL); if (0 != strcmp(out, tmp)) - return(false); + return false; free(tmp); strcat(out, path_sep); strcat(out, a[2]); tmp = opal_os_path(true, a[0], a[1], a[2], NULL); if (0 != strcmp(out, tmp)) - return(false); + return false; free(tmp); return true; } - static bool test3(void) { char out[1024]; char *tmp; - char *a[] = { "aaa", "bbb", "ccc", NULL }; + char *a[] = {"aaa", "bbb", "ccc", NULL}; if (NULL == path_sep) { printf("test3 cannot be run\n"); - return(false); + return false; } /* Same as prior test, only with absolute path name */ @@ -160,21 +152,21 @@ static bool test3(void) strcat(out, a[0]); tmp = opal_os_path(false, a[0], NULL); if (0 != strcmp(out, tmp)) - return(false); + return false; free(tmp); strcat(out, path_sep); strcat(out, a[1]); tmp = opal_os_path(false, a[0], a[1], NULL); if (0 != strcmp(out, tmp)) - return(false); + return false; free(tmp); strcat(out, path_sep); strcat(out, a[2]); tmp = opal_os_path(false, a[0], a[1], a[2], NULL); if (0 != strcmp(out, tmp)) - return(false); + return false; free(tmp); return true; @@ -187,15 +179,15 @@ static bool test4(void) if (NULL == path_sep) { printf("test4 cannot be run\n"); - return(false); + return false; } - for (i=0; i< MAXPATHLEN+5; i++) { + for (i = 0; i < MAXPATHLEN + 5; i++) { a[i] = 'a'; } a[i] = '\0'; if (NULL != opal_os_path(false, a, NULL)) { - return(false); + return false; } - return (true); + return true; } diff --git a/test/util/opal_path_nfs.c b/test/util/opal_path_nfs.c index 5e31e82990..27fecdb8fa 100644 --- a/test/util/opal_path_nfs.c +++ b/test/util/opal_path_nfs.c @@ -28,26 +28,26 @@ #include "opal_config.h" +#include <dirent.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> -#include <dirent.h> +#include <string.h> #include <sys/param.h> #ifdef HAVE_SYS_MOUNT_H -#include <sys/mount.h> +# include <sys/mount.h> #endif #ifdef HAVE_SYS_STATFS_H -#include <sys/statfs.h> +# include <sys/statfs.h> #endif #ifdef HAVE_SYS_VFS_H -#include <sys/vfs.h> +# include <sys/vfs.h> #endif -#include "support.h" -#include "opal/util/path.h" #include "opal/util/output.h" +#include "opal/util/path.h" #include "opal/util/printf.h" +#include "support.h" #define DEBUG @@ -65,15 +65,15 @@ */ #if !defined(__linux__) -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { if (argc > 1) { int i; printf("Interactive opal_path_nfs() test:\n"); for (i = 1; i < argc; i++) { - printf ("Is dir[%d]:%s one of the detected network file systems? %s\n", - i, argv[i], opal_path_nfs (argv[i], NULL) ? "Yes": "No"); + printf("Is dir[%d]:%s one of the detected network file systems? %s\n", i, argv[i], + opal_path_nfs(argv[i], NULL) ? "Yes" : "No"); } return 0; @@ -85,70 +85,67 @@ int main(int argc, char* argv[]) #else /* __linux__ */ -static void test(char* file, bool expect); -static void get_mounts (int * num_dirs, char ** dirs[], bool ** nfs); +static void test(char *file, bool expect); +static void get_mounts(int *num_dirs, char **dirs[], bool **nfs); - -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { int num_dirs; - char ** dirs; - bool * nfs; + char **dirs; + bool *nfs; test_init("opal_path_nfs()"); -#ifdef DEBUG - printf ("Test usage: ./opal_path_nfs [DIR]\n"); - printf ("On Linux interprets output from mount(8) to check for nfs and verify opal_path_nfs()\n"); - printf ("Additionally, you may specify multiple DIR on the cmd-line, of which you the output\n"); -#endif +# ifdef DEBUG + printf("Test usage: ./opal_path_nfs [DIR]\n"); + printf( + "On Linux interprets output from mount(8) to check for nfs and verify opal_path_nfs()\n"); + printf("Additionally, you may specify multiple DIR on the cmd-line, of which you the output\n"); +# endif if (1 < argc) { int i; for (i = 1; i < argc; i++) - printf ("Is dir[%d]:%s one of the detected network file systems? %s\n", - i, argv[i], opal_path_nfs (argv[i], NULL) ? "Yes": "No"); + printf("Is dir[%d]:%s one of the detected network file systems? %s\n", i, argv[i], + opal_path_nfs(argv[i], NULL) ? "Yes" : "No"); } - get_mounts (&num_dirs, &dirs, &nfs); + get_mounts(&num_dirs, &dirs, &nfs); while (num_dirs--) { - test (dirs[num_dirs], nfs[num_dirs]); + test(dirs[num_dirs], nfs[num_dirs]); } /* All done */ return test_finalize(); } - -void test(char* file, bool expect) +void test(char *file, bool expect) { -#ifdef DEBUG - printf ("test(): file:%s bool:%d\n", - file, expect); -#endif - if (expect == opal_path_nfs (file, NULL)) { +# ifdef DEBUG + printf("test(): file:%s bool:%d\n", file, expect); +# endif + if (expect == opal_path_nfs(file, NULL)) { test_success(); } else { - char * msg; - opal_asprintf(&msg, "Mismatch: input \"%s\", expected:%d got:%d\n", - file, expect, !expect); + char *msg; + opal_asprintf(&msg, "Mismatch: input \"%s\", expected:%d got:%d\n", file, expect, !expect); test_failure(msg); free(msg); } } -void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[]) +void get_mounts(int *num_dirs, char **dirs[], bool *nfs[]) { -#define SIZE 1024 - char * cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out"; +# define SIZE 1024 + char *cmd = "mount | cut -f3,5 -d' ' > opal_path_nfs.out"; int rc; int i; - FILE * file; - char ** dirs_tmp; - bool * nfs_tmp; + FILE *file; + char **dirs_tmp; + bool *nfs_tmp; char buffer[SIZE]; struct statfs mystatfs; - rc = system (cmd); + rc = system(cmd); if (-1 == rc) { *num_dirs = 0; @@ -164,7 +161,7 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[]) have an array large enough. */ file = fopen("opal_path_nfs.out", "r"); int count = 0; - while (NULL != fgets (buffer, SIZE, file)) { + while (NULL != fgets(buffer, SIZE, file)) { ++count; } printf("Found %d mounts\n", count); @@ -172,22 +169,22 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[]) // Add one more so we can have a NULL entry at the end ++count; - dirs_tmp = (char**) calloc (count, sizeof(char*)); - nfs_tmp = (bool*) calloc (count, sizeof(bool)); + dirs_tmp = (char **) calloc(count, sizeof(char *)); + nfs_tmp = (bool *) calloc(count, sizeof(bool)); i = 0; rc = 4711; rewind(file); // i should never be more than count, but be safe anyway. - while (i < count && NULL != fgets (buffer, SIZE, file)) { + while (i < count && NULL != fgets(buffer, SIZE, file)) { int mount_known; char fs[MAXNAMLEN]; if (!dirs_tmp[i]) { - dirs_tmp[i] = malloc (MAXNAMLEN); + dirs_tmp[i] = malloc(MAXNAMLEN); } - if (2 != (rc = sscanf (buffer, "%s %s\n", dirs_tmp[i], fs))) { + if (2 != (rc = sscanf(buffer, "%s %s\n", dirs_tmp[i], fs))) { goto out; } @@ -196,7 +193,7 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[]) * Cannot distinguish it from NFS in opal_path_nfs, therefore just * disregard it, as it is NOT an parallel filesystem... */ - if (0 == strcasecmp (fs, "rpc_pipefs")) { + if (0 == strcasecmp(fs, "rpc_pipefs")) { continue; } @@ -213,7 +210,7 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[]) } /* If we can not stat the fs, skip it */ - if (statfs (dirs_tmp[i], &mystatfs)) { + if (statfs(dirs_tmp[i], &mystatfs)) { continue; } @@ -223,31 +220,26 @@ void get_mounts (int * num_dirs, char ** dirs[], bool * nfs[]) */ for (mount_known = 0; mount_known < i; mount_known++) { /* If we know this mount-point, then exit early */ - if (0 == strcasecmp (dirs_tmp[mount_known], dirs_tmp[i])) { -#ifdef DEBUG - printf ("get_mounts: already know dir[%d]:%s\n", - mount_known, dirs_tmp[mount_known]); -#endif + if (0 == strcasecmp(dirs_tmp[mount_known], dirs_tmp[i])) { +# ifdef DEBUG + printf("get_mounts: already know dir[%d]:%s\n", mount_known, dirs_tmp[mount_known]); +# endif break; } } nfs_tmp[mount_known] = false; - if (0 == strcasecmp (fs, "nfs") || - 0 == strcasecmp (fs, "nfs4") || - 0 == strcasecmp (fs, "lustre") || - 0 == strcasecmp (fs, "panfs") || - 0 == strcasecmp (fs, "gpfs")) + if (0 == strcasecmp(fs, "nfs") || 0 == strcasecmp(fs, "nfs4") + || 0 == strcasecmp(fs, "lustre") || 0 == strcasecmp(fs, "panfs") + || 0 == strcasecmp(fs, "gpfs")) nfs_tmp[mount_known] = true; -#ifdef DEBUG - printf ("get_mounts: dirs[%d]:%s fs:%s nfs:%s\n", - mount_known, dirs_tmp[mount_known], - fs, nfs_tmp[mount_known] ? "Yes" : "No"); -#endif +# ifdef DEBUG + printf("get_mounts: dirs[%d]:%s fs:%s nfs:%s\n", mount_known, dirs_tmp[mount_known], fs, + nfs_tmp[mount_known] ? "Yes" : "No"); +# endif if (mount_known >= i) i++; - } out: *num_dirs = i; diff --git a/test/util/opal_timer.c b/test/util/opal_timer.c index 8873577453..d277861b21 100644 --- a/test/util/opal_timer.c +++ b/test/util/opal_timer.c @@ -20,11 +20,10 @@ #include <unistd.h> -#include "opal/runtime/opal.h" #include "opal/mca/timer/base/base.h" +#include "opal/runtime/opal.h" -int -main(int argc, char *argv[]) +int main(int argc, char *argv[]) { opal_timer_t start, end, diff; @@ -39,8 +38,7 @@ main(int argc, char *argv[]) sleep(1); end = opal_timer_base_get_cycles(); diff = end - start; - printf(" Slept approximately %llu cycles, or %llu us\n", - (unsigned long long) diff, + printf(" Slept approximately %llu cycles, or %llu us\n", (unsigned long long) diff, (unsigned long long) ((diff * 1000000) / opal_timer_base_get_freq())); #else printf("--> cycle count not supported\n"); diff --git a/test/util/orte_session_dir.c b/test/util/orte_session_dir.c index 7426989866..fb9152b5d5 100644 --- a/test/util/orte_session_dir.c +++ b/test/util/orte_session_dir.c @@ -19,116 +19,105 @@ #include "orte_config.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif /* HAVE_UNISTD_H */ +# include <unistd.h> +#endif /* HAVE_UNISTD_H */ #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> -#endif /* HAVE_SYS_PARAM_H */ +# include <sys/param.h> +#endif /* HAVE_SYS_PARAM_H */ #include <sys/stat.h> -#include "support.h" +#include "opal/util/os_path.h" #include "orte/constants.h" #include "orte/util/proc_info.h" -#include "opal/util/os_path.h" #include "orte/util/session_dir.h" -#include "orte/util/proc_info.h" - +#include "support.h" -static bool test1(void); /* given prefix, both one that works and one that fails */ -static bool test2(void); /* no prefix given, ORTE_PREFIX_ENV set, one good and one bad */ -static bool test3(void); /* no prefix given, TMPDIR set, one good and one bad */ -static bool test4(void); /* no prefix given, TMP set, one good and one bad */ -static bool test5(void); /* no prefix given, HOME set, one good and one bad */ -static bool test6(void); /* no prefix given, nothing set, one good and one bad */ -static bool test7(void); /* remove session directory tree */ -static bool test8(void); /* attempt to remove tree when subdirs present */ +static bool test1(void); /* given prefix, both one that works and one that fails */ +static bool test2(void); /* no prefix given, ORTE_PREFIX_ENV set, one good and one bad */ +static bool test3(void); /* no prefix given, TMPDIR set, one good and one bad */ +static bool test4(void); /* no prefix given, TMP set, one good and one bad */ +static bool test5(void); /* no prefix given, HOME set, one good and one bad */ +static bool test6(void); /* no prefix given, nothing set, one good and one bad */ +static bool test7(void); /* remove session directory tree */ +static bool test8(void); /* attempt to remove tree when subdirs present */ void clear_proc_info(void); -static FILE *test_out=NULL; +static FILE *test_out = NULL; -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { orte_proc_info(); /* initialize proc info structure */ - orte_process_info.my_name = (orte_process_name_t*)malloc(sizeof(orte_process_name_t)); + orte_process_info.my_name = (orte_process_name_t *) malloc(sizeof(orte_process_name_t)); orte_process_info.my_name->cellid = 0; orte_process_info.my_name->jobid = 0; orte_process_info.my_name->vpid = 0; test_init("orte_session_dir_t"); - test_out = fopen( "test_session_dir_out", "w+" ); - if( test_out == NULL ) { - test_failure("test_session_dir couldn't open test file failed"); - test_finalize(); - exit(1); + test_out = fopen("test_session_dir_out", "w+"); + if (test_out == NULL) { + test_failure("test_session_dir couldn't open test file failed"); + test_finalize(); + exit(1); } - fprintf(test_out, "running test1\n"); if (test1()) { test_success(); - } - else { - test_failure("orte_session_dir_t test1 failed"); + } else { + test_failure("orte_session_dir_t test1 failed"); } fprintf(test_out, "running test2\n"); if (test2()) { test_success(); - } - else { - test_failure("orte_session_dir_t test2 failed"); + } else { + test_failure("orte_session_dir_t test2 failed"); } fprintf(test_out, "running test3\n"); if (test3()) { test_success(); - } - else { - test_failure("orte_session_dir_t test3 failed"); + } else { + test_failure("orte_session_dir_t test3 failed"); } fprintf(test_out, "running test4\n"); if (test4()) { test_success(); - } - else { - test_failure("orte_session_dir_t test4 failed"); + } else { + test_failure("orte_session_dir_t test4 failed"); } fprintf(test_out, "running test5\n"); if (test5()) { test_success(); - } - else { - test_failure("orte_session_dir_t test5 failed"); + } else { + test_failure("orte_session_dir_t test5 failed"); } fprintf(test_out, "running test6\n"); if (test6()) { test_success(); - } - else { - test_failure("orte_session_dir_t test6 failed"); + } else { + test_failure("orte_session_dir_t test6 failed"); } fprintf(test_out, "running test7\n"); if (test7()) { test_success(); - } - else { - test_failure("orte_session_dir_t test7 failed"); + } else { + test_failure("orte_session_dir_t test7 failed"); } fprintf(test_out, "running test8\n"); if (test8()) { test_success(); - } - else { - test_failure("orte_session_dir_t test8 failed"); + } else { + test_failure("orte_session_dir_t test8 failed"); } fprintf(test_out, "completed all tests\n"); @@ -142,7 +131,6 @@ int main(int argc, char* argv[]) return 0; } - static bool test1(void) { /* Test proper action when given a prefix */ @@ -155,16 +143,16 @@ static bool test1(void) prefix = opal_os_path(false, "tmp", NULL); if (ORTE_SUCCESS != orte_session_dir(true, prefix, NULL, NULL, "test-universe", NULL, NULL)) { - fprintf(test_out, "test1 - couldn't create specified path\n"); + fprintf(test_out, "test1 - couldn't create specified path\n"); free(prefix); - return(false); + return false; } /* see if it can access an existing path */ if (ORTE_SUCCESS != orte_session_dir(false, prefix, NULL, NULL, "test-universe", NULL, NULL)) { - fprintf(test_out, "test1 - couldn't access existing path\n"); + fprintf(test_out, "test1 - couldn't access existing path\n"); free(prefix); - return(false); + return false; } orte_session_dir_finalize(orte_process_info.my_name); @@ -174,7 +162,6 @@ static bool test1(void) return true; } - static bool test2(void) { clear_proc_info(); @@ -184,19 +171,17 @@ static bool test2(void) setenv("OMPI_PREFIX_ENV", "/tmp/trythis", 1); if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) { - unsetenv("OMPI_PREFIX_ENV"); - return(false); + unsetenv("OMPI_PREFIX_ENV"); + return false; } orte_session_dir_finalize(orte_process_info.my_name); unsetenv("OMPI_PREFIX_ENV"); - return(true); - + return true; } - static bool test3(void) { /* use the TMPDIR enviro variable */ @@ -205,18 +190,17 @@ static bool test3(void) setenv("TMPDIR", "/tmp/trythis", 1); if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) { - unsetenv("TMPDIR"); - return(false); + unsetenv("TMPDIR"); + return false; } orte_session_dir_finalize(orte_process_info.my_name); unsetenv("TMPDIR"); - return(true); + return true; } - static bool test4(void) { /* use the TMP enviro variable */ @@ -226,18 +210,17 @@ static bool test4(void) setenv("TMP", "/tmp/trythis", 1); if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) { - unsetenv("TMP"); - return(false); + unsetenv("TMP"); + return false; } orte_session_dir_finalize(orte_process_info.my_name); unsetenv("TMP"); - return(true); + return true; } - static bool test5(void) { /* use the HOME enviro variable */ @@ -247,34 +230,33 @@ static bool test5(void) setenv("HOME", "/tmp/trythis", 1); if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) { - unsetenv("HOME"); - return(false); + unsetenv("HOME"); + return false; } orte_session_dir_finalize(orte_process_info.my_name); unsetenv("HOME"); - return(true); + return true; } - static bool test6(void) { clear_proc_info(); /* no enviro variables set, no prefix given - * Program should turn to default of /tmp (where "/" is whatever - * top-level directory is appropriate for given system) - */ + * Program should turn to default of /tmp (where "/" is whatever + * top-level directory is appropriate for given system) + */ if (ORTE_SUCCESS != orte_session_dir(true, NULL, NULL, NULL, "test-universe", NULL, NULL)) { - return(false); + return false; } orte_session_dir_finalize(orte_process_info.my_name); - return(true); + return true; } static bool test7(void) @@ -286,14 +268,14 @@ static bool test7(void) clear_proc_info(); /* create test proc session directory tree */ - if (ORTE_SUCCESS != orte_session_dir(true, NULL, "localhost", NULL, "test-universe", "test-job", "test-proc")) { - return(false); + if (ORTE_SUCCESS + != orte_session_dir(true, NULL, "localhost", NULL, "test-universe", "test-job", + "test-proc")) { + return false; } - fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n", - orte_process_info.proc_session_dir, - orte_process_info.job_session_dir, - orte_process_info.universe_session_dir); + fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n", orte_process_info.proc_session_dir, + orte_process_info.job_session_dir, orte_process_info.universe_session_dir); /* create some files */ @@ -313,10 +295,11 @@ static bool test7(void) fclose(fp); if (ORTE_SUCCESS != orte_session_dir_finalize(orte_process_info.my_name)) { - return(false); + return false; } - for (i=0; i < 3; i++) unlink(filenm[i]); + for (i = 0; i < 3; i++) + unlink(filenm[i]); orte_session_dir_finalize(orte_process_info.my_name); return true; @@ -331,14 +314,14 @@ static bool test8(void) clear_proc_info(); /* create test proc session directory tree */ - if (ORTE_SUCCESS != orte_session_dir(true, NULL, "localhost", NULL, "test-universe2", "test-job2", "test-proc2")) { - return(false); + if (ORTE_SUCCESS + != orte_session_dir(true, NULL, "localhost", NULL, "test-universe2", "test-job2", + "test-proc2")) { + return false; } - fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n", - orte_process_info.proc_session_dir, - orte_process_info.job_session_dir, - orte_process_info.universe_session_dir); + fprintf(test_out, "removing directories: %s\n\t%s\n\t%s\n", orte_process_info.proc_session_dir, + orte_process_info.job_session_dir, orte_process_info.universe_session_dir); /* create some files */ @@ -357,12 +340,12 @@ static bool test8(void) fprintf(fp, "ss"); fclose(fp); - if (ORTE_SUCCESS != orte_session_dir_finalize(orte_process_info.my_name)) { - return(false); + return false; } - for (i=0; i < 3; i++) unlink(filenm[i]); + for (i = 0; i < 3; i++) + unlink(filenm[i]); orte_session_dir_finalize(orte_process_info.my_name); return true; @@ -375,5 +358,4 @@ void clear_proc_info(void) orte_process_info.universe_session_dir = NULL; orte_process_info.job_session_dir = NULL; orte_process_info.proc_session_dir = NULL; - } diff --git a/test/util/orte_universe_setup_file_io.c b/test/util/orte_universe_setup_file_io.c index a25a082121..223d0a29f3 100644 --- a/test/util/orte_universe_setup_file_io.c +++ b/test/util/orte_universe_setup_file_io.c @@ -20,22 +20,22 @@ #include "orte/constants.h" #include <stdio.h> -#include <string.h> #include <stdlib.h> +#include <string.h> #ifdef HAVE_SYS_PARAM_H -#include <sys/param.h> +# include <sys/param.h> #endif #include "orte/util/univ_info.h" #include "orte/util/universe_setup_file_io.h" #include "support.h" -static bool test1(void); /* verify it returns info */ -static bool test2(void); /* test second time through */ +static bool test1(void); /* verify it returns info */ +static bool test2(void); /* test second time through */ orte_universe_t orte_universe_info; -int main(int argc, char* argv[]) +int main(int argc, char *argv[]) { test_init("universe_setup_file_io"); @@ -52,23 +52,20 @@ int main(int argc, char* argv[]) if (test1()) { test_success(); - } - else { - test_failure("universe_setup_file_io write failed"); + } else { + test_failure("universe_setup_file_io write failed"); } if (test2()) { test_success(); - } - else { - test_failure("universe_setup_file_io read failed"); + } else { + test_failure("universe_setup_file_io read failed"); } test_finalize(); return 0; } - static bool test1(void) { int rc; @@ -83,7 +80,6 @@ static bool test1(void) return true; } - static bool test2(void) { int rc; @@ -96,15 +92,15 @@ static bool test2(void) return false; } - if (0 != strcmp(orte_universe_info.name, univ.name) || - 0 != strcmp(orte_universe_info.host, univ.host) || - 0 != strcmp(orte_universe_info.uid, univ.uid) || - orte_universe_info.persistence != univ.persistence || - 0 != strcmp(orte_universe_info.scope, univ.scope) || - orte_universe_info.console != univ.console || - 0 != strcmp(orte_universe_info.seed_uri, univ.seed_uri) || - orte_universe_info.console_connected != univ.console_connected || - orte_universe_info.scriptfile != univ.scriptfile) { + if (0 != strcmp(orte_universe_info.name, univ.name) + || 0 != strcmp(orte_universe_info.host, univ.host) + || 0 != strcmp(orte_universe_info.uid, univ.uid) + || orte_universe_info.persistence != univ.persistence + || 0 != strcmp(orte_universe_info.scope, univ.scope) + || orte_universe_info.console != univ.console + || 0 != strcmp(orte_universe_info.seed_uri, univ.seed_uri) + || orte_universe_info.console_connected != univ.console_connected + || orte_universe_info.scriptfile != univ.scriptfile) { fprintf(stderr, "universe_setup_file_io: read mismatch\n"); return false; } -- GitLab