#include #include #include #include #include #include #include #include #include #include #include #include "multimandel.h" int in_sock,recv_sock,send_sock; struct cmd_msg msgbuf; struct data_msg *data; size_t data_size; double x_1,x_2,dx,*xval,*xsq; int width,numcolors,maxit; int *modtab; void fini(int) { shutdown(in_sock,2); close(in_sock); shutdown(recv_sock,2); close(recv_sock); shutdown(send_sock,2); close(send_sock); signal(SIGINT,SIG_DFL); raise(SIGINT); } void sorry(const char *s) { perror(s); fini(0); } ostream & operator << (ostream &o, const struct in_addr &adr) { unsigned char c[4]; memcpy(c,&adr,4); return o << (int)c[0]<<'.'<<(int)c[1]<<'.'<<(int)c[2]<<'.'<<(int)c[3]; } int x_recv(int fd, void *data, int size) { char *P=(char *)data; int left=size,bytes; do { if ((bytes=recv(fd,P,left,0))<0) return 0; P+=bytes; left-=bytes; } while (left>0); return size; } int one_point(double x0, double y0, double x2, double y2) { double x=x0,y=y0; int it=0,cmp=msgbuf.depth; if (x2+y2>=4.0) return 0; for (;;) { if (++it==cmp) return it; y+=(y*=x)+y0; x=x2-y2+x0; if ((x2=x*x)+(y2=y*y)>=4.0) return it; } } void one_line() { unsigned char *P=data->it; double y2=msgbuf.y*msgbuf.y,*xP=xval,*x2P=xsq; for (int i=0;i=numcolors) j=1; } data_size=sizeof(data_msg)+sizeof(unsigned char[width]); data=(data_msg*)new char[data_size]; data->num=msgbuf.num; // cout << "I am slave number " << msgbuf.num << endl; if (send(send_sock,data,data_size,0)<0) sorry("send"); // cout << "hello sent" << endl; break; case 'c': // cout << "compute line " << msgbuf.line << ' ' << msgbuf.y << endl; one_line(); data->line=msgbuf.line; if (send(send_sock,data,data_size,0)<0) sorry("send"); // cout << "sent line " << msgbuf.line << " to master" << endl; break; default: cerr << "unknown command " << msgbuf.command << endl; } } }