"ppl.h"ヘッダのConcurrency :: parallel_forアルゴリズムに関する質問があります。この例はIvor Hortonの本「Beginning Visual C++ 2010」からのものです。彼はあなたが並列計算を使用してマンデルブロ集合を構築する方法を示します。この特定の例では http://media.wiley.com/product_ancillary/83/04705008/DOWNLOAD/500880ch13.zip 「CH13/Ex13_03/Ex13_03.cpp」複数コアのプログラミング/ Mandelbrot Set/C++
:.cppのファイルを完了するために
リンク。
それはハンドル機能:
void DrawSetParallelFor(HWND hWnd)
{
// setting interface here
HDC hdc(GetDC(hWnd));
RECT rect;
GetClientRect(hWnd, & rect);
// getting width and height of our window
int imageHeight(rect.bottom);
int imageWidth(rect.right);
// defining variables and constants
const double realMin(-2.1); // Minimum real value
double imaginaryMin(-1.3); // Minimum imaginary value
double imaginaryMax(+1.3); // Maximum imaginary value
double realMax(realMin+(imaginaryMax-imaginaryMin)*imageWidth/imageHeight);
double realScale((realMax-realMin)/(imageWidth-1));
double imaginaryScale((imaginaryMax-imaginaryMin)/(imageHeight-1));
// defining critical section
Concurrency::critical_section cs; // Mutex for BitBlt() operation
// starting parallel loop
Concurrency::parallel_for(0, imageHeight, [&](int y)
{
// locking code
cs.lock();
HDC memDC = CreateCompatibleDC(hdc);
HBITMAP bmp = CreateCompatibleBitmap(hdc, imageWidth, 1);
cs.unlock();
HGDIOBJ oldBmp = SelectObject(memDC, bmp);
double cReal(0.0), cImaginary(0.0);
double zReal(0.0), zImaginary(0.0);
zImaginary = cImaginary = imaginaryMax - y*imaginaryScale;
// filling horizontal rows with colored pixels
for(int x = 0; x < imageWidth; ++x)
{
zReal = cReal = realMin + x*realScale;
SetPixel(memDC, x, 0, Color(IteratePoint(zReal, zImaginary, cReal, cImaginary)));
}
// locking again
cs.lock();
BitBlt(hdc, 0, y, imageWidth, 1, memDC, 0, 0, SRCCOPY);
cs.unlock();
// deleting objects
SelectObject(memDC, oldBmp);
DeleteObject(bmp);
DeleteDC(memDC);
});
ReleaseDC(hWnd, hdc);
}
基本的に、この関数はIteratePoint
関数で計算されているマンデルブロ集合を描画します。
ピクセルの水平方向の行がランダムな順序でレンダリングされます。私の質問はどのくらい正確にConcurrency::parallel_for
アルゴリズムがウィンドウのどの領域(つまり、yの水平行のピクセルのセット)がどのコアによってレンダリングされるかを決定する方法です。
p.s.作業例はここにあります:http://hotfile.com/dl/137661392/d63280a/MANDELBROT.rar.html
ありがとうございました!
は私にこれをクリアするためにどうもありがとうございました) –