This project is read-only.

Summation of Matrix elements

Sep 13, 2014 at 12:41 AM
Edited Sep 13, 2014 at 2:56 AM
Dear all

I want to know how I can get the summation of matrix elements for this sequential code:
int ClassesCount = 5;
int ObjectCount = 1000;

double [,] MatrixU= new double[ObjectCount  , ClassesCount ];

double [] ClassSum=new double[ClassesCount ];

void Fun()
for(int i = 0 ;i< ObjectCount ;i++ )
      for(int j = 0; j<ClassesCount ; j++)
           ClassSum[j] +=MatrixU[i , j];
Supposing that matrix filled before calling function from the main

could any one give solution for this example ?
many thanks in advance
Sep 14, 2014 at 2:24 AM
Dear all

I found the solution by using thread.atomicAdd function, but is this function support float or double variables ??

because it is work fine with integer and give this error when I use for float
(33): error: no instance of overloaded function "atomicAdd" matches the argument list
        argument types are: (float *, float)

I hope any one can give help for this and make this function support double variables it will be so helpful.

I will post the code soon ^_^