Browse Source

benchmarks

kaikas 7 years ago
parent
commit
abb9c304c4

+ 10 - 0
benchmarks/mpi/makefile

@@ -0,0 +1,10 @@
+EXECS=send_recv 
+MPICC?=mpicc
+
+all: ${EXECS}
+
+send_recv: send_recv.c
+	${MPICC} -o send_recv send_recv.c
+
+clean:
+	rm -f ${EXECS}

+ 1 - 0
benchmarks/mpi/readme.txt

@@ -0,0 +1 @@
+mpirun -n 2 ./send_recv 1 100000

BIN
benchmarks/mpi/send_recv


+ 62 - 0
benchmarks/mpi/send_recv.c

@@ -0,0 +1,62 @@
+#include <mpi.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+int main (int argc, char *argv []) {
+	int message_size = atoi (argv [1]);
+	int message_count = atoi (argv [2]);
+  unsigned long throughput;
+  double megabits;
+
+	// Initialize the MPI environment
+	MPI_Init(NULL, NULL);
+	// Find out rank, size
+	int world_rank;
+	MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
+	int world_size;
+	MPI_Comm_size(MPI_COMM_WORLD, &world_size);
+
+	if (world_size < 2) {
+		fprintf(stderr, "World size must be greater than 1 for %s\n", argv[0]);
+		MPI_Abort(MPI_COMM_WORLD, 1);
+	}
+
+	int data[message_size];
+
+  clock_t start, end;
+  long double elapsed;
+  start = clock();
+  
+	for (int i = 0; i != message_count; i++) {
+		if (world_rank == 0) {
+			data[0] = 1234;
+			MPI_Send(data, message_size, MPI_INT, 1, 0, MPI_COMM_WORLD);
+		} else if (world_rank == 1) {
+			MPI_Recv(data, message_size, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
+		}
+	}
+	
+	end = clock();
+	
+	if (world_rank == 1) {
+  	elapsed = end - start;
+    if (elapsed == 0)
+        elapsed = 1;
+  	
+  	throughput = (unsigned long)
+        ((double) message_count / (double) elapsed * 1000000);
+    megabits = ((double) throughput * message_size * 8) / 1000000;
+
+  	
+  	printf("message size: %d [B]\n", message_size);
+  	printf("message count: %d [B]\n", message_count);
+  	printf("mean throughput: %d [msg/s]\n", (int)throughput);
+  	printf("mean throughput: %.3f [Mb/s]\n", (double)megabits);
+
+	}
+
+	MPI_Finalize();
+	
+}

+ 13 - 0
benchmarks/zeromq/makefile

@@ -0,0 +1,13 @@
+EXECS=send receive
+MPICC?=mpicc
+
+all: ${EXECS}
+
+send: send.cpp
+	gcc -o send send.cpp -lzmq
+
+receive: receive.cpp
+	gcc -o receive receive.cpp -lzmq
+
+clean:
+	rm -f ${EXECS}

+ 3 - 0
benchmarks/zeromq/readme.txt

@@ -0,0 +1,3 @@
+./send tcp://enp0s3:5555 1 100000
+./receive tcp://192.168.0.35:5555 1 100000
+

BIN
benchmarks/zeromq/receive


+ 107 - 0
benchmarks/zeromq/receive.cpp

