Skip to content
Snippets Groups Projects
Unverified Commit aff9498a authored by Geoffrey Paulsen's avatar Geoffrey Paulsen Committed by GitHub
Browse files

Merge pull request #8886 from hjelmn/format-others

examples/test: format using clang-format
parents 02b20108 669c0dc7
No related branches found
No related tags found
No related merge requests found
Showing
with 563 additions and 583 deletions
......@@ -7,15 +7,14 @@
*/
#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;
......@@ -46,8 +45,7 @@ main(int argc, char **argv)
/* rank i sends to and receives from each higher rank */
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);
}
......
......@@ -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,8 +23,7 @@ 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 */
......@@ -49,13 +48,15 @@ main(int argc, char *argv[])
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);
}
......@@ -7,8 +7,8 @@
* Sample MPI "hello world" application in C
*/
#include <stdio.h>
#include "mpi.h"
#include <stdio.h>
int main(int argc, char *argv[])
{
......@@ -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;
......
......@@ -9,8 +9,8 @@
* $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
......@@ -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;
......
......@@ -8,8 +8,8 @@
* $HEADER$
*/
#include <stdio.h>
#include <shmem.h>
#include <stdio.h>
int main(void)
{
......@@ -32,4 +32,3 @@ int main (void)
return 0;
}
......@@ -56,4 +56,3 @@ int main(void)
return 0;
}
......@@ -27,4 +27,3 @@ int main(void)
shmem_finalize();
}
......@@ -24,8 +24,8 @@
*
*/
#include <stdio.h>
#include <shmem.h>
#include <stdio.h>
int main(void)
{
......@@ -44,8 +44,7 @@ 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],
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 */
......
......@@ -8,8 +8,8 @@
* $HEADER$
*/
#include <stdio.h>
#include <shmem.h>
#include <stdio.h>
#define SIZE 16
......
......@@ -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 */
......
......@@ -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);
}
......
......@@ -40,14 +40,16 @@ 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");
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;
......@@ -73,9 +75,8 @@ int main(int argc, char **argv)
MPI_T_pvar_get_num(&num);
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);
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) {
......
......@@ -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
}
......@@ -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;
......@@ -99,7 +97,6 @@ int main(int argc, char *argv[])
}
nthreads = atoi(argv[1]);
/* first test single-threaded functionality */
/* -- cmpset 32-bit tests -- */
......@@ -226,7 +223,6 @@ int main(int argc, char *argv[])
assert(volint == 42);
assert(oldint == 42);
/* -- cmpset ptr tests -- */
volptr = 42, oldptr = 42, newptr = 50;
......@@ -282,7 +278,6 @@ int main(int argc, char *argv[])
opal_atomic_rmb();
assert((42 + 5) == valint);
/* threaded tests */
val32 = 0;
......
......@@ -25,8 +25,8 @@
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include "opal/sys/atomic.h"
......@@ -50,9 +50,7 @@ static void* atomic_math_test(void* arg)
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;
......@@ -109,140 +104,167 @@ main(int argc, char *argv[])
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
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",
......
......@@ -25,8 +25,8 @@
#ifdef HAVE_PTHREAD_H
# include <pthread.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include "opal/sys/atomic.h"
......@@ -46,21 +46,25 @@ static void* atomic_spinlock_start(void* 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) {
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;
......
......@@ -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,7 +42,6 @@ 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) {
/**
......@@ -71,10 +68,12 @@ main(int argc, char* argv[])
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);
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);
......@@ -102,10 +101,12 @@ main(int argc, char* argv[])
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);
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);
......@@ -133,10 +134,12 @@ main(int argc, char* argv[])
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);
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);
......@@ -164,19 +167,18 @@ main(int argc, char* argv[])
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);
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);
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
......@@ -27,20 +27,16 @@
#else
# 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
};
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);
void test1(void);
......@@ -61,29 +57,26 @@ int comp_fn(void * ele1, void * ele2)
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;
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;
......@@ -124,14 +117,11 @@ void test_keys(void)
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);
}
}
}
......@@ -272,15 +262,13 @@ void test2(void);
/* the number of memory segments to allocate */
#define NUM_ALLOCATIONS 500
struct opal_test_rb_key_t
{
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];
......@@ -292,14 +280,9 @@ OBJ_CLASS_INSTANCE(opal_test_rb_value_t, opal_free_list_item_t, NULL, NULL);
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;
......@@ -317,11 +300,9 @@ void test2(void)
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);
......@@ -330,51 +311,40 @@ void test2(void)
}
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)
{
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)->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)
{
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,10 +358,8 @@ 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]);
......
......@@ -4,8 +4,8 @@
#include "opal_config.h"
#include <stdio.h>
#include "support.h"
#include <stdio.h>
#include "opal/class/opal_bitmap.h"
#include "opal/constants.h"
......@@ -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);
......@@ -54,7 +53,8 @@ int main(int argc, char *argv[])
error_out = stderr;
#else
error_out = fopen("./opal_bitmap_test_out.txt", "w");
if( error_out == NULL ) error_out = stderr;
if (error_out == NULL)
error_out = stderr;
#endif
/* Initialize bitmap */
......@@ -103,9 +103,8 @@ int main(int argc, char *argv[])
return 0;
}
void test_bitmap_set(opal_bitmap_t *bm) {
void test_bitmap_set(opal_bitmap_t *bm)
{
int result = 0;
/* start of bitmap and boundaries */
......@@ -130,8 +129,8 @@ void test_bitmap_set(opal_bitmap_t *bm) {
TEST_AND_REPORT(result, ERR_CODE, "opal_bitmap_set_bit");
}
void test_bitmap_clear(opal_bitmap_t *bm) {
void test_bitmap_clear(opal_bitmap_t *bm)
{
int result = 0;
/* Valid set bits */
......@@ -150,7 +149,6 @@ void test_bitmap_clear(opal_bitmap_t *bm) {
TEST_AND_REPORT(result, ERR_CODE, "opal_bitmap_clear_bit");
}
void test_bitmap_is_set(opal_bitmap_t *bm)
{
int result = 0;
......@@ -170,7 +168,6 @@ void test_bitmap_is_set(opal_bitmap_t *bm)
TEST_AND_REPORT(result, 0, "opal_bitmap_is_set_bit");
}
void test_bitmap_find_and_set(opal_bitmap_t *bm)
{
int bsize;
......@@ -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);
......@@ -230,7 +226,6 @@ int set_bit(opal_bitmap_t *bm, int bit)
return 0;
}
int clear_bit(opal_bitmap_t *bm, int bit)
{
int err = opal_bitmap_clear_bit(bm, bit);
......@@ -242,7 +237,6 @@ int clear_bit(opal_bitmap_t *bm, int bit)
return 0;
}
int is_set_bit(opal_bitmap_t *bm, int bit)
{
bool result = opal_bitmap_is_set_bit(bm, bit);
......@@ -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);
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;
......@@ -294,14 +286,12 @@ int clear_all(opal_bitmap_t *bm)
}
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);
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;
......@@ -316,7 +306,6 @@ int set_all(opal_bitmap_t *bm)
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;
......
......@@ -13,15 +13,15 @@
#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>
......@@ -42,7 +42,8 @@
} 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;
......@@ -68,7 +69,8 @@ static void *thread_test (opal_object_t *arg) {
return NULL;
}
static void *thread_test_exhaust (opal_object_t *arg) {
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];
......@@ -99,8 +101,10 @@ static void *thread_test_exhaust (opal_object_t *arg) {
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;
}
......@@ -110,13 +114,15 @@ static bool check_fifo_consistency (opal_fifo_t *fifo, int expected_count)
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;
......@@ -211,7 +217,8 @@ int main (int argc, char *argv[]) {
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();
......@@ -220,8 +227,8 @@ int main (int argc, char *argv[]) {
}
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));
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) {
......@@ -240,16 +247,19 @@ int main (int argc, char *argv[]) {
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();
} 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));
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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment