Can some one suggest best way to calculate the huge matrix.

Example:

const  int NUMPAT = 1212;
 const  int NUMIN  = 6;
 
 const   int NUMHID1= 13;
 const   int NUMHID2 =15;
 const   int NUMOUT = 12;

#define rando() ((double)rand()/(RAND_MAX+1))

Below are-----

double Input[NUMPAT+1][NUMIN+1];
    double Target[NUMPAT+1][NUMOUT+1];
    double SumH1[NUMPAT+1][NUMHID1+1], WeightIH1[NUMIN+1][NUMHID1+1], Hidden1[NUMPAT+1][NUMHID1+1];
    double SumH2[NUMPAT+1][NUMHID2+1], WeightH1H2[NUMHID1+1][NUMHID2+1], Hidden2[NUMPAT+1][NUMHID2+1];
    double SumO[NUMPAT+1][NUMOUT+1], WeightH2O[NUMHID2+1][NUMOUT+1], Output[NUMPAT+1][NUMOUT+1];
    double DeltaO[NUMOUT+1],SumDOW1[NUMHID1+1],SumDOW2[NUMHID2+1],DeltaH1[NUMHID1+1],DeltaH2[NUMHID2+1];
    double DeltaWeightIH1[NUMIN+1][NUMHID1+1],DeltaWeightH1H2[NUMHID1+1][NUMHID2+1],DeltaWeightH2O[NUMHID2+1][NUMOUT+1];

Operations required to do on those matrices are:
1) Processing the values of huge matrix and calculating results.
2) Multiplication of two matrices.
3) Adding or subtracting matrices to matrices

Of course, all the matrices size could be same.

Create a recursive solution where it creates N/M by N/M subchunks where N > M and N % M == 0, and creates a separate thread to calculate the product of the two matrix using LU decomposition, and and uses that result for the parent subchunk.

Other than that, use a external library that has the calculation features that you need already and that could potentially take into account the architecture for optimization.

I can help you of how you can do multiplication to two matrices ....
ther first matrix for example :
matrix1 size is :p*q
matrix2 size is :q*r
to mulitiply the two matrices you must satisfy the condition (i.e the size of the column of the first matrix is must be equal to the size of the raw of the second matrix )
then :
for(int i=0;i<p;i++){
for(int j=0;j<r;j++)
{
mult[j]=0;
for(int k=0;k<q;k++)
mult[j]+=matrix1[k]*matrix2[k][j]
}
}
}//end of the main for

First things first, don't store matrices as arrays of arrays. You need to store them contiguously, i.e., you make one big linear array and store either one column after another (column-major) or one row after another (row-major). Storing arrays of arrays is very inefficient in general.

Second, save yourself the trouble and get an off-the-shelf library for doing this. There are tons of those, from very old but significantly tested and robust (like LAPACK), to very new and sophisticated programming-wise (like Blitz++), to architecturally optimized, to GPU-based, to parallel computation-based. There are also libraries that specialize for sparse matrices or very large matrices (and btw, your matrices wouldn't really qualify as "huge", more like "not small"). Pick your choice.

Finally, if all you need is to multiply / add / subtract matrices, then these functions are really simple (like the code by monjed above), it's a trivial matter of a few nested for-loops to implement those operations.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.