📄 mandelbrotslave.c
字号:
#include <sys/types.h>
#include <fcntl.h>
#include <stdio.h>
#include <math.h>
#include "pvm3.h"
#define ENCODING PvmDataDefault
#define Y_RESN 800 /* y resolution */
typedef struct complextype
{
float real, imag;
} Compl;
void main(void)
{
int mytid; /* my task id */
int ptid; /* parent task id */
int row;
int i, j, k;
Compl z, c;
float lengthsq, temp;
mytid = pvm_mytid();
/* tell parent I am ready */
ptid=pvm_parent();
while(true)
{
/* gain the task from the parent */
pvm_recv(ptid,999);
pvm_upkint(&row,1,1);
if(row==-1)break;
pvm_initsend(ENCODING);
/* Calculate points */
for(i=row; i<row+50; 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 < 255);
/* send the point the the parent */
pvm_pkint(&i,1,1);
pvm_pkint(&j,1,1);
pvm_pkint(&k,1,1);
pvm_send(ptid,888);
}
/* request the task from the parent */
pvm_pkint(&k,1,1);
pvm_send(ptid,999);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -