Again about VC++

Again about VC++

Does not seem that anyone paid attention to my previous reques. I am repeating it as a new posting.

Sorry for getting back to an old question. I am not a professional programmer but have to do it occasionally. I was trying to use Lapack from Visual C++. My question is how to declare a two dimensional array in C++ so that it is correctly passed to Fortran. A simple example of a call of a Lapack function would help tremendously. Thanks, Dmitri

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Dmitri,

Thanks for your post. I'm afraid I don't have any exampleson hand of calling LAPACK from C++ with 2 dimensionalarrays. When I call LAPACK from C, I usually use a 1D array. I'll see what I can cook up.

Anyone else have a quick example?

Todd

Thanks. Do you mean that you declared all double arrays as one dimensional and stored them column by column? That's easy.
DmR

Yes. I store matrices in a single dimension arrays with data stored in columns (columns are stored contiguously in Fortran as opposed to the row-major format of C++). The LDA parameter (stands forleading dimension of the matrix A)found in many BLAS and LAPACK functions determines the distance between elements of the same row. LDA thereby imposes the 2D structure of the matrix on the 1 dimensional array.

Todd

Hi Todd,

could you please help me in the following problem. I noticed you could pass arrays to fortan.

thanks

Farid

> In the following code when I pass the array to the fortran code I have a
> problem
> When I change the array in FORTRAN for each entry such as FA(4)=4 I don't
> receive any error messages and it's ok, but when I 'm using loop for
> chaning the content of array such as FA(i)=i*6 or copying FA array to
> another array I'm receiving following error message I've already tried
> __cdecl and __stdcall.
> Could you please tell me your idea about this problem or give me some code
> which work properly on your machine, I have VS 6 and have no problem with
> version of software (In passing single parameters to fortran I have no
> problem).
> I do really appriciate your help and unerstand you are very busy esp in
> these days.
>
>
> Thanks & Regards
> Farid
>
>
>
>
> ERRORs:
> NTR2CALL error LNK2019: unresolved external symbol _ALI@12 referenced in
> function _main
> NTR2CALL fatal error LNK1120: 1 unresolved externals
>
> =====================================================FORTRAN
> SUBROUTINE ALI(a,b,FA)
> Real*8 a,b
> integer i
> Real*8 FA(10)
>
> b=110+a
>
> DO i = 1, 6
> FA(i)=1
> enddo
>
> END SUBROUTINE ALI
> =====================================================VC++
> // external Fortran function prototype
> #include "stdafx.h"
> using namespace std;
> #include "iostream"
>
> extern "C" {void ALI(double&,double&,double*);}
> #pragma comment(lib, "Lib1.lib")
>
> void main()
> {
> double a,b;
> int i=0;
> double FA[10]={1,2,3,4,5,6,7,8,9,10};
> cout<> <<"Enter a"
> <> <> cin>>a;
> ALI(a,b,FA);
>
> cout<> <<"b=a+110= "
> <> <> <> <> for (i=0;i<10;i++)
> {
> cout<<" "<> }
> cout<> <> <> return;
> }
>

Leave a Comment

Please sign in to add a comment. Not a member? Join today