Register to reply 
Help with cblas_dgemm matrix multiplication 
Share this thread: 
#1
Dec512, 12:42 PM

P: 194

I'm having problems running cblas_dgemm on a matix matrix multiplication.
I have the following matricies
and multiple pos * tempPos and put it in pos_avg nlocal is less than n and it needs to multiple up to nlocal rows not n I'm using the following call for mass and it works as expected:



#2
Dec512, 05:39 PM

Mentor
P: 21,249

Do you understand what each parameter represents? 


#3
Dec512, 10:50 PM

P: 194

I understand what the parameters mean. I just don't see what I'm doing wrong. I have checked all of the meanings multiple times and the values I'm passing.
the mass matrix is n (303) x 1 pos is n(303) x NDIM (3) tempPos is NDIM x 1 tempMass is nlocal(300) x 1 mass_avg is 1x1 pos_avg is NDIM(3) x 1 n is actually 3 more than nlocal. I included all of the values up above. I don't think I'm passing any of the values in wrong which is why I'm so confused. 


#4
Dec612, 09:12 AM

Mentor
P: 21,249

Help with cblas_dgemm matrix multiplication
The same goes for all of your other onedimension arrays, including tempPos, tempMass, and pos_avg. I don't know why you made mass_avg an array, since it has only one element, but what you did seems to have worked for you. An alternate way to do things would be to declare mass_ave as a double, and then just pass &mass_ave as a parameter.
If you change the declaration above to the following, I think that will fix your problem.



#5
Dec612, 09:48 AM

P: 194

all of the arrays i said the dimensions for are in row major or are supposed to be. I can't change the pos array dimensions or the rest of the program will break. It's written by someone else as a simulation and is pretty long, i'm just adding averages and a couple other things to it.
I can change anything besides the mass and pos arrays. The position matrix should be 303 rows by 3 columns. Am I doing the call to dgemm right in this situation? I didn't realize I could pass in a double for mass in that way, thanks for letting me know! 


#6
Dec612, 01:56 PM

Mentor
P: 21,249

If pos is a matrix with 303 rows, and 3 columns per row, then it should be declared in either of these ways:
From what you have already said, you want to do this multiplication  pos * tempPos  and store the result in pos_avg. pos is 303 x 3, tempPos is 3 x 1, so the product will be 303 x 1, not 3 x 1 as you have for pos_avg. You need to declar tempPos to be the right size: double pos_avg[303]. I also think that a couple of the parameters in your call to cblas_dgemm are not right. Parameters 1, 2, and 3 are OK, I think. The following applies to parameters 4 through 12. 4. nlocal = #rows in A matrix == this should be n (303), not nlocal (300) 5. 1 = #cols in B == OK 6. NDIM = #cols in A == OK 7. 1.0  a scalar == OK, I guess. I don't know what this is for. 8. pos[0]The array for A == OK, once you get your array declared right. 9. NDIM = stride for A == OK. The stride is the number of elements per row. 10.tempPos = The array for B == OK 11. 1 = stride for B == OK 12. 0.0  scalar to multiply by == ?? Seems like it should be 1.0 13. pos_ave = the array for C == OK 14. 1 = stride for C == OK 


#7
Dec612, 11:32 PM

P: 194

Thanks for the help, I appreciate you spending time on trying to figure this out. I ended up figuring out that the pos matrix needed to be translated so the second parameter was CblasTrans and I needed to make tempPos larger and it worked.



#8
Dec712, 12:32 AM

Mentor
P: 21,249

Glad I could help out.



Register to reply 
Related Discussions  
Proof Involving Matrix Polynomials and Matrix Multiplication  Calculus & Beyond Homework  7  
System under matrix addition (+) and matrix multiplication (.) is a field  Introductory Physics Homework  1  
Matrix Multiplication and Rank of Matrix  General Math  2  
Matrix multiplication preserve order Block matrix  Linear & Abstract Algebra  2  
Matrix Multiplication and Algebraic Properties of Matrix Operations  Calculus & Beyond Homework  2 