From aea3bceeb16e553ff75a2f28c7f44f04b81513d7 Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Mon, 08 Dec 2014 20:11:04 +0000
Subject: [PATCH] timing code

---
 src/server.c |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/server.c b/src/server.c
index 657ea7c..70f1889 100644
--- a/src/server.c
+++ b/src/server.c
@@ -6,6 +6,7 @@
 #include <netinet/in.h> /* needed for sockaddr_in */
 #include <netdb.h>
 #include <pthread.h>
+#include <time.h>
 
 #include "mini_blas.h"
 #include "utils.h"
@@ -51,20 +52,22 @@
 
 void read_all(int fd, char *buffer, size_t bytes)
 {
+    //printf("Want %d\n", bytes);
     size_t n = 0;
     while(n < bytes){
         int next = read(fd, buffer + n, bytes-n);
-        if(next < 0) error("read failed");
+        if(next <= 0) error("read failed");
         n += next;
     }
 }
 
 void write_all(int fd, char *buffer, size_t bytes)
 {
+    //printf("Writ %d\n", bytes);
     size_t n = 0;
     while(n < bytes){
         int next = write(fd, buffer + n, bytes-n);
-        if(next < 0) error("write failed");
+        if(next <= 0) error("write failed");
         n += next;
     }
 }
@@ -79,8 +82,9 @@
 
 void handle_connection(void *pointer)
 {
-    printf("New Connection\n");
     connection_info info = *(connection_info *) pointer;
+    free(pointer);
+    //printf("New Connection\n");
     int fd = info.fd;
     network net = info.net;
     int i;
@@ -115,10 +119,8 @@
             write_all(fd, (char *)layer.weights, layer.outputs*layer.inputs*sizeof(float));
         }
     }
-    printf("Received updates\n");
+    //printf("Received updates\n");
     close(fd);
-    ++*(info.counter);
-    if(*(info.counter)%10==0) save_network(net, "/home/pjreddie/imagenet_backup/alexnet.part");
 }
 
 void server_update(network net)
@@ -128,15 +130,23 @@
     listen(fd, 10);
     struct sockaddr_in client;     /* remote address */
     socklen_t client_size = sizeof(client);   /* length of addresses */
-    connection_info info;
-    info.net = net;
-    info.counter = &counter;
+    time_t t=0;
     while(1){
+        connection_info *info = calloc(1, sizeof(connection_info));
+        info->net = net;
+        info->counter = &counter;
         pthread_t worker;
         int connection = accept(fd, (struct sockaddr *) &client, &client_size);
-        info.fd = connection;
-        pthread_create(&worker, NULL, (void *) &handle_connection, &info);
+        if(!t) t=time(0);
+        info->fd = connection;
+        pthread_create(&worker, NULL, (void *) &handle_connection, info);
+        ++counter;
+        printf("%d\n", counter);
+        if(counter == 1024) break;
+        if(counter%1000==0) save_network(net, "cfg/nist.part");
     }
+    printf("1024 epochs: %d seconds\n", time(0)-t);
+    close(fd);
 }
 
 void client_update(network net, char *address)
@@ -166,6 +176,7 @@
 
     /* send a message to the server */
     int i;
+    //printf("Sending\n");
     for(i = 0; i < net.n; ++i){
         if(net.types[i] == CONVOLUTIONAL){
             convolutional_layer layer = *(convolutional_layer *) net.layers[i];
@@ -183,6 +194,7 @@
             memset(layer.weight_updates, 0, layer.inputs*layer.outputs*sizeof(float));
         }
     }
+    //printf("Sent\n");
 
     for(i = 0; i < net.n; ++i){
         if(net.types[i] == CONVOLUTIONAL){
@@ -203,5 +215,6 @@
             push_connected_layer(layer);
         }
     }
+    //printf("Updated\n");
     close(fd);
 }

--
Gitblit v1.10.0