Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #include <omp.h>
- int main()
- {
- /* screen ( integer) coordinate */
- int iX,iY;
- const int iXmax = 3000;
- const int iYmax = 3000;
- /* world ( double) coordinate = parameter plane*/
- double Cx,Cy;
- const double CxMin=-2.5;
- const double CxMax=1.5;
- const double CyMin=-2.0;
- const double CyMax=2.0;
- /* */
- double PixelWidth=(CxMax-CxMin)/iXmax;
- double PixelHeight=(CyMax-CyMin)/iYmax;
- /* color component ( R or G or B) is coded from 0 to 255 */
- /* it is 24 bit color RGB file */
- const int MaxColorComponentValue=255;
- FILE * fp;
- char *filename="new1.ppm";
- char *comment="# ";/* comment should start with # */
- static unsigned char color[iYmax][iXmax][3];
- /* Z=Zx+Zy*i ; Z0 = 0 */
- double Zx, Zy;
- double Zx2, Zy2; /* Zx2=Zx*Zx; Zy2=Zy*Zy */
- /* */
- int Iteration;
- const int IterationMax=200;
- /* bail-out value , radius of circle ; */
- const double EscapeRadius=2;
- double ER2=EscapeRadius*EscapeRadius;
- /*create new file,give it a name and open it in binary mode */
- fp= fopen(filename,"wb"); /* b - binary mode */
- /*write ASCII header to the file*/
- fprintf(fp,"P6\n %s\n %d\n %d\n %d\n",comment,iXmax,iYmax,MaxColorComponentValue);
- /* compute and write image data bytes to the file*/
- int tab[4] = {0, 0, 0, 0};
- int id;
- double startTime = omp_get_wtime();
- #pragma omp parallel private(Zx, Zy, Zx2, Zy2, iX, iY, Cy, Cx, Iteration, id) num_threads(4)
- {
- id = omp_get_thread_num();
- #pragma omp for schedule(static, 60)
- for(iY=0;iY<iYmax;iY++)
- {
- Cy=CyMin + iY*PixelHeight;
- if (fabs(Cy)< PixelHeight/2) Cy=0.0; /* Main antenna */
- for(iX=0;iX<iXmax;iX++)
- {
- Cx=CxMin + iX*PixelWidth;
- /* initial value of orbit = critical point Z= 0 */
- Zx=0.0;
- Zy=0.0;
- Zx2=Zx*Zx;
- Zy2=Zy*Zy;
- /* */
- for (Iteration=0;Iteration<IterationMax && ((Zx2+Zy2)<ER2);Iteration++)
- {
- Zy=2*Zx*Zy + Cy;
- Zx=Zx2-Zy2 +Cx;
- Zx2=Zx*Zx;
- Zy2=Zy*Zy;
- };
- //tab[id] += Iteration;
- /* compute pixel color (24 bit = 3 bytes) */
- if (Iteration==IterationMax)
- { /* interior of Mandelbrot set = black */
- color[iY][iX][0]=0;
- color[iY][iX][1]=0;
- color[iY][iX][2]=0;
- }
- else
- { /* exterior of Mandelbrot set = white */
- color[iY][iX][0]=id*60;
- color[iY][iX][1]=id*60;
- color[iY][iX][2]=id*60;
- };
- /*write color to the file*/
- }
- }
- }
- double endTime = omp_get_wtime() - startTime;
- printf("Time : %f\n t1: %d\n, t2: %d\n, t3: %d\n, t4: %d\n" , endTime, tab[0], tab[1], tab[2], tab[3]);
- fwrite(color,1,3*iXmax*iYmax,fp);
- fclose(fp);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement