?? mandelbrot_slave.c
字號:
/* Mandlebrot program slave */
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "pvm3.h"
#define ENCODING PvmDataDefault
#define X_RESN 800
#define Y_RESN 800
typedef struct complextype
{
float real, imag;
} Compl;
int main ()
{
/* pvm ********************************************************/
int mytid; /* my task id */
int cc,ptid;
/**************************************************************/
/* Mandlebrot variables */
int row , i, k ,sendBuf[800] ;
Compl z, c;
float lengthsq, temp;
int calMax = 20000 ;
/* pvm ********************************************************/
mytid = pvm_mytid();
/* tell parent I am ready */
ptid=pvm_parent();
pvm_setopt(PvmRoute, PvmRouteDirect);
pvm_initsend(ENCODING);
pvm_send(ptid, 0 );
/**************************************************************/
while(1)
{
//receive:
if( pvm_recv(ptid,mytid)<0 )
return 0 ;
pvm_upkint(&calMax, 1, 1) ;
pvm_upkint(&row, 1, 1) ;
if((row>399)||(row<0)) //超出計算范圍,循環結束
{
printf("Received row = %d , finished.\n",row) ;
break ;
}
/* Calculate */
for(i=0 ; i < X_RESN; i++)
{
z.real = z.imag = 0.0;
c.real = ((float) i - 400.0)/200.0; /* scale factors for 800 x 800 window */
c.imag = ((float) row - 400.0)/200.0; /* scale factors for 800 x 800 window */
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 < calMax);
sendBuf[i] = k ;
}
// send result
pvm_initsend(ENCODING);
pvm_pkint(&mytid, 1, 1) ;
pvm_pkint(&row, 1, 1) ;
pvm_pkint(sendBuf, 800, 1) ;
pvm_send(ptid, 2);
}
return 1 ;
/* slave Finished */
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -