/*************************************/

// Osial P.

// Zuk Mandelbrota (MPI) v1.0

/*************************************/

#include <stdio.h>

#include <math.h>

#include <stdlib.h>

#undef SEEK_SET

#undef SEEK_END

#undef SEEK_CUR

#include <mpi.h>

using namespace std;

/*****************************************/

// Stale

/*****************************************/

const double magnify = 2.0; // Powiekszenie

const int itermax = 2000; // Literacje

const int xres = 2000; // Rozdzielczosc H

const int yres = 2000; // Rozdzielczosc V

/*****************************************/

// Zmienne

/*****************************************/

short int kr = 0;

short int kg = 0; // kolor fraktal

short int kb = 0;

short int br = 255;

short int bg = 255;// kolor tlo

short int bb = 255;

MPI_Status mpistatus; //Status operacji mpi

int wezel_lok, liczbawezlow, lok_min, lok_max, iteration;

unsigned int hx, hy, it;

double x, xx, y, cx, cy;

bool * tab;

/****************************************/

// Program glowny

/****************************************/

int main(int argc, char * argv[]){

MPI_Init(&argc,&argv);

MPI_Comm_size(MPI_COMM_WORLD, &liczbawezlow);

MPI_Comm_rank(MPI_COMM_WORLD, &wezel_lok);

int licz_el_tab = (yres / liczbawezlow) * xres;

tab = new bool[licz_el_tab];

// Podzial zakresu zadan pomiedzy proceswy

lok_min = yres * wezel_lok / liczbawezlow + 1;

lok_max = yres * (wezel_lok + 1) / liczbawezlow;

FILE * pFile;

pFile = fopen ("mandelbrot.ppm","w");

if(wezel_lok == 0){fprintf(pFile,"P6\n%d %d\n255\n",xres,yres);}

// Wlasciwa czesc

it = 1;

for (hy=lok_min;hy <= lok_max;hy++) {

for (hx=1;hx <= xres;hx++) {

cx = (((float)hx)/((float)xres)-0.5)/magnify*3.0-0.7;

cy = (((float)hy)/((float)yres)-0.5)/magnify*3.0;

x = 0.0; y = 0.0;

for (iteration=1;iteration<itermax;iteration++) {

xx = x*x-y*y+cx;

y = 2.0*x*y+cy;

x = xx;

if (x*x+y*y>100.0) iteration = 999999;

}

if(wezel_lok == 0){

if (iteration<99999){

fputc((char)kr,pFile);

fputc((char)kg,pFile);

fputc((char)kb,pFile);

}

else {

fputc((char)br,pFile);

fputc((char)bg,pFile);

fputc((char)bb,pFile);

}

}

else { if (iteration<99999) tab[it]=true;

else tab[it]=false;

it=it++;

}

}

}

// odbieranie tablic danych

MPI_Barrier(MPI_COMM_WORLD);

if(wezel_lok == 0){

for(int i=1;i<liczbawezlow;i++){

MPI_Recv(tab,licz_el_tab,MPI_BYTE,i,1,MPI_COMM_WORLD, &mpistatus);

for(int l=0;l<licz_el_tab;l++){

if (tab[l] == true)

{

fputc((char)kr,pFile);

fputc((char)kg,pFile);

fputc((char)kb,pFile);

}

else {

fputc((char)br,pFile);

fputc((char)bg,pFile);

fputc((char)bb,pFile);

}

}

}

}

else {

MPI_Send(tab,licz_el_tab,MPI_BYTE,0,1,MPI_COMM_WORLD);

}

fclose (pFile);

MPI_Finalize();

}

#!/ bin/bash

#$ cwd

#$ eblad.err

#$ o wyjscie.out

#$ pe mpich2 smpd 1 #(liczba procesorów zaleznie od testu)

port=$((JOB ID% 5000 + 20000))

echo Running on host `hostname`

echo Time is `date`

echo Directory is `pwd`

echo This job runs on the following processors : cat $TMPDIR/machines

echo This job has allocated $NSLOTS processors

######################################################

/usr/bin/time f ”Czas wykonania %E , zakonczony ze statusem %x” n

/home/opt/mpich2_smpd/bin/mpiexec np $NSLOTS machinefilen

$TMPDIR/machines p $ port procesmpi

###################### k o n i e c ###########################

2