- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear all,
Iam working on linpack benchmark where in i need to supply a high resolution timer function. The intrinsic function second() does not provide the required resolution. So i had to use a function based on gettimeofday() function. The function was written in C and was compiled using gcc to create a *.o file.
The fortran program was modified to use the call the c functions binary object. All was working fine except that when the function is called it returns some weird results in the main program but the function itself seems OK.
I am attaching the code and the results here.
FORTRAN CODE:
c The program simulates the linpack second function call at its simplest form.
c The linpack code cannot be changed in any form as it is said in the site
c
PROGRAM b2
double precision :: t1,t2
t1=second1()
c
c DO SOME JOB
c
c elapsed_time =second1() - t1
c print elapsed_time
c
print *,"FORTRAN: MAIN CALL:",t1
END
c
c END OF PROGRAM b2
c
double precision function second1()
implicit none
external mysecond
double precision :: v1,v2
c making a call to the external c function
call mysecond(v1)
v2=v1
second1=v2
print *,"FORTRAN: AT FUNCTION CALL:",v1
print *,"FORTRAN: CHECK ASSIGNMENT:",v2
RETURN
end
C CODE:
#include
#include
#include time.h>
double mysecond_(double *val)
{
struct timeval tv;
gettimeofday(&tv, NULL);
*val = tv.tv_sec + tv.tv_usec / 1.e6;
printf("VALUE FROM C:%f ",*val);
}
RESULT OBTAINED:
[root@master tests]# ifort b2.f mysecond.o
[root@master tests]# ./a.out
VALUE FROM C:63937.754206
FORTRAN: AT FUNCTION CALL: 63937.7542060000
FORTRAN: CHECK ASSIGNMENT: 63937.7542060000
FORTRAN: MAIN CALL: 3.315236911126272E-018
[root@master tests]# ./a.out
VALUE FROM C:63945.945295
FORTRAN: AT FUNCTION CALL: 63945.9452950000
FORTRAN: CHECK ASSIGNMENT: 63945.9452950000
FORTRAN: MAIN CALL: 1.71327996253967
------------------------------------------------------------
The value from the C program is returned to the Fortran function successfully but not to the main program that is calling the function. What could be the problem?
Regards
Bala
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

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