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

  • SEARCH
  • Home
  • 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 7663437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T14:03:42+00:00 2026-05-31T14:03:42+00:00

I have a program for multiplication of square matrices. It also, I think the

  • 0

I have a program for multiplication of square matrices. It also, I think the program’s performance by the formula (number of operations) / (run time). Why is the growth dimension of the matrix decreases performance? Thanks.

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sys/time.h>
using namespace std;

 double getsec(){
   struct timeval t;
  gettimeofday(&t,NULL);
   return t.tv_sec+t.tv_usec*0.000001;
}

int main(int argc, char* argv[])
{
double begintime=getsec();

int n;
if(argc==2)n=atoi(argv[1]);
else n=3;

int**a=new int*[n];
double**b=new double*[n];
double**c=new double*[n];
for (int i=0;i<n;i++){
    a[i]=new int [n];
    b[i]=new double [n];
    c[i]=new double [n];
}

for (int i=0;i<n;i++)
    for(int j=0;j<n;j++){
        a[i][j]=i+1;
        b[i][j]=1/(j+1.);
        c[i][j]=0;
    }

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];

double qty_of_operations = (double)2*n*n*n;

cout<<n<<"  c11="<<c[0][0]<<"  c1n="<<c[0][n-1]<<"  cn1="<<c[n-1][0]<<"  cnn="<<c[n-1][n-1]<<"  "<<qty_of_operations/(getsec()-begintime)<<endl;
return 0;

}

  • 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-05-31T14:03:43+00:00Added an answer on May 31, 2026 at 2:03 pm

    I think you are asking why the average number of floating-point operations per second (FLOPS) decreases as the matrix size increases.

    The answer is: cache. The “naive” approach to matrix multiplication that you are using is terrible for cache performance; as the matrix grows you will be increasing the number of cache misses.

    If you’re determined to write this yourself (rather than using an extant linear-algebra library), you should investigate “blocking”, also known as “loop tiling”. See e.g. http://en.wikipedia.org/wiki/Loop_tiling. The basic idea is that you break the operation up into smaller blocks that correspond to your cache size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that uses pthread library to do the matrix multiplication of
I have program that runs fast enough. I want to see the number of
I have a program that uses the mt19937 random number generator from boost::random. I
I have the following program that generates a multiplication table. A formatting problem arises
I have program consisting of a number of classes. I have a problem with
I have program that constantly query a mysql server. Each time I access the
I am trying to run a program that asks for a number and the
I am making a simple program which abstracts complex numbers and complex number operations.
I have program that the number of classes loaded there is constantly rising. How
I have a C program that has n multiplications (single multiplication with n iterations)

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.