loveislonely Posted July 8, 2008 Posted July 8, 2008 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.
Country Boy Posted July 9, 2008 Posted July 9, 2008 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.
loveislonely Posted July 10, 2008 Author Posted July 10, 2008 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.
Bignose Posted July 10, 2008 Posted July 10, 2008 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.
loveislonely Posted July 11, 2008 Author Posted July 11, 2008 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.
Dave Posted July 12, 2008 Posted July 12, 2008 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.
loveislonely Posted July 13, 2008 Author Posted July 13, 2008 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now