⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mandelbrot_slave.c

📁 PVM下mandel_brot集并行化代码
💻 C
字号:
/** * The mandelbrot set PVM source code. * Author:	Amal Cao * Since:	Dec. 18th 2008 *  GPL v2.0 */#include <stdlib.h>#include <sys/types.h>#include <fcntl.h>#include <stdio.h>#include "pvm3.h"#define ENCODING  PvmDataDefault#define		X_RESN	800       /* x resolution */#define		Y_RESN	800       /* y resolution */#define  		H_MAX    360   /* HSB color space constant */#define		DELAY   10	  /* delay factor: to make the program                                    run slower and give more interesting                                    timing result */typedef struct complextype{        float real, imag;} Compl;	int *val;int main(void){    int mytid;   /* my task id */    int cc,ptid;        int n = 0;    int tmp[3];    //double rsl_value=0.0;        mytid = pvm_mytid();        /* tell parent I am ready */    ptid=pvm_parent();        pvm_setopt(PvmRoute, PvmRouteDirect);    pvm_initsend(ENCODING);    pvm_send(ptid, 0);        /* pack mytid in buffer */        cc=pvm_recv(ptid,mytid);    pvm_upkint(tmp,3,1);    //rsl_value=flex(tmp[0],tmp[1]);        int size = X_RESN/tmp[1];    if (tmp[0] == tmp[1]-1)    	size += X_RESN%tmp[1];    int loop_step = tmp[2];    int start = tmp[0]*X_RESN/tmp[1];        val = (int *)malloc(size*Y_RESN*sizeof(int));        int i, j, k;    Compl z, c;	float	lengthsq, temp;         for(i=0; i < size; 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+start) - 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 < H_MAX * loop_step);          val[i*X_RESN+j] = (k >= H_MAX * loop_step) ? H_MAX-1 : (k % H_MAX);        }    }        pvm_initsend(ENCODING);    pvm_pkint(val,size*Y_RESN,1);    pvm_send(ptid,mytid);        free(val);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -