| | |
| | | #include <netinet/in.h> /* needed for sockaddr_in */ |
| | | #include <netdb.h> |
| | | #include <pthread.h> |
| | | #include <time.h> |
| | | |
| | | #include "mini_blas.h" |
| | | #include "utils.h" |
| | |
| | | { |
| | | connection_info info = *(connection_info *) pointer; |
| | | free(pointer); |
| | | printf("New Connection\n"); |
| | | //printf("New Connection\n"); |
| | | int fd = info.fd; |
| | | network net = info.net; |
| | | int i; |
| | |
| | | write_all(fd, (char *)layer.weights, layer.outputs*layer.inputs*sizeof(float)); |
| | | } |
| | | } |
| | | printf("Received updates\n"); |
| | | //printf("Received updates\n"); |
| | | close(fd); |
| | | } |
| | | |
| | |
| | | listen(fd, 10); |
| | | struct sockaddr_in client; /* remote address */ |
| | | socklen_t client_size = sizeof(client); /* length of addresses */ |
| | | 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); |
| | | 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) |