/* * Bryan Ward * char_mandel_mpi.c - generate grayscale mandelbrot - mpi */ #include #include #include #include #include #include #define width 12800 #define height 10240 #define iter 255 #define xmin -2.0 #define xmax 2.0 #define ymin -2.0 #define ymax 2.0 //#define I 0+1i //needed for cray cc unsigned char checkPoint (double complex c) { double complex z = 0; unsigned char j = 0; while ((creal (z) * creal (z) + cimag (z) * cimag (z)) < 4 && j < iter) { z = z * z + c; j++; } return j; } int main(int argc, char **argv) { FILE *fl; //MPI int mpistate,size,rank; MPI_Status mpistatus; //Non-MPI unsigned char* buff; unsigned char* final; int i,j,segment; unsigned char* part; double complex c; double xpix,ypix; // double complex unit = 0 + 1i; double start; //MPI Initialization MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); start = MPI_Wtime(); ypix = (ymax - ymin) / height; xpix = (xmax - xmin) / width; segment = width*height/size; part = (unsigned char *)malloc(sizeof(unsigned char)*segment); fprintf(stderr,"Processor %d starting to iterate over %d points\n",rank,segment); for (i = segment*rank;i < segment*(rank+1);i++) { c = xmin + (i%width * xpix) + (ymin + (i/height *ypix))*I; part[i-segment*rank] = checkPoint(c); } printf("Processor %d done calculating in %f seconds\n",rank,MPI_Wtime()-start); // MPI_Barrier(MPI_COMM_WORLD); if(rank == 0) { if((fl = fopen("mpibrot.pgm","w")) == NULL) fprintf(stderr,"Cannot open mpibrot.pgm"); fprintf (fl, "P5\n"); fprintf (fl, "#Copyright (C) 2007 Bryan Ward\n"); fprintf (fl, "%d\t%d\n", width, height); fprintf (fl, "255\n"); fwrite((void*)part,sizeof(unsigned char),segment,fl); buff = (unsigned char *)malloc(segment*sizeof(unsigned char)); for(i = 1;i