Community
cancel
Showing results for
Did you mean: Beginner
112 Views

## A simple question

Hi,

Basically, I use FORTRAN for scientific computation. I just get a question how to implement the matrix operations in c++. For example, if I want to multiply two matrix, it is simple in Fortran,

A(2,3)=1
B(3,4)=2

print *, matmul(A,B)

But how to do this in C++? For intel c++ and MKL, could we do this by something like

A*B

??????

Thanks very much.

Ying
5 Replies Moderator
112 Views

Here is the C code:

```[cpp]// matrix multiply routine
void multiply_d(double a[][NUM], double  b[][NUM], double  c[][NUM])
{
int i,j,k;
double temp;
for(i=0;i = c + a * b;
}
}
}
}
[/cpp]```

In the next release of the IntelC++ Compiler, we've added "CEAN" array notation feature. Which will make such type of operationeasier.It will be more close to what you get in Fortran. But it is not released yet.

If you'd like to checkout, you can join the Intel Parallel Studio beta program because the "CEAN" array notation feature is also part of the Intel Parallel Composer 2011 beta.

Jennifer Black Belt
112 Views
Ying

You can also define a class or struct that defines a 2-D or n-D array.
Then for this class you can add operator overloads. Without writing this class for you the implementation would look like

#include "YourArrayClassHere.h"

Array2D A(n,n), B(n,n), C(n,n);

A = 1.0;
B = 2.0;
C = A * B;

for(int row=0; row < A.nrows(); ++row)
for(int col=0; col < A.ncols(); ++col)
A[row][col] = yourFunc();

...

Things like that.

A little web surfing on Google might find you some handy template libraries.

Jim Black Belt
112 Views
Also the std:: class could be used but there are likely more efficient mattrix templates available and specialized for math.

Jim Beginner
112 Views
Hi everyone,

Thanks for your helpful answer. For the matrix operation, I find C++ is not as easy as Fortran. I don't know whether the C++ code can be run as fast as Fortran does either (though I always want to find out). I used Blitz++ before, which uses C++ templates, something like your suggestion. But I have more interest in the 'CEAN' array. I am sure Intel can do something like Blitz++, which I believe a huge contribution to the scientific computation.

Could I ask what it means 'In the next release of the Intel C++ Compiler' for the 'CEAN'? You mean Intel C++ 11.2 or 12.0? When can we enjoy the CEAN array? I am looking forward this.

By the way, I ask question about Intel C++ for scientific computation is that although I am using Fortran and I am really satisfied with Fortran, but it is slow to implement the algorithms because there is no good IDE to support Fortran. This is a pity!

Thanks very much. Black Belt
112 Views
>>By the way, I ask question about Intel C++ for scientific computation is that although I am using Fortran and I am really satisfied with Fortran, but it is slow to implement the algorithms because there is no good IDE to support Fortran. This is a pity!

MS Visual Studio works fine with Intel Visual Fortran.

Jim 