This is another matrix multiplication project using the BLAS function dgemm. It is complied and run in an Ubuntu system.

The set consists of two programs: (right mouse click. save target or link as)

matrix_mult_cf.cpp

fort_matmul_main.f

The set calculates: C = A*B

The C++ program matrix_mult_cf reads in two matrices, A & B.

The input matrices may each have an arbitrary number of rows and columns up to a certain cell limit. Furthermore, the number of A columns must be equal to the number of B rows.

The matrix_mult_cf program then calls a subroutine from fort_matmul_main to do the matrix multiplication.

The fort_matmul_main subroutine uses dgemm to perform the actual multiplication.

An important feature of this program set is that the C++ and Fortran codes pass the matrices back and forth using 1D arrays. This approach requires some extra steps, but it avoids the complexity of passing 2D arrays, especially if any of the matrices is non-square.

The set is compiled using:

gfortran matrix_mult_cf.cpp fort_matmul_main.f -o mmult_cf -lstdc++ -lblas

The resulting executable code is run as

./mmult_cf

* * *

Tom Irvine

### Like this:

Like Loading...