X-Git-Url: https://hackdaworld.org/gitweb/?p=physik%2Fnlsop.git;a=blobdiff_plain;f=nlsop_server.c;h=232f5ccfae0a44c64b5c473ffc939064683ccb6d;hp=085e289a37f4007643197e3468142b29c0799c03;hb=3c6b696777d3ecc13534fe4054fc1ffa8c706044;hpb=f9a7f27f952d23ebd856c4c60fbdf7c024f95f7b diff --git a/nlsop_server.c b/nlsop_server.c index 085e289..232f5cc 100644 --- a/nlsop_server.c +++ b/nlsop_server.c @@ -124,15 +124,34 @@ int save_job(t_net *net,int channel,t_job *job,unsigned char dc) { int ret; d3_lattice d3l; info info; + unsigned char data; + + printf("receiving data from client (%d)\n",job->size); + data=DATA_OK; + + network_send_chan(net,channel,&data,sizeof(unsigned char)); + + network_receive_chan(net,channel,(unsigned char *)&d3l, + sizeof(d3_lattice)); + network_send_chan(net,channel,&data,sizeof(unsigned char)); + printf("debug: got d3_lattice\n"); + + network_receive_chan(net,channel,(unsigned char *)&info,sizeof(info)); + network_send_chan(net,channel,&data,sizeof(unsigned char)); + printf("debug: got info\n"); + + network_receive_chan(net,channel,job->ac,job->size*sizeof(unsigned char)); + network_send_chan(net,channel,&data,sizeof(unsigned char)); + printf("debug: got ac\n"); - ret=network_receive_chan(net,channel,job->ac,job->size*sizeof(unsigned char)); - if(ret==N_ERROR) printf("FATAL: getting ac status failed\n"); - ret=network_receive_chan(net,channel,(unsigned char *)job->cc, + network_receive_chan(net,channel,(unsigned char *)job->cc, job->size*sizeof(int)); - if(ret==N_ERROR) printf("FATAL: getting cc failed\n"); - ret=network_receive_chan(net,channel,(unsigned char *)&(job->step), - sizeof(int)); - if(ret==N_ERROR) printf("FATAL: getting step number failed\n"); + network_send_chan(net,channel,&data,sizeof(unsigned char)); + printf("debug: got cc\n"); + + network_receive_chan(net,channel,(unsigned char *)&(job->step),sizeof(int)); + network_send_chan(net,channel,&data,sizeof(unsigned char)); + printf("debug: got steps\n"); if(dc!=DC_QUIT) { snprintf(filename,128,"./data/nlsop_b%f_c%f_s%f_ds%d_dr%f_-_%d_of_%d.save", @@ -144,16 +163,12 @@ int save_job(t_net *net,int channel,t_job *job,unsigned char dc) { return -1; } - memset(&d3l,0,sizeof(d3_lattice)); - d3l.max_x=job->x; - d3l.max_y=job->y; - d3l.max_z=job->z; if(write(fd,&d3l,sizeof(d3_lattice))info),sizeof(info))status&IDLE?'i':'a'); c->status=IDLE; + printf("now: %c\n",c->status&IDLE?'i':'a'); + printf("it is channel %d\n",c->channel); + /* free job memory */ + free(j->ac); + free(j->cc); /* delete job entry */ list_del_current(job); printf("job ended, saved and removed from list.\n"); @@ -323,7 +350,7 @@ int distribute_jobs(t_event *event,void *allineed) { t_net *net; t_list *c_list,*g_list,*job; - int count_j,count_c; + int count_j,count_c,min; t_job *j; t_client *c; unsigned char data; @@ -337,12 +364,39 @@ int distribute_jobs(t_event *event,void *allineed) { g_list=(t_list *)addr[2]; job=(t_list *)addr[3]; - count_j=list_count(job); - count_c=list_count(c_list); + list_reset(job); + list_reset(c_list); + + count_j=0; + count_c=0; + + if((c_list->current==NULL)||(job->current==NULL)) return 2; + + j=(t_job *)job->current->data; + c=(t_client *)c_list->current->data; + if(j->status==IN_QUEUE) count_j++; + if(c->status==IDLE) count_c++; + + while(list_next(job)!=L_NO_NEXT_ELEMENT) { + j=(t_job *)job->current->data; + if(j->status==IN_QUEUE) count_j++; + } + while(list_next(c_list)!=L_NO_NEXT_ELEMENT) { + c=(t_client *)c_list->current->data; + if(c->status==IDLE) count_c++; + } + + min=(count_ccurrent->data; c=(t_client *)c_list->current->data; while(c->status!=IDLE) { @@ -372,12 +426,15 @@ int distribute_jobs(t_event *event,void *allineed) { if(data==NLSOP_CJOB) { network_send_chan(net,c->channel,j->ac,j->size*sizeof(unsigned char)); + network_receive_chan(net,c->channel,&data,sizeof(unsigned char)); network_send_chan(net,c->channel,(unsigned char *)&(j->cc), j->size*sizeof(int)); + network_receive_chan(net,c->channel,&data,sizeof(unsigned char)); + network_send_chan(net,c->channel,(unsigned char *)&(j->step),sizeof(int)); + network_receive_chan(net,c->channel,&data,sizeof(unsigned char)); } - --count_c; - --count_j; + --min; list_next(c_list); list_next(job); }