@@ -0,0 +1,107 @@
+/*
+    Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
+
+    This file is part of libzmq, the ZeroMQ core engine in C++.
+
+    libzmq is free software; you can redistribute it and/or modify it under
+    the terms of the GNU Lesser General Public License (LGPL) as published
+    by the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    As a special exception, the Contributors give you permission to link
+    this library with independent modules to produce an executable,
+    regardless of the license terms of these independent modules, and to
+    copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the
+    terms and conditions of the license of that module. An independent
+    module is a module which is not derived from or based on this library.
+    If you modify this library, you must extend this exception to your
+    version of the library.
+
+    libzmq is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+    License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <zmq.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main (int argc, char *argv [])
+{
+    const char *connect_to;
+    int message_count;
+    int message_size;
+    void *ctx;
+    void *s;
+    int rc;
+    int i;
+    zmq_msg_t msg;
+
+    if (argc != 4) {
+        printf ("usage: remote_thr <connect-to> <message-size> "
+            "<message-count>\n");
+        return 1;
+    }
+    connect_to = argv [1];
+    message_size = atoi (argv [2]);
+    message_count = atoi (argv [3]);
+
+    ctx = zmq_init (1);
+    if (!ctx) {
+        printf ("error in zmq_init: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    s = zmq_socket (ctx, ZMQ_PUSH);
+    if (!s) {
+        printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    //  Add your socket options here.
+    //  For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
+
+    rc = zmq_connect (s, connect_to);
+    if (rc != 0) {
+        printf ("error in zmq_connect: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    for (i = 0; i != message_count; i++) {
+        rc = zmq_msg_init_size (&msg, message_size);
+        if (rc != 0) {
+            printf ("error in zmq_msg_init_size: %s\n", zmq_strerror (errno));
+            return -1;
+        }
+        rc = zmq_sendmsg (s, &msg, 0);
+        if (rc < 0) {
+            printf ("error in zmq_sendmsg: %s\n", zmq_strerror (errno));
+            return -1;
+        }
+        rc = zmq_msg_close (&msg);
+        if (rc != 0) {
+            printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
+            return -1;
+        }
+    }
+
+    rc = zmq_close (s);
+    if (rc != 0) {
+        printf ("error in zmq_close: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    rc = zmq_ctx_term (ctx);
+    if (rc != 0) {
+        printf ("error in zmq_ctx_term: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    return 0;
+}

BIN
benchmarks/zeromq/send


+ 140 - 0
benchmarks/zeromq/send.cpp

@@ -0,0 +1,140 @@
+/*
+    Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
+
+    This file is part of libzmq, the ZeroMQ core engine in C++.
+
+    libzmq is free software; you can redistribute it and/or modify it under
+    the terms of the GNU Lesser General Public License (LGPL) as published
+    by the Free Software Foundation; either version 3 of the License, or
+    (at your option) any later version.
+
+    As a special exception, the Contributors give you permission to link
+    this library with independent modules to produce an executable,
+    regardless of the license terms of these independent modules, and to
+    copy and distribute the resulting executable under terms of your choice,
+    provided that you also meet, for each linked independent module, the
+    terms and conditions of the license of that module. An independent
+    module is a module which is not derived from or based on this library.
+    If you modify this library, you must extend this exception to your
+    version of the library.
+
+    libzmq is distributed in the hope that it will be useful, but WITHOUT
+    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+    FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+    License for more details.
+
+    You should have received a copy of the GNU Lesser General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <zmq.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main (int argc, char *argv [])
+{
+    const char *bind_to;
+    int message_count;
+    size_t message_size;
+    void *ctx;
+    void *s;
+    int rc;
+    int i;
+    zmq_msg_t msg;
+    void *watch;
+    unsigned long elapsed;
+    unsigned long throughput;
+    double megabits;
+
+    if (argc != 4) {
+        printf ("usage: local_thr <bind-to> <message-size> <message-count>\n");
+        return 1;
+    }
+    bind_to = argv [1];
+    message_size = atoi (argv [2]);
+    message_count = atoi (argv [3]);
+
+    ctx = zmq_init (1);
+    if (!ctx) {
+        printf ("error in zmq_init: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    s = zmq_socket (ctx, ZMQ_PULL);
+    if (!s) {
+        printf ("error in zmq_socket: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    //  Add your socket options here.
+    //  For example ZMQ_RATE, ZMQ_RECOVERY_IVL and ZMQ_MCAST_LOOP for PGM.
+
+    rc = zmq_bind (s, bind_to);
+    if (rc != 0) {
+        printf ("error in zmq_bind: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    rc = zmq_msg_init (&msg);
+    if (rc != 0) {
+        printf ("error in zmq_msg_init: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    rc = zmq_recvmsg (s, &msg, 0);
+    if (rc < 0) {
+        printf ("error in zmq_recvmsg: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+    if (zmq_msg_size (&msg) != message_size) {
+        printf ("message of incorrect size received\n");
+        return -1;
+    }
+
+    watch = zmq_stopwatch_start ();
+
+    for (i = 0; i != message_count - 1; i++) {
+        rc = zmq_recvmsg (s, &msg, 0);
+        if (rc < 0) {
+            printf ("error in zmq_recvmsg: %s\n", zmq_strerror (errno));
+            return -1;
+        }
+        if (zmq_msg_size (&msg) != message_size) {
+            printf ("message of incorrect size received\n");
+            return -1;
+        }
+    }
+
+    elapsed = zmq_stopwatch_stop (watch);
+    if (elapsed == 0)
+        elapsed = 1;
+
+    rc = zmq_msg_close (&msg);
+    if (rc != 0) {
+        printf ("error in zmq_msg_close: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    throughput = (unsigned long)
+        ((double) message_count / (double) elapsed * 1000000);
+    megabits = ((double) throughput * message_size * 8) / 1000000;
+
+    printf ("message size: %d [B]\n", (int) message_size);
+    printf ("message count: %d\n", (int) message_count);
+    printf ("mean throughput: %d [msg/s]\n", (int) throughput);
+    printf ("mean throughput: %.3f [Mb/s]\n", (double) megabits);
+
+    rc = zmq_close (s);
+    if (rc != 0) {
+        printf ("error in zmq_close: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    rc = zmq_ctx_term (ctx);
+    if (rc != 0) {
+        printf ("error in zmq_ctx_term: %s\n", zmq_strerror (errno));
+        return -1;
+    }
+
+    return 0;
+}