Slave Source

WB01343_.gif (599 bytes)

// PVM Mandelbrot Set Slave Program
// Tom Dixon - Supercomp Period 3

#include </usr/pvm3/include/pvm3.h>
#include <stdlib.h>
#include <fstream.h>

void main()
{
  int mytid;
  int min, max, ysize, col, master, it, who;
  double y1, y2, x, y, a, b, ta;
  
  // Initial information
  pvm_recv(-1, 69);
  pvm_upkint(&who, 1, 1);
  pvm_upkdouble(&y1, 1, 1);
  pvm_upkdouble(&y2, 1, 1);
  pvm_upkint(&ysize, 1, 1);
  pvm_upkint(&max, 1, 1);
  pvm_upkint(&min, 1, 1);
  master=pvm_parent();
  mytid=pvm_mytid();

  double** screen = (double **)malloc(sizeof(double *)*ysize);
  for (int i = 0; i < ysize; i++)
    screen[i]=(double*)malloc(sizeof(double)*3);

  while (1) {
    pvm_recv(-1, 666);
    pvm_upkint(&col, 1, 1);
    pvm_upkdouble(&x, 1, 1);
    
    for(int j=0; j<ysize; j++) {
      it=0;
      y=y2-(y2-y1)*j/ysize;
      a=x; b=y;
      while (it<max && a*a+b*b<4) {
        ta=a*a-b*b+x;
        b=2*a*b+y;
        a=ta;
        it++;
      }
      if (it<max) {
        screen[j][0]=double(it-min)/(max-min);
        screen[j][1]=1-double(it-min)/(max-min);
        screen[j][2]=double(it-min)/(max-min);
      }
      else screen[j][0]=screen[j][1]=screen[j][2]=0;
    }

    pvm_initsend(PvmDataDefault);
    pvm_pkint(&who, 1, 1);
    pvm_pkint(&col, 1, 1);
    for(int i=0; i<ysize; i++)
      pvm_pkdouble(screen[i], 3, 1);
    pvm_send(master, 254);
  }
}

WB01343_.gif (599 bytes)