Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   Fast algorithm for computing matrix multiplication!!!! (http://www.go4expert.com/articles/fast-algorithm-computing-matrix-t8284/)

asadullah.ansari 16Jan2008 16:49

Fast algorithm for computing matrix multiplication!!!!
 
Mostly people are using this algorithm to compute matrix multiplication:

Code: C

#define n 1000
int main()
{
    int a[n][n],b[n][n],c[n][n];
    c[0][0]=0;
    for( i=0;i<n;++i)
    {
        for(j=0;j<n;++j)
        {
            for(k=0;k<n;++k)
            {
                c[i][j] = c[i][j] + a[i][k] * b[k][j]
            }
        }
    }
    return 0;
}

In this program( a short algo) , every time we are taking one element of an array to catche and processing for it. Means At one time cpu reading one element value of a array and b Array and compute and store to c Array.

To reading every time elements from array , why we are taking some group of element i.e. Block size, then no need to read every element. A groups of element will be on catche and we can do fast as given above algo. This algorithm called " Block Algorithm". This Block algorithm can be applied many place where this type of situation will come.

Block Algorithm for Matrix Multiplication:
Code: C

#define n 1000
#define BlockSize  100
int main()
{
    int a[n][n],b[n][n],c[n][n];
    c[0][0]=0;
    for( i1=0;i1<(n/BlockSize);++i1)
    {
        for(j1=0;j1<(n/BlockSize);++j1)
        {
            for(k1=0;k1<(n/BlockSize);++k1)
            {
                for(i=i1=0;i<min(i1+BlockSize-1);++i)
                {
                    for(j=j1=0;j<min(j1+BlockSize-1);++j)
                    {
                        for(k=k1;k<min(k1+BlockSize-1);++k)
                        {               
                            c[i][j] = c[i][j] + a[i][k] * b[k][j]
                        }
                    }
                }
            }
        }
           }
 return 0;
}


debleena_doll2002 8Feb2008 09:40

Re: Fast algorithm for computing matrix multiplication!!!!
 
Yes!!! But can you tell me how's senario of Catche memory here?

shabbir 8Feb2008 14:57

Re: Fast algorithm for computing matrix multiplication!!!!
 
Quote:

Originally Posted by debleena_doll2002
Yes!!! But can you tell me how's senario of Catche memory here?

You can create a thread in the right category and it does not seem the right place.

crazytolearn57 26Feb2008 18:40

Re: Fast algorithm for computing matrix multiplication!!!!
 
i didnt understand

parvez.yu 27Feb2008 12:30

Re: Fast algorithm for computing matrix multiplication!!!!
 
nice

aisha.ansari84 5Mar2008 18:18

Re: Fast algorithm for computing matrix multiplication!!!!
 
i feel its a reall nice way,good one

alramesh 5Mar2008 20:15

Re: Fast algorithm for computing matrix multiplication!!!!
 
i m not getting at all.

alramesh 5Mar2008 20:16

Re: Fast algorithm for computing matrix multiplication!!!!
 
Can you explain more about Block Algorithm?

rahul.mca2001 6Mar2008 13:14

Re: Fast algorithm for computing matrix multiplication!!!!
 
Quote:

Originally Posted by alramesh
Can you explain more about Block Algorithm?

what is Block Algorithm


All times are GMT +5.5. The time now is 16:06.