- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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

Link Copied

5 Replies

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Jim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

MS Visual Studio works fine with Intel Visual Fortran.

Jim

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page