Embedding FORTRAN routines in PGRADE - PowerPoint PPT Presentation

1 / 50
About This Presentation
Title:

Embedding FORTRAN routines in PGRADE

Description:

int main(int argc, char *argv[]) routine1(): Statc memory. Stack Pointer. Heep Pointer ... int main( int argc, char *argv[]) routine1(): program main. integer i ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 51
Provided by: herm155
Category:

less

Transcript and Presenter's Notes

Title: Embedding FORTRAN routines in PGRADE


1
Embedding FORTRAN routines in P-GRADE
  • Gabor.Hermann_at_sztaki.hu
  • www.lpds.sztaki.hu

2
Course
  • 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

3
Comparation 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

4
int VAR_I, MySize100000 void routine2(int
par) VAR_Imalloc(MySizepar) void
routine1() routine2 (3) int main(int
argc, char argv) routine1() _
5
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
6
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
7
VAR_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
8
VAR_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
9
VAR_I
int VAR_I, MySize100000 void routine2(int
par) VAR_Imalloc(MySizepar) void
routine1() routine2 (3) int main(
int argc, char argv) routine1() _
MySize
10
program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I200
Return adress
routine1
jj
ii
11
program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I200
Return adress
routine1
jj
iiI
12
program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I200
Return adress
routine1
jj3
iiI
13
program main integer ii200call
routine1(i) end subroutine routine1(ii) integer
ii,jj jj3 ii iijj return end
Main
I600
Return adress
routine1
jj3
iiI
14
program 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
  • SUBROUTINE
  • 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)
20
Type of input Parameters
Input Parameters
Type of return
21
PREPROCESSOR MACROinclude define ifdef ifnde
f else endif
22
(No Transcript)
23
a.ouot
2
Parameter
24
(No Transcript)
25
IDENTICAL
26
(No Transcript)
27
DIFFERENT
28
Scalar 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)
30
COMPOUND TYPES
  • Arrays
  • Structs
  • Unions

31
COMPOUND TYPES
  • Arrays int a3 int b1816
  • Structs struct Person char name20 int
    age
  • Unions union Cheat int asInt char
    asByte4

32
COMPOUND 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)
33
COMPOUND 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)
37
int i, pi, ppi pi i ppi pi ppi
3
3
38
(No Transcript)
39
LOGICAL FUNCTIONS ! lt lt gt gt
int i3, j5 if ( ( i j) ( j2
gt33) i )
MAKE BOOLEAN FROM NUMERIC OPERANDS
40
LOGICAL OPERATORS !
int i3, j5, k ij if ( k
!( j2 gt33) (i k ) )

MAKE BOOLEAN FROM NUMERIC OPERANDS
41
for(i0iltsize i ).
i0 do . i
while(ilt(size1))
i0 while(iltsize) . i
42
i0 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)
47
POINTER 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)
Write a Comment
User Comments (0)
About PowerShow.com