Nu pot sa creez obiecte array_view

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
Kavarna
Junior
Junior
Posts: 11
Joined: 20 Sep 2015, 19:14
Judet: Neamţ

Nu pot sa creez obiecte array_view

Post by Kavarna » 16 Feb 2016, 20:46

Am incercat sa fac primul program in care folosesc AMP.

Code: Select all

#include <amp.h>
#include <iostream>
#include <algorithm>

using namespace concurrency;

void perform_calculation(std::vector<int>& vA, std::vector<int>&vB,
	std::vector<int>vC, int M, int N)
{
	extent<2> e(M, N);
	array_view<int, 2> a(e, vA); // the program stops here
	array_view<int, 2> b(e, vB);
	array_view<int, 2> c(e, vC);
	c.discard_data();
	index<2> idx(0, 0);


	parallel_for_each(e,
		[=](index<2> idx)restrict(amp)
	{
		c[idx] = a[idx] + b[idx];
	});
	c.synchronize();
}

void do_it()
{
	const int M = 1024;
	const int N = 1024;

	std::vector<int> vA(M * N);
	std::vector<int> vB(M * N);

	int i = 0;
	std::generate(vA.begin(), vA.end(), [&] {return i++; });
	std::generate(vB.begin(), vB.end(), [&] {return i--; });

	std::vector<int> vC(M * N);

	perform_calculation(vA, vB, vC, M, N);
}

int main()
{
	do_it();

	std::cout << "Hit any key to exit..." << std::endl;
	std::cin.get();

}
Programul de mai sus poate fi compilat, dar nu-l pot rula. De ficare data cand incerc sa-l rulez imi apare exceptia de mai jos.
Image
Programul se blocheaza atunci cand incerc sa creez un obiect array_view.



Viorel
Microsoft MVP
Microsoft MVP
Posts: 292
Joined: 13 Jul 2007, 12:26

Re: Nu pot sa creez obiecte array_view

Post by Viorel » 17 Feb 2016, 09:16

Încearcă configurația „Release”.

Kavarna
Junior
Junior
Posts: 11
Joined: 20 Sep 2015, 19:14
Judet: Neamţ

Re: Nu pot sa creez obiecte array_view

Post by Kavarna » 17 Feb 2016, 18:07

Viorel wrote:Încearcă configurația „Release”.
Nu cred ca m-as fi gandit sa incerc asa ceva.
Mersi mult!

nedo
Junior
Junior
Posts: 32
Joined: 14 Oct 2011, 20:18
Judet: Bucureşti

Re: Nu pot sa creez obiecte array_view

Post by nedo » 20 Feb 2016, 13:20

Din ce vad, std::extent are alt constructor, esti sigur ca il folosesti corect? http://en.cppreference.com/w/cpp/types/extent

Kavarna
Junior
Junior
Posts: 11
Joined: 20 Sep 2015, 19:14
Judet: Neamţ

Re: Nu pot sa creez obiecte array_view

Post by Kavarna » 20 Feb 2016, 13:58

nedo wrote:Din ce vad, std::extent are alt constructor, esti sigur ca il folosesti corect? http://en.cppreference.com/w/cpp/types/extent
E, de fapt, concurrency::extent.

Post Reply