Commit 6e4646a7 authored by Joseph Pallamidessi's avatar Joseph Pallamidessi

Merge branch 'devel', thus adding the networking

and memory leak fixes (#6) by @pallamidessi and @lukhio
parents 8bf4db08 53686f45
......@@ -164,8 +164,8 @@ void CSymbol::print(FILE *fp)
fprintf(fp," cudaMemcpy(ret,dev_ptr,sizeof(%s),cudaMemcpyDeviceToHost);\n",sName);
//while (pSym=pSymbolList->walkToNextItem())
//fprintf(fp," this->%s=ret->%s;\n",pSym->Object->sName,pSym->Object->sName);
fprintf(fp," }\n\n");
}
fprintf(fp," }\n\n");
}
// creation of class constructor
......
......@@ -54,10 +54,11 @@ void * CComUDPServer::UDP_server_thread(void *parm) {
printf(" Received individual from %s:%d\n", inet_ntoa(cliaddr.sin_addr), ntohs(cliaddr.sin_port));
pthread_mutex_lock(&server_mutex);
/*process received data */
memmove(p->data[(*p->nb_data)].data,buffer,sizeof(char)*MAXINDSIZE);
(*p->nb_data)++;
recv_data buffer_copy;
memmove(buffer_copy.data,buffer,sizeof(char)*MAXINDSIZE);
// printf("address %p\n",(p->data));
p->data = (RECV_DATA*)realloc(p->data,sizeof(RECV_DATA)*((*p->nb_data)+1));
p->data->push_back(buffer_copy);
(*p->nb_data)++;
// printf("address %p\n",(p->data));
pthread_mutex_unlock(&server_mutex);
/*reset receiving buffer*/
......@@ -71,7 +72,6 @@ CComUDPServer::CComUDPServer(unsigned short port,int dg) {
struct sockaddr_in ServAddr; /* Local address */
debug = dg;
this->nb_data = 0;
this->data = (RECV_DATA*)calloc(1,sizeof(RECV_DATA));
#ifdef WIN32
WSADATA wsadata;
if (WSAStartup(MAKEWORD(1,1), &wsadata) == SOCKET_ERROR) {
......@@ -108,7 +108,7 @@ CComUDPServer::CComUDPServer(unsigned short port,int dg) {
this->parm->Socket = ServerSocket;
this->parm->ServAddr = ServAddr;
this->parm->nb_data = &this->nb_data;
this->parm->data = this->data;
this->parm->data = new std::vector<recv_data>;
this->parm->debug = this->debug;
if(pthread_create(&thread, NULL, &CComUDPServer::UDP_server_thread, (void *)this->parm) != 0) {
......
......@@ -535,13 +535,13 @@ void CEvolutionaryAlgorithm::sendIndividual(){
void CEvolutionaryAlgorithm::receiveIndividuals(){
//Checking every generation for received individuals
if(this->treatedIndividuals<(unsigned)this->server->nb_data){
if(this->server->parm->data->size() != 0){
//cout << "number of received individuals :" << this->server->nb_data << endl;
//cout << "number of treated individuals :" << this->treatedIndividuals << endl;
CSelectionOperator *antiTournament = getSelectionOperator("Tournament",!this->params->minimizing, globalRandomGenerator);
//Treating all the individuals before continuing
while(this->treatedIndividuals < (unsigned)this->server->nb_data){
while(this->server->parm->data->size() != 0){
//selecting the individual to erase
antiTournament->initialize(this->population->parents, 7, this->population->actualParentPopulationSize);
unsigned index = antiTournament->selectNext(this->population->actualParentPopulationSize);
......@@ -552,14 +552,14 @@ void CEvolutionaryAlgorithm::receiveIndividuals(){
//cout << "old individual fitness :" << this->population->parents[index]->fitness << endl;
//cout << "old Individual :" << this->population->parents[index]->serialize() << endl;
this->server->read_data_lock();
string line = this->server->parm->data[this->treatedIndividuals].data;
string line = this->server->parm->data->back().data;
this->server->parm->data->pop_back();
this->population->parents[index]->deserialize(line);
//TAG THE INDIVIDUAL AS IMMIGRANT
this->population->parents[index]->isImmigrant = true;
//TAG THE INDIVIDUAL AS IMMIGRANT
this->population->parents[index]->isImmigrant = true;
this->server->read_data_unlock();
//cout << "new Individual :" << this->population->parents[index]->serialize() << endl;
this->treatedIndividuals++;
}
}
}
......
......@@ -27,12 +27,13 @@
#include <omp.h>
#endif
#include <string>
#include <vector>
#define _MULTI_THREADED
#define MAXINDSIZE 50000 /*maximum size of an individual in number of characters*/
typedef struct {
typedef struct recv_data {
char data[MAXINDSIZE];
}RECV_DATA;
......@@ -40,7 +41,7 @@ typedef struct {
int Socket; /* Socket descriptor for server */
struct sockaddr_in ServAddr; /* Local address */
int debug;
RECV_DATA *data;
std::vector<recv_data>* data;
int *nb_data;
}UDP_server_thread_parm_t;
......@@ -48,7 +49,7 @@ class CComUDPServer {
public:
int debug;
RECV_DATA *data;
std::vector<recv_data> data;
int nb_data;
UDP_server_thread_parm_t *parm;
CComUDPServer(unsigned short port, int dg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment