/* Sequential Mandelbrot program */ #include #include #include #include #include #include #define X_RESN 800 /* x resolution */ #define Y_RESN 800 /* y resolution */ typedef struct complextype { float real, imag; } Compl; int main ( int argc, char *argv[]) { FILE *fp, *fopen (); int x, y; int size, rank; char str[100]; MPI_Status status; MPE_XGraph graph; MPE_Color *colorArray; int numcolors; /* Mandlebrot variables */ int i, j, k; Compl z, c; float lengthsq, temp; /* set window position */ x = 50; y = 50; MPI_Init(&argc,&argv); MPI_Comm_size(MPI_COMM_WORLD,&size); MPI_Comm_rank(MPI_COMM_WORLD,&rank); MPE_Open_graphics( &graph, MPI_COMM_WORLD, NULL, x, y, 500, 500, 0 ); /* The only purpose of this section is to print a color bar representing the available MPE colors (there are 15 of them) */ /********************************************************************/ MPE_Num_colors( graph, &numcolors ); colorArray = (MPE_Color *) malloc(sizeof(MPE_Color)*numcolors); MPE_Make_color_array(graph, numcolors, colorArray); if (rank == 0) printf("Number of colors = %d\n", numcolors); x=50; y=0; for (i = 0; i < numcolors; i++) { MPE_Fill_rectangle( graph, x, y, 20, 20, colorArray[i]); x += 20; } /*********************************************************************/ /* Calculate and draw points */ for(i=0; i < X_RESN; i++) for(j=0; j < Y_RESN; j++) { z.real = z.imag = 0.0; c.real = ((float) j - 400.0)/200.0; /* scale factors for 800 x 800 window */ c.imag = ((float) i - 400.0)/200.0; k = 0; do { /* iterate for pixel color */ temp = z.real*z.real - z.imag*z.imag + c.real; z.imag = 2.0*z.real*z.imag + c.imag; z.real = temp; lengthsq = z.real*z.real+z.imag*z.imag; k++; } while (lengthsq < 4.0 && k < 100); if (k == 100) { MPE_Draw_point(graph, j, i-100, MPE_BLACK); // if (rank == 0) // printf("Length squared= % f\n", lengthsq); } if (lengthsq >= 4.0 && (i-100) > 25) MPE_Draw_point(graph, j, i-100, colorArray[(int)(lengthsq + 4) % 15]); } MPE_Update( graph ); /* Program Finished */ if (rank == 0) { getchar(); //Pause for a key to be pressed } MPE_Close_graphics( &graph ); MPI_Finalize(); return 0; }