cleaned up dirty pointer handling -> global priv struct
[physik/nlsop.git] / nlsop_client.c
index f5d7b84..201c48c 100644 (file)
@@ -66,6 +66,7 @@ int *gi;
 unsigned char dc;
 
 int get_data_and_calc(t_event *event,void *allineed);
+int nop(t_event *event,void *allineed);
 
 int usage(char *prog)
 {
@@ -304,19 +305,48 @@ u32 get_reject_graph(info *my_info,d3_lattice *d3_l,char *file,u32 *graph) {
 void send_data(int signum) {
 
   int c;
+  unsigned char data;
+  int fd;
 
   c=gd3_l->max_x*gd3_l->max_y*gd3_l->max_z;
 
+  printf("%d <-\n",c);
+
   network_send(gnet->connection[0].fd,&dc,1);
-  /*
+  network_receive(gnet->connection[0].fd,&data,sizeof(unsigned char));
+  printf("debug: sent dc\n");
+
   network_send(gnet->connection[0].fd,(unsigned char *)gd3_l,
                sizeof(d3_lattice));
+  network_receive(gnet->connection[0].fd,&data,sizeof(unsigned char));
+  printf("debug: sent d3_lattice\n");
+
   network_send(gnet->connection[0].fd,(unsigned char *)gmy_info,sizeof(info));
-  */
+  network_receive(gnet->connection[0].fd,&data,sizeof(unsigned char));
+  printf("debug: sent info\n");
+
   network_send(gnet->connection[0].fd,gd3_l->status,c*sizeof(unsigned char));
+  network_receive(gnet->connection[0].fd,&data,sizeof(unsigned char));
+  printf("debug: sent ac\n");
+
   network_send(gnet->connection[0].fd,(unsigned char *)gd3_l->extra,
                c*sizeof(int));
+  network_receive(gnet->connection[0].fd,&data,sizeof(unsigned char));
+  printf("debug: sent cc\n");
+
   network_send(gnet->connection[0].fd,(unsigned char *)gi,sizeof(int));
+  network_receive(gnet->connection[0].fd,&data,sizeof(unsigned char));
+  printf("debug: sent steps\n");
+
+  if(signum==121) {
+    printf("save test file\n");
+    fd=open("./test.save",O_WRONLY|O_CREAT);
+    write(fd,gd3_l,sizeof(d3_lattice));
+    write(fd,gmy_info,sizeof(info));
+    write(fd,gd3_l->status,c*sizeof(unsigned char));
+    write(fd,gd3_l->extra,c*sizeof(int));
+    close(fd);
+  }
 
 }
 
@@ -338,7 +368,7 @@ int main(int argc,char **argv)
   gnet=&net;
 
   /* default values */
-  strcpy(server_ip,"");
+  strcpy(server_ip,"137.250.82.105");
   strcpy(p_file,IMP_PROFILE);
   strcpy(n_e_file,NEL_PROFILE);
   strcpy(r_file,"");
@@ -397,7 +427,14 @@ int main(int argc,char **argv)
   /* wait for job */
   event_math(net.connection[0].fd,&event,READ,ADD);
   printf("idle, waiting for jobs ...\n");
-  event_start(&event,NULL,get_data_and_calc,NULL);
+  event_start(&event,NULL,get_data_and_calc,nop);
+
+  return 1;
+}
+
+int nop(t_event *event,void *allineed) {
+
+  printf("\ni did a nop :)\n");
 
   return 1;
 }
@@ -413,7 +450,7 @@ int get_data_and_calc(t_event *event,void *allineed) {
   u32 x_c,y_c,z_c;
   int i,j;
   int c_step;
-  unsigned char data[256];
+  unsigned char data;
 
   t_net *net;
 
@@ -430,8 +467,8 @@ int get_data_and_calc(t_event *event,void *allineed) {
   printf("got a new job ...\n");
   
   /* get info (+data) */
-  network_receive(net->connection[0].fd,data,1);
-  if(data[0]==NLSOP_NJOB || data[0]==NLSOP_CJOB) {
+  network_receive(net->connection[0].fd,&data,sizeof(unsigned char));
+  if(data==NLSOP_NJOB || data==NLSOP_CJOB) {
     network_receive(net->connection[0].fd,(unsigned char *)&d3_l,
                     sizeof(d3_lattice));
     network_receive(net->connection[0].fd,(unsigned char *)&my_info,
@@ -448,21 +485,29 @@ int get_data_and_calc(t_event *event,void *allineed) {
       printf("extra malloc failed\n");
       return -1;
     }
-    if(data[0]==NLSOP_CJOB) {
+    if(data==NLSOP_CJOB) {
+      data=DATA_OK;
       network_receive(net->connection[0].fd,d3_l.status,
                       j*sizeof(unsigned char));
+      network_send(net->connection[0].fd,&data,sizeof(unsigned char));
       network_receive(net->connection[0].fd,(unsigned char *)d3_l.extra,
                       j*sizeof(int));
+      network_send(net->connection[0].fd,&data,sizeof(unsigned char));
       network_receive(net->connection[0].fd,(unsigned char *)&c_step,
                       sizeof(int));
+      network_send(net->connection[0].fd,&data,sizeof(unsigned char));
     }
   }
+  else {
+    printf("unknown instruction, restarting ...\n");
+    return -1;
+  }
 
   printf("starting simulation with following parameters:\n");
   printf("b = %f | c = %f | s = %f\n",my_info.b,my_info.c,my_info.s);
   printf("diff every %d steps | diff rate = %f\n",my_info.diff_rate,
                                                   my_info.dr_ac);
-  printf("current step: %d | total steps: %d\n"my_info.steps,c_step);
+  printf("current step: %d | total steps: %d\n",c_step,my_info.steps);
   printf("...\n");
 
   /* care for signals */
@@ -521,7 +566,7 @@ int get_data_and_calc(t_event *event,void *allineed) {
     i++;
     if(i%my_info.save_rate==0) {
       dc=DC_OK;
-      send_data(0);
+      send_data(120);
       dc=DC_QUIT;
     }
     if(i%my_info.s_rate==0) sputter(&d3_l);
@@ -529,10 +574,15 @@ int get_data_and_calc(t_event *event,void *allineed) {
 
   /* finished */
   dc=DC_END;
-  send_data(0);
+  send_data(121);
   dc=DC_QUIT;
 
   /* shutdown/free/close everything now ... */
+  free(d3_l.status);
+  free(d3_l.extra);
+  free(c_profile);
+  free(n_e_loss);
+  free(nel_z);
 
   return 1;
 }