求曼德勃罗集合C语言串行并行代码.zip
求曼德勃罗集合C语言串行并行代码,使用OpenMP和MPI来应用并行性。
代码片段和文件信息
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4333 2019-06-06 09:41 曼德勃罗集合串行.cpp
文件 4524 2019-06-06 16:05 曼德勃罗集合并行.cpp
文件 50331702 2019-06-06 16:06 output.bmp
#include
#include
#include
#include
#include
struct BMPHeader
{
char bfType[2];
int bfSize; // 文件大小(以字节为单位)
int bfReserved; //设置为0
int bfOffBits; //字节偏移到实际位图数据(= 54)
int biSize; // BITMAPINFOHEADER的大小 字节(= 40)
int biWidth; //图像宽度,以像素为单位
int biHeight; //图像高度,以像素为单位
short biPlanes; /*目标设备中planes的数目(设为1) */
short biBitCount; /* 每个像素的Bits(24) */
int biCompression; //压缩类型(如果没有压缩,则为0)
int biSizeImage; //图像大小,以字节为单位(如果没有压缩则为0)
int biXPelsPerMeter; /* 显示设备的分辨率(像素/米) */
int biYPelsPerMeter; /* 显示设备的分辨率(像素/米) */
int biClrUsed; /* 颜色表中的颜色数(如果为0,则使用biBitCount允许的最大值)*/
int biClrImportant; /* 重要颜色数量。如果为0,则所有颜色都很重要*/
};
int write_bmp(const char *filename int width int height char *rgb)
{
int i j ipos;
int bytesPerLine;
unsigned char *line;
FILE *file;
struct BMPHeader bmph;
/* 每行的长度必须是4个字节的倍数 */
bytesPerLine = (3 * (width + 1) / 4) * 4;
strncpy(bmph.bfType “BM“ 2);
bmph.bfOffBits = 54;
bmph.bfSize = bmph.bfOffBits + bytesPerLine * height;
bmph.bfReserved = 0;
bmph.biSize = 40;
bmph.biWidth = width;
bmph.biHeight = height;
bmph.biPlanes = 1;
bmph.biBitCount = 24;
bmph.biCompression = 0;
bmph.biSizeImage = bytesPerLine * height;
bmph.biXPelsPerMeter = 0;
bmph.biYPelsPerMeter = 0;
bmph.biClrUsed = 0;
bmph.biClrImportant = 0;
file = fopen (filename “wb“);
if (file == NULL) return(0);
fwrite(&bmph.bfType 2 1 file);
fwrite(&bmph.bfSize 4 1 file);
fwrite(&bmph.bfReserved 4 1 file);
fwrite(&bmph.bfOffBits 4 1 file);
fwrite(&bmph.biSize 4 1 file);
fwrite(&bmph.biWidth 4 1 file);
fwrite(&bmph.biHeight 4 1 file);
fwrite(&bmph.biPlanes 2 1 file);
fwrite(&bmph.biBitCount 2 1 file);
fwrite(&bmph.biCompression 4 1 file);
fwrite(&bmph.biSizeImage 4 1 file);
fwrite(&bmph.biXPelsPerMeter 4 1 file);
fwrite(&bmph.biYPelsPerMeter 4 1 file);
fwrite(&bmph.biClrUsed 4 1 file);
fwrite(&bmph.biClrImportant 4 1 file);
line = (unsigned char *) malloc(bytesPerLine);
if (line == NULL)
{
fprintf(stderr “Can‘t allocate memory for BMP file.
“);
return(0);
}
for (i = height - 1; i >= 0; i--)
{
for (j = 0; j < width; j++)
{
ipos = 3 * (width * i + j);
line[3*j] = rgb[ipos + 2];
line[3*j+1] = rgb[ipos + 1];
line[3*j+2] = rgb[ipos];
}
fwrite(line bytesPerLine 1 file);
}
free(line);
fclose(file);
return(1);
}
void render(char *out int width int height) {
int xy;
for(x=0;x
for(y=0;y //unsigned int xI;
//unsigned int yI;
int index = 3*width*y + x*3;
float x_origin = ((flo
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 4333 2019-06-06 09:41 曼德勃罗集合串行.cpp
文件 4524 2019-06-06 16:05 曼德勃罗集合并行.cpp
文件 50331702 2019-06-06 16:06 output.bmp
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。
评论列表(条)