Jump to content

About matrix multiplication.


Recommended Posts

Hi, I have three n*n matrices: A, B, and C. They are all real. A and B are symmetrical but C is not.

 

M=AC+CA; and E=BM+MB.

 

Based on the answers of the question before (the one about the M=AC+CA), I think there is no way to make M by one matrix multiplication. Thus I think the generation of E should be two matrix multiplications as well.

 

This matrix multiplication will be carried out once for every loop of the program. Since I found the matrix C is a constant matrix for all the loops, I wonder is there a way that I can make the matrix multiplications once for all the loop, such as E=XC+CX or something like that? Thank you so much.

Link to comment
Share on other sites

Hi, I have three n*n matrices: A, B, and C. They are all real. A and B are symmetrical but C is not.

 

M=AC+CA; and E=BM+MB.

 

Based on the answers of the question before (the one about the M=AC+CA), I think there is no way to make M by one matrix multiplication. Thus I think the generation of E should be two matrix multiplications as well.

 

This matrix multiplication will be carried out once for every loop of the program. Since I found the matrix C is a constant matrix for all the loops, I wonder is there a way that I can make the matrix multiplications once for all the loop, such as E=XC+CX or something like that? Thank you so much.

I'm sorry, I really am not sure what you are saying. You understand that there is no way to write M= AC+ CA as a single multiplication. Are you asking if E as a single "formula"?

 

Certainly that can be done with a little algebra. You have defined M= AC+ CA and then E= BM+MB. Replace M by AC+ CA and you have E= B(AC+CA)+ (AC+ CA)B= BAC+ BCA+ ACB+ CAB. Since matrix multiplication is not, in general, commutative, you will need all four multiplications.

Link to comment
Share on other sites

I'm sorry, I really am not sure what you are saying. You understand that there is no way to write M= AC+ CA as a single multiplication. Are you asking if E as a single "formula"?

 

Certainly that can be done with a little algebra. You have defined M= AC+ CA and then E= BM+MB. Replace M by AC+ CA and you have E= B(AC+CA)+ (AC+ CA)B= BAC+ BCA+ ACB+ CAB. Since matrix multiplication is not, in general, commutative, you will need all four multiplications.

 

Hi HallsofIvy, thank you for your reply. Sorry for the misleading. I agree I have to do all four of the matrix multiplications. I meant the matrix multiplication is carried out in a loop, e.g. i=1,100, and in each step of the loop the matrix multiplication is executed (in this example, the multiplication will be carried out 400 times for a loop). Since I found the matrix C is a constant matrix for all the steps of the loop, I was wondering whether there is a way to carry out the matrix multiplication once for one loop (which means for i=1,100 I only need to carry out the matrix multiplication 4 times or less than 10 times, or something like that). Thank you very much.

Link to comment
Share on other sites

BAC+ BCA+ ACB+ CAB

 

This can be re-written

 

B(AC)+ B(CA)+ (AC)B+ (CA)B

 

and if you save the terms in parenthesis, you should be able to save some extra multiplications there. Matrix multiplication is associative.

 

But, just like your other thread, I don't see the potential for much savings.

Link to comment
Share on other sites

Thank you very much. It seems there is no way to make it happen :-(.

 

Any way, is there a formula that I can calculate the Mflop of the matrix multiplication (if I am using the DGEMM subroutine of Fortran)? All the matrices are (n*n) square matrices. Thank you.

Link to comment
Share on other sites

Sure. You can record the number of CPU clock cycles used, and that should give you the number of flops, but I'm not sure how one does this in Fortran.

 

Thanks, but could you please tell me some more details about how to connect the CPU time with the mflops? I assume there is a formula about the benchmark of matrix-matrix multiplication. Am I right?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.