Title: Embedding FORTRAN routines in PGRADE
1Embedding FORTRAN routines in P-GRADE
- Gabor.Hermann_at_sztaki.hu
- www.lpds.sztaki.hu
2Course
- Internal look behind the scene(how FORTRAN and C
use the memory, how codes are compiled and
linked) - Short introduction in C (Kratkij kursz, or C
without tears) - Case study (Example Project to to embed of a
simple Fortran program) - Free discussion/consultation
3Comparation of C and FORTRAN
Memory management Global Memory Recursive
call Pointer usage Linking
- Dynamic
- exteren
- permitted
- explicite
- Simple, identical with FORTRAN
- Static
- COMMON blocks
- prohibited
- implicite
- Simple, identical with C
4int VAR_I, MySize100000 void routine2(int
par) VAR_Imalloc(MySizepar) void
routine1() routine2 (3) int main(int
argc, char argv) routine1() _
5Routine1
int VAR_I, MySize100000 void routine2(int
par) VAR_Imalloc(MySizepar) void
routine1() routine2 (3) int main(int
argc, char argv) routine1() _
Frame pointer
6Routine1
int VAR_I, MySize100000 void routine2(int
par) VAR_Imalloc(MySizepar) void
routine1() routine2 (3) int main(int
argc, char argv) routine1() _
Frame pointer
Routine2
par3
Frame pointer
7VAR_I
Routine1
int VAR_I, MySize100000 void routine2(int
par) VAR_Imalloc(MySizepar) void
routine1() routine2 (3) int main(int
argc, char argv) routine1() _
Frame pointer
Routine2
par3
Frame pointer
Routine2
MySize
8VAR_I
Routine1
int VAR_I, MySize100000 void routine2(int
par) VAR_Imalloc(MySizepar) void
routine1() routine2 (3) int main(int
argc, char argv) routine1() _
Frame pointer
Routine2
MySize
9VAR_I
int VAR_I, MySize100000 void routine2(int
par) VAR_Imalloc(MySizepar) void
routine1() routine2 (3) int main(
int argc, char argv) routine1() _
MySize
10program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I200
Return adress
routine1
jj
ii
11program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I200
Return adress
routine1
jj
iiI
12program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I200
Return adress
routine1
jj3
iiI
13program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I600
Return adress
routine1
jj3
iiI
14program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I600
Return adress
?
routine1
jj3?
iiI
15 COMPILATION UNITC FORTRAN
- File
- GLOBAL DEFEXTERN FUNCTIONS,EXTERN
VARIABLES,
16//File P2.c int global14 int global2 int
f1(int c1, int c2) static int s316
return s3c1 global2c2
//File P1.c extern int f1(int, int) extern int
global1 static int global2 void main(int argc,
char argv) global12 global2 f1(1,2)
17//File P2.c int global14 int global2 int
f1(int c1, int c2) static int s316
return s3c1 global2c2
//File P1.c extern int f1(int, int) extern int
global1 static int global2 void main(int argc,
char argv) global12 global2 f1(1,2)
C FORTRAN
Function f1(c1, c2) common /ize/global1,global2 in
t global1,global2,s3,c1,c2 return
s3c1global2c2 end block data common
/ize/global1,global2 int global1,global2 data
global1/4/ end
Program main common /ize/global1,global2 int
global1,global2,global2own global12 gobal2own
call f1(1,2) end
18//File P2.c int global14 int global2 int
f1(int c1, int c2) static int
s316 return s3c1 global2c2
//File P1.c extern int f1(int, int) extern int
global1 static int global2 void main(int
argc, char argv) global12 global2
f1(1,2)
global1
P1_global2
global2
P2_F1_s3
F1 CODE
MAIN CODE
19(No Transcript)
20Type of input Parameters
Input Parameters
Type of return
21PREPROCESSOR MACROinclude define ifdef ifnde
f else endif
22(No Transcript)
23a.ouot
2
Parameter
24(No Transcript)
25IDENTICAL
26(No Transcript)
27DIFFERENT
28Scalar TYPES
- char
- int
- long int
- long long int
- short int
- float
- double
- pointer
- enum
- char a, be, c 12
- int v 123455
- long int s 10, iN0xFFFFFFFF0FF3
- long long int ss
- short int sI 31128
- float fa 12.345689
- double ff fafafa
- int pI s
- enum gyumolcs alma,korte enum gyumolcs
iLoveIt korte
29(No Transcript)
30COMPOUND TYPES
31COMPOUND TYPES
- Arrays int a3 int b1816
- Structs struct Person char name20 int
age - Unions union Cheat int asInt char
asByte4
32COMPOUND TYPES typedef
- Arrays int a3 int b1816
- Structs struct PersonT char name20 int
age - Unions union Cheat int asInt char
asByte4
typedef char nameT20 typedef struct Person1
nameT name int age struct Person1 father
Person2 struct Person1 Joe Person2
Jim jim (Joe.father)
33COMPOUND TYPES
- Arrays int a3 int b1816
- Structs struct PersonT char name20 int
age - Unions union Cheat int asInt char
asByte4
typedef char nameT20 typedef struct Person1
nameT name int age struct Person1 father
Person2 struct Person1 Joe Person2
Jim jim (Joe.father)
Look like variable declarations, but they are
type types!
34(No Transcript)
35(No Transcript)
36(No Transcript)
37int i, pi, ppi pi i ppi pi ppi
3
3
38(No Transcript)
39LOGICAL FUNCTIONS ! lt lt gt gt
int i3, j5 if ( ( i j) ( j2
gt33) i )
MAKE BOOLEAN FROM NUMERIC OPERANDS
40LOGICAL OPERATORS !
int i3, j5, k ij if ( k
!( j2 gt33) (i k ) )
MAKE BOOLEAN FROM NUMERIC OPERANDS
41for(i0iltsize i ).
i0 do . i
while(ilt(size1))
i0 while(iltsize) . i
42i0 label1 while(iltsize) .
goto label1 . goto label2 i
label 2
i0 while(iltsize) .
continue . break i
43(No Transcript)
44(No Transcript)
45(No Transcript)
46(No Transcript)
47POINTER ARITHMETCS
BA I -gt B AsizeIIB-A -gt I (B
- A)/size
size
A
B
Float r B,A4 r A3 BA3 r B
48(No Transcript)
49(No Transcript)
50(No Transcript)