Dear All,
I have the following problem:
main program in fortran and an external module in C++ (see below). I would like to build them together in pgi compiler. Any suggestion?
In gnu compiler I do:
gfortran -c -fcray-pointer -O3 main.for
g++ -c ext_lib.cpp
gfortran -o load_lib.exe *.o -lstdc++
Barak
Fortran code:
PROGRAM load_lib
!This program
IMPLICIT NONE
INTEGER seq(0:9)
INTEGER n
INTEGER l
INTEGER8 pn
POINTER (pn, l)
! real8,DIMENSION(2) :: Az_min_max
print*
print*,'seq = ’
do n = 0, 9, 1
seq(n) = n
print*,seq(n)
end do
print*, ‘Calling external module…’
print*
print*, ‘---------- external modulde output start ----------’
print*
n = 10
pn = loc(n)
CALL external_processing(seq, n, pn)
print*
print*, ‘---------- external modulde output end ----------’
print*
500 print*,‘Done’
print*,'seq = ’
do n = 0, 9, 1
print*,seq(n)
end do
print*
END PROGRAM load_lib
-----------------------------> end of Fortran code <--------------------------
C++ code module: ---->
#include <stdio.h>
#include
#include
#include
#include <math.h>
template
class VectorOps
{
public:
VectorOps() {};
VectorOps(int len)
{
setLength(len);
}
void setLength(int len)
{
_len = len;
std::cout << std::dec << " VectorOps::setLength():: length set to: " << _len << std::endl;
}
VectorOps& operator <<(T *);
VectorOps& operator >>(T *);
void inc();
void sqr();
protected:
int _len;
std::vector _data;
};
template
VectorOps& VectorOps::operator <<(T* input_seq)
{
for(int i = 0; i < _len; i++) {
data.push_back(input_seq);
}
std::cout << " input sequnce received" << std::endl;
return this;
}
template
VectorOps& VectorOps::operator >>(T output_seq)
{
for(int i = 0; i < _len; i++) {
output_seq = _data;
}
std::cout << " output sequnce transmitted" << std::endl;
return *this;
}
template
void VectorOps::inc()
{
for(int i = 0; i < _len; i++) {
_data++;
}
std::cout << " stored sequence incremented" << std::endl;
}
template
void VectorOps::sqr()
{
for(int i = 0; i < _len; i++) {
data = pow(data, 2);
}
std::cout << " stored sequence squared" << std::endl;
}
extern “C”
{
void external_processing(int *seq, int *n, int **pn)
{
std::cout << " library function received " << std::hex <<
(long) n <<
" " << (long) (*pn) <<
std::endl;
VectorOps vo(*n);
vo << seq;
vo.inc();
vo.sqr();
vo >> seq;
}
}