/* * mpi_buddha.c - generates the buddhabrot fractal using mpi */ #include #include #include #include #include #define width 1280 #define height 1024 #define iter 1000 #define iteration (100000000L) #define xmin -2.0 #define xmax 2.0 #define ymin -2.0 #define ymax 2.0 #define max(x,y) (x > y ? x : y) #define min(x,y) (x < y ? x : y) int checkPoint(double complex c, int *n, double complex *seq) { int k; double complex z = 0; double complex new; *n = 0; for(k = 0;k < iter;k++) { z = z*z + c; seq[k] = z; if(creal(z)*creal(z) + cimag(z) *cimag(z) > 10) { *n = k; return 1; } } return 0; } int main(int argc, char ** argv) { FILE* fl; int i,j,n,ix,iy,t; double complex c; unsigned int *image = NULL; double complex *seq = NULL; unsigned int *buff = NULL; int max,min,range; int mpistate,size,rank; MPI_Status mpistatus; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); if((image = (unsigned int*)malloc(width*height*sizeof(unsigned int))) == NULL) { fprintf(stderr,"Failed to malloc memory for the image\n"); } if((seq = (double complex*)malloc(iter*sizeof(double complex))) == NULL) { fprintf(stderr,"Failed to malloc memory for the sequence\n"); } for(i = 0; i < width*height;i++) { image[i] = 0; } for(t = 0;t < iteration;t++) { c = 6*drand48() - 3 + (6*drand48()-3)*I; if(checkPoint(c,&n,seq)) { for(i = 0; i < n;i++) { ix = .3 * width * (creal(seq[i]) + .5) + width/2; iy = .3 * height * cimag(seq[i]) + height/2; if(ix >=0 && iy >= 0 && ix < width && iy < height) image[iy*width+ix]++; } } } MPI_Barrier(MPI_COMM_WORLD); if(rank == 0) { printf("Passed the MPI_Barrier\n"); if((buff = (unsigned int *)malloc(width*height*sizeof(unsigned int)))==NULL) fprintf(stderr,"Failed to allocate memory for the buffer\n"); for(i = 1;i