Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

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

Highlighted
##

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

yingwu

Beginner

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

05-06-2010
08:21 AM

17 Views

A simple question

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

Highlighted
##

JenniferJ

Moderator

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

05-07-2010
09:31 AM

17 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

Highlighted
##

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

jimdempseyatthecove

Black Belt

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

05-07-2010
01:35 PM

17 Views

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

Highlighted
##

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

Jim

jimdempseyatthecove

Black Belt

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

05-07-2010
01:40 PM

17 Views

Jim

Highlighted
##

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.

yingwu

Beginner

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

05-10-2010
03:36 AM

17 Views

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

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.

Highlighted
##

>>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

jimdempseyatthecove

Black Belt

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

05-10-2010
08:03 AM

17 Views

MS Visual Studio works fine with Intel Visual Fortran.

Jim

For more complete information about compiler optimizations, see our Optimization Notice.