#include #include #include #include #include #include #include #include #include "lodepng.h" #ifndef CMPLX #define CMPLX(r,i) ((r) + (i)*I) #endif const int MAXITER=200; const double EPS=1e-1; static double complex att_func(double complex x,double exponent){ #if 0 static const int N=9; double complex r=1,y=x; for(int i=1;iN)norm=N; int clrv=(int)(norm/N*255); return (struct colour){clrv,clrv,clrv}; } struct config{ double unitsz; int width,height; double midx,midy; double exponent; }; struct thread_info{ pthread_t th; int ystart,yend; unsigned char *img; bool do_basins; struct config cfg; }; static void* thread_entry(void *arg_vp){ struct thread_info *th_info=arg_vp; int ystart=th_info->ystart; int yend=th_info->yend; unsigned char *img=th_info->img; bool do_basins=th_info->do_basins; struct config cfg=th_info->cfg; int nbasins=0,bsz=0; double complex *basins=NULL; if(do_basins){ bsz=16; basins=malloc(bsz*sizeof(double complex)); assert(basins); } printf("Thread: y in [%d,%d)\n",ystart,yend); for(int iy=ystart;iy=2){ cfg.exponent=strtod(argv[1],NULL); } const char *fname; if(argc>=3){ fname=argv[2]; } else { fname="out.png"; } unsigned char img[cfg.width*cfg.height*3]; int nthreads=sysconf(_SC_NPROCESSORS_ONLN); if(nthreads==4)nthreads/=2; if(nthreads>=999||nthreads<1)nthreads=1; fprintf(stderr,"Using %d thread%s\n",nthreads,nthreads==1?"":"s"); pthread_attr_t attr; if(pthread_attr_init(&attr)!=0){ perror("pthread_attr_init"); return 1; } struct thread_info ths[nthreads]; for(int i=0;i