Quantcast
Channel: Parallel Computing in C++ and Native Code forum
Viewing all articles
Browse latest Browse all 856

c++ amp - vector multiplication problem - optimization with big arrays (bottom post)

$
0
0

hi,
i was wandering if you could help me with my C++ amp code. I want to parallel the multiplication of vector and matrix. Here is my code

#include <amp.h>

using namespace std;
using namespace concurrency;

int _tmain(int argc, _TCHAR* argv[])

int n;
    cin>> n;
double **A = new double*[n];
    for(int i = 0; i < n; ++i) {
        A[i] = new double[n];
    }

for (int i = 0; i < n ; ++ i)
        for (int j = 0; j < n; ++ j){

            A[i][j]=rand()%100;
            A[j][i]=A[i][j];

        }

for( int i=0; i < n; i++)
            x[i]=0;
        double *ri = new double[n];
        for( int i=0; i < n; i++)
            ri[i]=0;
        double *ri1 = new double[n];

array_view<const double, 2> a(n, n, A);
array_view<const double, 1> X(n, x);
array_view<double, 1> RI(n, ri);
    RI.discard_data();
parallel_for_each(
    RI.extent,
    [=] (index<1> idx) restrict(amp) {
        int y = idx[0];

    double result = 0.0f;
            for (int k=0; k<n; k++) {
                result += a(y, k) * X(k); }
            RI[idx] = result;
});
RI.synchronize();


This, however, does raise the errors C2228 and C2338, which I've not been able to resolve so far.

Thank you in advance!
Regards,
Bartosz






Viewing all articles
Browse latest Browse all 856

Latest Images

Trending Articles



Latest Images