Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9198543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:18:34+00:00 2026-06-17T22:18:34+00:00

I intend to multiply 2 matrices using the cache-friendly method ( that would lead

  • 0

I intend to multiply 2 matrices using the cache-friendly method ( that would lead to less number of misses)

I found out that this can be done with a cache friendly transpose function.

But I am not able to find this algorithm. Can I know how to achieve this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:18:35+00:00Added an answer on June 17, 2026 at 10:18 pm

    The word you are looking for is thrashing. Searching for thrashing matrix multiplication in Google yields more results.

    A standard multiplication algorithm for c = a*b would look like

    void multiply(double[,] a, double[,] b, double[,] c)
    {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                    C[i, j] += a[i, k] * b[k, j]; 
    }
    

    Basically, navigating the memory fastly in large steps is detrimental to performance. The access pattern for k in B[k, j] is doing exactly that. So instead of jumping around in the memory, we may rearrange the operations such that the most inner loops operate only on the second access index of the matrices:

    void multiply(double[,] a, double[,] B, double[,] c)
    {  
       for (i = 0; i < n; i++)
       {  
          double t = a[i, 0];
          for (int j = 0; j < n; j++)
             c[i, j] = t * b[0, j];
    
          for (int k = 1; k < n; k++)
          {
             double s = 0;
             for (int j = 0; j < n; j++ )
                s += a[i, k] * b[k, j];
             c[i, j] = s;
          }
       }
    }
    

    This was the example given on that page. However, another option is to copy the contents of B[k, *] into an array beforehand and use this array in the inner loop calculations. This approach is usually much faster than the alternatives, even if it involves copying data around. Even if this might seem counter-intuitive, please feel free to try for yourself.

    void multiply(double[,] a, double[,] b, double[,] c)
    {
        double[] Bcolj = new double[n];
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < n; k++)
                Bcolj[k] = b[k, j];
    
            for (int i = 0; i < n; i++)
            {
                double s = 0;
                for (int k = 0; k < n; k++)
                    s += a[i,k] * Bcolj[k];
                c[j, i] = s;
            }
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I intend to create asp.net pages using Visual Studio 2008. Preferably, the pages should
I intend to develop a J2ME application, that should be able to read words
I intend using the Argotic framework in support of a .Net Atom server. Unfortunately
I'm trying out the free tier on Amazon EC2 and intend to host a
I want to create counters in MySQL database that stores the number of views
I have a set of fields that I intend to share between multiple models.
I'm using an NHibernateProvider library I found online, and I want to keep security
I want to have immutable types that can, ideally, sort out their own hashing
Short version: I'm making a DLL that I intend to pass around the department,
I've created a drawing using canvas which I intend to use multiple times for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.