N
NM
Hi All,
I am having a peculiar problem. I used to link between intel fortran 7.0
and g++ without any problem. Now the intel compiler is upgraded to version
9.0 and I am getting segmenatation fault. While debugging I found when data
structures are allocated in C++ and passed to fortran subroutines the
fortran subroutines are accessing a different location in the address space.
For example I have created a very simple program that shows the problem
The fortran subroutine in the file b.f
subroutine fortran_sub(MAXNODS,NODES)
type node
integer :: order
integer :: father
integer :: sons(3)
double precision :: zdofs(10)
endtype node
type(node) ::NODES(MAXNODS)
integer MAXNODS,i
do i = 1 , MAXNODS
NODES(i)%order = i
NODES(i)%father = i
enddo
return
end
The C++ main function in a.cpp
#include <iostream>
using namespace std;
class node_contiguous_struct {
public:
int order;
int father;
int sons[3];
double zdofs[10];
};
typedef node_contiguous_struct * node_array_contiguous;
extern "C" {
void fortran_sub_(int *MAXNODS,node_array_contiguous NODES);
}
int main(void)
{
node_array_contiguous NODES;
int MAXNODS = 5;
NODES = new node_contiguous_struct[MAXNODS];
fortran_sub_(&MAXNODS,NODES);
for (int i = 0; i < MAXNODS; i++) {
cout << "\nNODES["<<i<<"]\n";
cout << " .order = " << NODES.order;
cout << " .father = " << NODES.father;
}
return 0;
}
and the output of the program
NODES[0]
.order = 1 .father = 1
NODES[1]
.order = 0 .father = 2
NODES[2]
.order = 0 .father = 0
NODES[3]
.order = 0 .father = 0
NODES[4]
.order = 0 .father = 0
Obviously the fortran subroutine is writing somewhere else in the memory
space, thus after the first index everything is messed up. I did not had
this problem with intel fortran compiler version 7. Can this be a compiler
specific problem? Am I doing something wrong here?
Any help is appreciated.
Thanks
NM
I am having a peculiar problem. I used to link between intel fortran 7.0
and g++ without any problem. Now the intel compiler is upgraded to version
9.0 and I am getting segmenatation fault. While debugging I found when data
structures are allocated in C++ and passed to fortran subroutines the
fortran subroutines are accessing a different location in the address space.
For example I have created a very simple program that shows the problem
The fortran subroutine in the file b.f
subroutine fortran_sub(MAXNODS,NODES)
type node
integer :: order
integer :: father
integer :: sons(3)
double precision :: zdofs(10)
endtype node
type(node) ::NODES(MAXNODS)
integer MAXNODS,i
do i = 1 , MAXNODS
NODES(i)%order = i
NODES(i)%father = i
enddo
return
end
The C++ main function in a.cpp
#include <iostream>
using namespace std;
class node_contiguous_struct {
public:
int order;
int father;
int sons[3];
double zdofs[10];
};
typedef node_contiguous_struct * node_array_contiguous;
extern "C" {
void fortran_sub_(int *MAXNODS,node_array_contiguous NODES);
}
int main(void)
{
node_array_contiguous NODES;
int MAXNODS = 5;
NODES = new node_contiguous_struct[MAXNODS];
fortran_sub_(&MAXNODS,NODES);
for (int i = 0; i < MAXNODS; i++) {
cout << "\nNODES["<<i<<"]\n";
cout << " .order = " << NODES.order;
cout << " .father = " << NODES.father;
}
return 0;
}
and the output of the program
NODES[0]
.order = 1 .father = 1
NODES[1]
.order = 0 .father = 2
NODES[2]
.order = 0 .father = 0
NODES[3]
.order = 0 .father = 0
NODES[4]
.order = 0 .father = 0
Obviously the fortran subroutine is writing somewhere else in the memory
space, thus after the first index everything is messed up. I did not had
this problem with intel fortran compiler version 7. Can this be a compiler
specific problem? Am I doing something wrong here?
Any help is appreciated.
Thanks
NM