| 1 |
C ========== begin copyright notice ============== |
| 2 |
C This file is part of |
| 3 |
C --------------- |
| 4 |
C xaifBooster |
| 5 |
C --------------- |
| 6 |
C Distributed under the BSD license as follows: |
| 7 |
C Copyright (c) 2005, The University of Chicago |
| 8 |
C All rights reserved. |
| 9 |
C |
| 10 |
C Redistribution and use in source and binary forms, |
| 11 |
C with or without modification, are permitted provided that the following conditions are met: |
| 12 |
C |
| 13 |
C - Redistributions of source code must retain the above copyright notice, |
| 14 |
C this list of conditions and the following disclaimer. |
| 15 |
C - Redistributions in binary form must reproduce the above copyright notice, |
| 16 |
C this list of conditions and the following disclaimer in the documentation |
| 17 |
C and/or other materials provided with the distribution. |
| 18 |
C - Neither the name of The University of Chicago nor the names of its contributors |
| 19 |
C may be used to endorse or promote products derived from this software without |
| 20 |
C specific prior written permission. |
| 21 |
C |
| 22 |
C THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY |
| 23 |
C EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 24 |
C OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT |
| 25 |
C SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 26 |
C INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 27 |
C PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 28 |
C INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 29 |
C LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 |
C OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
C |
| 32 |
C General Information: |
| 33 |
C xaifBooster is intended for the transformation of |
| 34 |
C numerical programs represented as xml files according |
| 35 |
C to the XAIF schema. It is part of the OpenAD framework. |
| 36 |
C The main application is automatic |
| 37 |
C differentiation, i.e. the generation of code for |
| 38 |
C the computation of derivatives. |
| 39 |
C The following people are the principal authors of the |
| 40 |
C current version: |
| 41 |
C Uwe Naumann |
| 42 |
C Jean Utke |
| 43 |
C Additional contributors are: |
| 44 |
C Andrew Lyons |
| 45 |
C Peter Fine |
| 46 |
C |
| 47 |
C For more details about xaifBooster and its use in OpenAD please visit: |
| 48 |
C http://www.mcs.anl.gov/openad |
| 49 |
C |
| 50 |
C This work is partially supported by: |
| 51 |
C NSF-ITR grant OCE-0205590 |
| 52 |
C ========== end copyright notice ============== |
| 53 |
subroutine template() |
| 54 |
use OAD_tape |
| 55 |
use OAD_rev |
| 56 |
use OAD_cp |
| 57 |
|
| 58 |
|
| 59 |
! original arguments get inserted before version |
| 60 |
! and declared here together with all local variables |
| 61 |
! generated by xaifBooster |
| 62 |
|
| 63 |
!$TEMPLATE_PRAGMA_DECLARATIONS |
| 64 |
|
| 65 |
|
| 66 |
! checkpointing stacks and offsets |
| 67 |
integer :: cp_loop_variable_1,cp_loop_variable_2, |
| 68 |
+cp_loop_variable_3,cp_loop_variable_4 |
| 69 |
! floats 'F' |
| 70 |
double precision, dimension(:), allocatable, save :: |
| 71 |
+theArgFStack |
| 72 |
integer, save :: theArgFStackoffset=0, theArgFStackSize=0 |
| 73 |
double precision, dimension(:), allocatable, save :: |
| 74 |
+theResFStack |
| 75 |
integer, save :: theResFStackoffset=0, theResFStackSize=0 |
| 76 |
! integers 'I' |
| 77 |
integer, dimension(:), allocatable, save :: |
| 78 |
+theArgIStack |
| 79 |
integer, save :: theArgIStackoffset=0, theArgIStackSize=0 |
| 80 |
integer, dimension(:), allocatable, save :: |
| 81 |
+theResIStack |
| 82 |
integer, save :: theResIStackoffset=0, theResIStackSize=0 |
| 83 |
! booleans 'B' |
| 84 |
logical, dimension(:), allocatable, save :: |
| 85 |
+theArgBStack |
| 86 |
integer, save :: theArgBStackoffset=0, theArgBStackSize=0 |
| 87 |
logical, dimension(:), allocatable, save :: |
| 88 |
+theResBStack |
| 89 |
integer, save :: theResBStackoffset=0, theResBStackSize=0 |
| 90 |
! strings 'S' |
| 91 |
character*(80), dimension(:), allocatable, save :: |
| 92 |
+theArgSStack |
| 93 |
integer, save :: theArgSStackoffset=0, theArgSStackSize=0 |
| 94 |
character*(80), dimension(:), allocatable, save :: |
| 95 |
+theResSStack |
| 96 |
integer, save :: theResSStackoffset=0, theResSStackSize=0 |
| 97 |
|
| 98 |
type(modeType) :: our_orig_mode |
| 99 |
|
| 100 |
! call external C function used in inlined code |
| 101 |
integer iaddr |
| 102 |
external iaddr |
| 103 |
|
| 104 |
if (our_rev_mode%arg_store) then |
| 105 |
C print*, " arg_store ", our_rev_mode |
| 106 |
C store arguments |
| 107 |
!$PLACEHOLDER_PRAGMA$ id=4 |
| 108 |
end if |
| 109 |
if (our_rev_mode%arg_restore) then |
| 110 |
C print*, " arg_restore", our_rev_mode |
| 111 |
C restore arguments |
| 112 |
!$PLACEHOLDER_PRAGMA$ id=6 |
| 113 |
end if |
| 114 |
if (our_rev_mode%plain) then |
| 115 |
C print*, " plain ", our_rev_mode |
| 116 |
our_orig_mode=our_rev_mode |
| 117 |
our_rev_mode%arg_store=.FALSE. |
| 118 |
C original function |
| 119 |
!$PLACEHOLDER_PRAGMA$ id=1 |
| 120 |
our_rev_mode=our_orig_mode |
| 121 |
end if |
| 122 |
if (our_rev_mode%tape) then |
| 123 |
C print*, " tape ", our_rev_mode |
| 124 |
our_rev_mode%arg_store=.TRUE. |
| 125 |
our_rev_mode%arg_restore=.FALSE. |
| 126 |
our_rev_mode%res_store=.FALSE. |
| 127 |
our_rev_mode%res_restore=.FALSE. |
| 128 |
our_rev_mode%plain=.TRUE. |
| 129 |
our_rev_mode%tape=.FALSE. |
| 130 |
our_rev_mode%adjoint=.FALSE. |
| 131 |
C taping |
| 132 |
!$PLACEHOLDER_PRAGMA$ id=2 |
| 133 |
our_rev_mode%arg_store=.FALSE. |
| 134 |
our_rev_mode%arg_restore=.FALSE. |
| 135 |
our_rev_mode%res_store=.FALSE. |
| 136 |
our_rev_mode%res_restore=.FALSE. |
| 137 |
our_rev_mode%plain=.FALSE. |
| 138 |
our_rev_mode%tape=.FALSE. |
| 139 |
our_rev_mode%adjoint=.TRUE. |
| 140 |
end if |
| 141 |
if (our_rev_mode%res_restore) then |
| 142 |
C restore results |
| 143 |
!$PLACEHOLDER_PRAGMA$ id=7 |
| 144 |
end if |
| 145 |
if (our_rev_mode%adjoint) then |
| 146 |
C print*, " adjoint ", our_rev_mode |
| 147 |
our_rev_mode%arg_store=.FALSE. |
| 148 |
our_rev_mode%arg_restore=.TRUE. |
| 149 |
our_rev_mode%res_store=.FALSE. |
| 150 |
our_rev_mode%res_restore=.FALSE. |
| 151 |
our_rev_mode%plain=.FALSE. |
| 152 |
our_rev_mode%tape=.TRUE. |
| 153 |
our_rev_mode%adjoint=.FALSE. |
| 154 |
C adjoint |
| 155 |
!$PLACEHOLDER_PRAGMA$ id=3 |
| 156 |
our_rev_mode%arg_store=.FALSE. |
| 157 |
our_rev_mode%arg_restore=.TRUE. |
| 158 |
our_rev_mode%res_store=.FALSE. |
| 159 |
our_rev_mode%res_restore=.FALSE. |
| 160 |
our_rev_mode%plain=.FALSE. |
| 161 |
our_rev_mode%tape=.TRUE. |
| 162 |
our_rev_mode%adjoint=.FALSE. |
| 163 |
end if |
| 164 |
if (our_rev_mode%res_store) then |
| 165 |
C store results |
| 166 |
C print*, " res_store ", our_rev_mode |
| 167 |
!$PLACEHOLDER_PRAGMA$ id=5 |
| 168 |
end if |
| 169 |
end subroutine template |