1 |
heimbach |
1.1 |
subroutine template() |
2 |
|
|
use OAD_cp |
3 |
|
|
use OAD_tape |
4 |
|
|
use OAD_rev |
5 |
|
|
|
6 |
|
|
!$TEMPLATE_PRAGMA_DECLARATIONS |
7 |
|
|
|
8 |
|
|
integer :: cp_loop_variable_1,cp_loop_variable_2, |
9 |
|
|
+ cp_loop_variable_3,cp_loop_variable_4 |
10 |
|
|
|
11 |
|
|
type(modeType) :: our_orig_mode |
12 |
|
|
|
13 |
|
|
integer iaddr |
14 |
|
|
external iaddr |
15 |
|
|
|
16 |
utke |
1.2 |
INTEGER numItersHelper, myThidHelper, nIterMinHelper |
17 |
heimbach |
1.1 |
|
18 |
|
|
Real*8 cg2d_b_p(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
19 |
|
|
Real*8 cg2d_x_p(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
20 |
|
|
|
21 |
|
|
#ifdef OAD_DEBUG_JOINT |
22 |
|
|
character*(80):: indentation=' |
23 |
|
|
+ ' |
24 |
|
|
our_indent=our_indent+1 |
25 |
|
|
|
26 |
|
|
write(standardmessageunit, '(A,A,A)', ADVANCE='NO') |
27 |
|
|
+'OAD:',indentation(1:our_indent), 'enter __SRNAME__:' |
28 |
|
|
call oad_dump_revmod(); call oad_dump_tapestats() |
29 |
|
|
write(standardmessageunit,*) |
30 |
|
|
#endif |
31 |
|
|
if (our_rev_mode%plain) then |
32 |
|
|
#ifdef OAD_DEBUG_JOINT |
33 |
|
|
write(standardmessageunit,'(A,A,A)') |
34 |
|
|
+'OAD:',indentation(1:our_indent), |
35 |
|
|
+' __SRNAME__: entering plain' |
36 |
|
|
#endif |
37 |
|
|
c set up for plain execution |
38 |
|
|
our_orig_mode=our_rev_mode |
39 |
|
|
our_rev_mode%arg_store=.FALSE. |
40 |
|
|
our_rev_mode%arg_restore=.FALSE. |
41 |
|
|
our_rev_mode%plain=.TRUE. |
42 |
|
|
our_rev_mode%tape=.FALSE. |
43 |
|
|
our_rev_mode%adjoint=.FALSE. |
44 |
|
|
#ifdef OAD_DEBUG_JOINT |
45 |
|
|
write(standardmessageunit,'(A,A,A)') |
46 |
|
|
+'OAD:',indentation(1:our_indent), |
47 |
|
|
+' __SRNAME__: runninng plain / down plain' |
48 |
|
|
#endif |
49 |
|
|
cg2d_b_p=cg2d_b%v |
50 |
|
|
cg2d_x_p=cg2d_x%v |
51 |
|
|
call cg2d ( |
52 |
|
|
I cg2d_b_p, |
53 |
|
|
U cg2d_x_p, |
54 |
|
|
O firstResidual, |
55 |
|
|
O minResidualSq, |
56 |
|
|
O lastResidual, |
57 |
|
|
U numIters, |
58 |
|
|
O nIterMin, |
59 |
|
|
I myThid) |
60 |
|
|
cg2d_x%v=cg2d_x_p |
61 |
|
|
c reset the mode |
62 |
|
|
our_rev_mode=our_orig_mode |
63 |
|
|
end if |
64 |
|
|
if (our_rev_mode%tape) then |
65 |
|
|
|
66 |
|
|
numItersHelper=numiters |
67 |
|
|
mythidHelper=mythid |
68 |
utke |
1.2 |
nIterMinHelper=nIterMin |
69 |
heimbach |
1.1 |
#ifdef OAD_DEBUG_JOINT |
70 |
|
|
write(standardmessageunit,'(A,A,A)') |
71 |
|
|
+'OAD:',indentation(1:our_indent), |
72 |
|
|
+' __SRNAME__: entering tape' |
73 |
|
|
#endif |
74 |
|
|
c set up for plain execution |
75 |
|
|
our_orig_mode=our_rev_mode |
76 |
|
|
our_rev_mode%arg_store=.FALSE. |
77 |
|
|
our_rev_mode%arg_restore=.FALSE. |
78 |
|
|
our_rev_mode%plain=.TRUE. |
79 |
|
|
our_rev_mode%tape=.FALSE. |
80 |
|
|
our_rev_mode%adjoint=.FALSE. |
81 |
|
|
#ifdef OAD_DEBUG_JOINT |
82 |
|
|
write(standardmessageunit,'(A,A,A)') |
83 |
|
|
+'OAD:',indentation(1:our_indent), |
84 |
|
|
+' __SRNAME__: runninng plain / down plain' |
85 |
|
|
#endif |
86 |
|
|
cg2d_b_p=cg2d_b%v |
87 |
|
|
cg2d_x_p=cg2d_x%v |
88 |
|
|
call cg2d ( |
89 |
|
|
I cg2d_b_p, |
90 |
|
|
U cg2d_x_p, |
91 |
|
|
O firstResidual, |
92 |
|
|
O minResidualSq, |
93 |
|
|
O lastResidual, |
94 |
|
|
U numIters, |
95 |
|
|
O nIterMin, |
96 |
|
|
I myThid) |
97 |
|
|
cg2d_x%v=cg2d_x_p |
98 |
|
|
c reset the mode |
99 |
|
|
our_rev_mode=our_orig_mode |
100 |
utke |
1.2 |
c manually push integers to the tape: |
101 |
|
|
call oad_tape_push(numItersHelper) |
102 |
|
|
call oad_tape_push(nIterMinHelper) |
103 |
|
|
call oad_tape_push(mythidHelper) |
104 |
heimbach |
1.1 |
end if |
105 |
|
|
if (our_rev_mode%adjoint) then |
106 |
|
|
#ifdef OAD_DEBUG_JOINT |
107 |
|
|
write(standardmessageunit,'(A,A,A)') |
108 |
|
|
+'OAD:',indentation(1:our_indent), |
109 |
|
|
+' __SRNAME__: entering adjoint' |
110 |
|
|
#endif |
111 |
|
|
c manually pop two integers from the tape: |
112 |
utke |
1.2 |
call oad_tape_pop(mythid) |
113 |
|
|
call oad_tape_pop(nIterMin) |
114 |
|
|
call oad_tape_pop(numiters) |
115 |
heimbach |
1.1 |
c selfadjoint: |
116 |
|
|
c the original is called with |
117 |
|
|
c cg2d(b,x,...) |
118 |
|
|
c in the adjoint context if we |
119 |
|
|
c use the same code base |
120 |
|
|
c we call with |
121 |
|
|
c cg2d(x_bar,bh,... |
122 |
|
|
c where afterwards |
123 |
|
|
c b_bar+=bh and x_bar=0 |
124 |
|
|
c the adjoint second formal argument cg2d_x should be |
125 |
|
|
c the values of the first argument: |
126 |
|
|
cg2d_b_p=cg2d_x%d |
127 |
|
|
c the first formal argument cg2d_b should hold |
128 |
|
|
c the increment, i.e. we nullify the second formal |
129 |
|
|
c argument (cg2d_x) value: |
130 |
|
|
cg2d_x_p=0.0 |
131 |
|
|
c set up for plain execution |
132 |
|
|
our_orig_mode=our_rev_mode |
133 |
|
|
our_rev_mode%arg_store=.FALSE. |
134 |
|
|
our_rev_mode%arg_restore=.FALSE. |
135 |
|
|
our_rev_mode%plain=.TRUE. |
136 |
|
|
our_rev_mode%tape=.FALSE. |
137 |
|
|
our_rev_mode%adjoint=.FALSE. |
138 |
|
|
#ifdef OAD_DEBUG_JOINT |
139 |
|
|
write(standardmessageunit,'(A,A,A)') |
140 |
|
|
+'OAD:',indentation(1:our_indent), |
141 |
|
|
+' __SRNAME__: runninng self adjoint / down plain' |
142 |
|
|
#endif |
143 |
|
|
call cg2d ( |
144 |
|
|
I cg2d_b_p, |
145 |
|
|
U cg2d_x_p, |
146 |
|
|
O firstResidual, |
147 |
|
|
O minResidualSq, |
148 |
|
|
O lastResidual, |
149 |
|
|
U numIters, |
150 |
|
|
O nIterMin, |
151 |
|
|
I myThid) |
152 |
|
|
c reset the mode |
153 |
|
|
our_rev_mode=our_orig_mode |
154 |
|
|
c now the adjoint result is the increment |
155 |
|
|
c contained in the second formal argument |
156 |
|
|
cg2d_b%d= cg2d_b%d+cg2d_x_p |
157 |
|
|
cg2d_x%d=0.0 |
158 |
|
|
end if |
159 |
|
|
#ifdef OAD_DEBUG_JOINT |
160 |
|
|
write(standardmessageunit,'(A,A,A)', ADVANCE='NO') |
161 |
|
|
+'OAD:',indentation(1:our_indent), 'leave __SRNAME__:' |
162 |
|
|
call oad_dump_revmod(); call oad_dump_tapestats() |
163 |
|
|
write(standardmessageunit,*) |
164 |
|
|
|
165 |
|
|
our_indent=our_indent-1 |
166 |
|
|
#endif |
167 |
|
|
|
168 |
|
|
end subroutine template |