I would like to achieve a speedup for this program. I was wondering how to get started. I was thinking of maybe using pointers. Any hints would be great.

void test()
{
        int i, j, k;
        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];
                        }
                }
        }
}

What is the program solving?

With the current logic, start with i, and see if you can narrow the range, a bit. Then repeat with j, and k.

And what about N? Can it be brought down any?

You should get a boost by redoing your arrays down to all one dimension arrays. You can lose as much in clarity as you gain in faster run-time, however.

Narrowing the range has to be emphatically emphasized. (Lovely alliteration!) ;)

> of maybe using pointers

Wouldn't help. A compiler is smart enough to do that for you. In fact, any code-level optimization will gain you very little.

Looks like you are multiplying matrices. Strasser algorithm is a way to go.

By changing the code to this:

C[i][j] += A[i][k] * B[k][j];

you can reduce accessing memory( or register) by ONE time.

This is the code for multiplying 2 matrices. One of the techniques to improve the code is to exploit the concept of locality - spatial locality in this case. You can keep 'j' as the innermost loop.
Refer this article in Wikipedia - locality for a nice explanation!

firstly define N. you will get error in loop because N is not defined

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.