-
大小: 1.18MB文件類型: .zip金幣: 2下載: 0 次發布日期: 2023-11-18
- 語言: C/C++
- 標簽: Mandelbrot??C語言??并行??OpenMP??
資源簡介
求曼德勃羅集合C語言串行并行代碼,使用OpenMP和MPI來應用并行性。

代碼片段和文件信息
#include?
#include?
#include?
#include?
#include?
struct?BMPHeader
{
????char?bfType[2];?
????int?bfSize;?//?文件大?。ㄒ宰止潪閱挝唬?br/>????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.\n“);
????????return(0);
????}
????
????for?(i?=?height?-?1;?i?>=?0;?i--)
????{
???
for?(j?=?0;?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
評論
共有 條評論