| New Reply |
help with cblas_dgemm matrix multiplication |
Share Thread | Thread Tools |
| Dec5-12, 12:42 PM | #1 |
|
|
help with cblas_dgemm matrix multiplication
I'm having problems running cblas_dgemm on a matix matrix multiplication.
I have the following matricies Code:
double * mass = new double[n]; double (* pos)[NDIM] = new double[n][NDIM]; double tempPos[NDIM]; double tempMass[nlocal]; double mass_avg[1]; double pos_avg[NDIM]; 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: Code:
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, 1, 1, nlocal, 1.0, mass, nlocal, tempMass, 1, 1.0, m_ave, 1); Code:
cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, nlocal, 1, NDIM, 1.0, pos[0], NDIM, tempPos, 1, 0.0, pos_ave, 1); |
| Dec5-12, 05:39 PM | #2 |
|
Mentor
|
Do you understand what each parameter represents? |
| Dec5-12, 10:50 PM | #3 |
|
|
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. |
| Dec6-12, 09:12 AM | #4 |
|
Mentor
|
help with cblas_dgemm matrix multiplicationThe same goes for all of your other one-dimension 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. Code:
double (* pos)[NDIM] = new double[n][NDIM]; If you change the declaration above to the following, I think that will fix your problem. Code:
double (* pos)[NDIM] = new double[NDIM][n]; Code:
double pos[NDIM][n]; |
| Dec6-12, 09:48 AM | #5 |
|
|
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! |
| Dec6-12, 01:56 PM | #6 |
|
Mentor
|
If pos is a matrix with 303 rows, and 3 columns per row, then it should be declared in either of these ways:
Code:
double pos[n][NDIM]; // Uninitialized matrix allocated on stack. OR double (*pos)[n] = new double[n][NDIM]; // Uninitialized matrix allocated on heap. Code:
double (* pos)[NDIM] = new double[n][NDIM]; 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 |
| Dec6-12, 11:32 PM | #7 |
|
|
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.
|
| Dec7-12, 12:32 AM | #8 |
|
Mentor
|
Glad I could help out.
|
| New Reply |
| Thread Tools | |
Similar Threads for: help with cblas_dgemm matrix multiplication
|
||||
| Thread | Forum | Replies | ||
| 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 | ||