병렬 분산 처리 parallel_for 함수 사용법이 궁금합니다.

mydream의 이미지

VOID PopupDisplay(HWND& hwnd, RECT& area, COLORREF (*display)[1000]) {
	parallel_for(area.left, area.right, [](int x) {
		HDC hdc=GetDC(hwnd);
		for(int y=area.top;y<=area.bottom;y++) {
			SetPixel(hdc, x, y, display[x][y]);
		}
		ReleaseDC(hwnd, hdc);
	});
 
 
}

------ 빌드 시작: 프로젝트: test16, 구성: Debug Win32 ------
컴파일하고 있습니다...
test16.cpp
c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(126) : error C2146: 구문 오류 : ')'이(가) 'x' 식별자 앞에 없습니다.
c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(126) : error C2065: 'x' : 선언되지 않은 식별자입니다.
c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(126) : error C2143: 구문 오류 : ';'이(가) '{' 앞에 없습니다.
c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(126) : error C3861: 'parallel_for': 식별자를 찾을 수 없습니다.
c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(129) : error C2065: 'x' : 선언되지 않은 식별자입니다.
c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(129) : error C2065: 'x' : 선언되지 않은 식별자입니다.
c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(132) : error C2059: 구문 오류 : ')'
빌드 로그가 "file://c:\Documents and Settings\the\My Documents\Visual Studio 2008\Projects\test16\test16\Debug\BuildLog.htm"에 저장되었습니다.
test16 - 오류: 7개, 경고: 0개
========== 빌드: 성공 0, 실패 1, 최신 0, 생략 0 ==========

위와 같은 구문오류가 출력됩니다. 오류를 어떻게 고쳐야 하나요?

twinwings의 이미지

lambda 문법 쓰시는데 C++11을 지원하지 않는 VS2008 쓰시고 계시네요.

mydream의 이미지

질문글에서 사용한 함수가 지원이 안되는 것으로 나옵니다. 그래서 CreateThread 함수를 사용했는데, 이번에는 의도한대로 화면을 가져와 출력하지 못하는군요.

struct Loop {
	HDC &hdc;
	COLORREF (*display)[1000];
	LONG currentX;
	LONG top;
	LONG bottom;
};
DWORD WINAPI SetPixelsFromTopToBottom(LPVOID lpParameter) {
	Loop* set=(Loop*)lpParameter;
	//HDC hdc=GetDC(set->hwnd);
	for(LONG y=set->top;y<=set->bottom;y++) {
		SetPixel(set->hdc, set->currentX, y, (set->display)[set->currentX][y]);//여기서 백업한 display가 화면에 제대로 출력되지 않습니다.
	}
	//ReleaseDC(set->hwnd, hdc);
	return (DWORD)0;
}
VOID PopupDisplay(HWND& hwnd, RECT& area, COLORREF (*display)[1000]) {
	/*HDC hdc=GetDC(hwnd);
	for(int x=area.left;x<=area.right;x++) {
		for(int y=area.top;y<=area.bottom;y++) {
			SetPixel(hdc, x, y, display[x][y]);
		}
	}
	ReleaseDC(hwnd, hdc);*/
 
	HDC hdc=GetDC(hwnd);
	HANDLE ThreadHandle;
	for(LONG x=area.left;x<=area.right;x++) {
		Loop loop={hdc, display, x, area.top, area.bottom};
 
		DWORD ThreadID;
 
		ThreadHandle=CreateThread(NULL, 0, SetPixelsFromTopToBottom, &loop, 0, &ThreadID);
		CloseHandle(ThreadHandle);
	}
	ReleaseDC(hwnd, hdc);
}
twinwings의 이미지

c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(126) : error C2146: 구문 오류 : ')'이(가) 'x' 식별자 앞에 없습니다.

c:\documents and settings\the\my documents\visual studio 2008\projects\test16\test16\test16.cpp(126) : error C3861: 'parallel_for': 식별자를 찾을 수 없습니다.

에러부터 보세요.

1. 말했듯, lambda 문법은 C++11 이후 부터 지원합니다. 다시 말하면, VS2011 이후 쓰는게 안전하다는 겁니다.
(물론 그 이전 버전도 C++11 feature 부분지원합니다.)

2 식별자 없다는건 헤더파일이 포함되지 않았을 가능성이 큽니다.
만약 헤더파일 포했했는데도 "unresolved external symbol" 뜬다면 링커에게 라이브러리 위치 알려주세요.

http://vsts2010.tistory.com/119

https://msdn.microsoft.com/ko-kr/library/Dd492418.aspx

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.