Skip to content

Commit 9e1ceb1

Browse files
authored
Merge pull request #351 from CFD-GO/hotfix/adjoint
Correcting bug for adjoint compilation in makefile
2 parents aa97a05 + cbad57a commit 9e1ceb1

File tree

6 files changed

+29
-10
lines changed

6 files changed

+29
-10
lines changed

src/ADTools.cu

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33
CudaSharedMemory int pushcontrol[MAX_THREADS];
44

55
#define pushcontrol1b(x__) pushcontrol1b_(x__)
6+
#define pushControl1b(x__) pushcontrol1b_(x__)
67
#define pushcontrol2b(x__) pushcontrol2b_(x__)
8+
#define pushControl2b(x__) pushcontrol2b_(x__)
79
#define pushcontrol3b(x__) pushcontrol3b_(x__)
10+
#define pushControl3b(x__) pushcontrol3b_(x__)
811
#define popcontrol1b(x__) popcontrol1b_(x__)
12+
#define popControl1b(x__) popcontrol1b_(x__)
913
#define popcontrol2b(x__) popcontrol2b_(x__)
14+
#define popControl2b(x__) popcontrol2b_(x__)
1015
#define popcontrol3b(x__) popcontrol3b_(x__)
16+
#define popControl3b(x__) popcontrol3b_(x__)
1117

1218

1319
inline CudaDeviceFunction void pushcontrol1b_(int i) {

src/ADpost.sed.Rt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ s/0xFFDF<?%s formatC(v$index, width = 2, format = "d", flag = "0") ?>/<?%s v$nam
1818
s/0xFFCCFFCC/NodeType/g
1919
s/\bfloat\b/real_t/g
2020
s/\bdouble\b/real_t/g
21+
/#include[ ]*<[ ]*adBuffer.h[ ]*>/d
22+
<?R for (g in rows(Globals)) if (! g$adjoint) { ?>
23+
s/<?%s g$name ?>[ ]*[+][=]([^;]*);/AddTo<?%s g$name ?>(\1);/g<?R
24+
} ?>

src/ADpre_b.h.Rt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@
55
#define objectiveb 1.0
66
<?R for (v in Globals$name) { ?>
77
#define <?%s v ?>b <?%s v ?>InObj <?R } ?>
8+
9+
10+
#pragma GCC diagnostic warning "-Wpragmas"
11+
#pragma GCC diagnostic ignored "-Wdangling-else"
12+
#pragma GCC diagnostic ignored "-Wparentheses"
13+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"

src/makefile.main.Rt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ for (d in destinations) {
142142
add = paste("$(addprefix ",dest,"/,$(ADDITIONALS))",sep="")
143143
src_all = paste(src_all,add)
144144
rtopt = NULL
145-
if (adjoint) rtopt = c(rtopt, "MODEL=TRUE")
145+
if (adjoint) rtopt = c(rtopt, "ADJOINT=1")
146146
rtopt = c(rtopt, paste0("MODEL=\\\"",m,"\\\""))
147147
if (length(opts) > 0) {
148148
opts = ifelse(opts==0,"FALSE","TRUE")

tools/ADmod.R

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ begins = which(diff(a)==1)+1
3535

3636
f = file(opt$out)
3737
open(f,"wt")
38-
pushi = grep("pushreal",lines)
39-
looki = grep("lookreal",lines)
40-
popi = grep("popreal",lines)
38+
pushi = grep("push[rR]eal",lines)
39+
looki = grep("look[rR]eal",lines)
40+
popi = grep("pop[rR]eal",lines)
4141

4242
begins = c(begins,length(lines))
4343
alli = sort(c(pushi,popi,begins,looki))
@@ -63,7 +63,7 @@ for (i in alli) {
6363
decl = 0;
6464
} else {
6565
l = lines[i]
66-
l1 = sub("[ pushpopreallook]*","",l);
66+
l1 = sub("[ pushpopRreallook]*","",l);
6767
l1 = sub("[_]?\\(.*$","",l1);
6868
tp = switch(l1,
6969
"4"=list(type="float",array=FALSE),
@@ -92,21 +92,23 @@ for (i in alli) {
9292
cat("var: ",var," ----- fixed\n");
9393
buf = c(buf, paste("//",l));
9494
} else {
95-
if (grepl("pushreal", l)) {
95+
if (grepl("push", l)) {
9696
idx = idx + 1
9797
name = paste(tmpname, idx, sep="_")
9898
if (idx > decl) {
9999
vars = c(vars, paste(tp," ",name,ar_dec,"; // ADmod.R: ",l,sep=""));
100100
decl = idx;
101101
}
102102
buf = c(buf, paste(name,ar_idx," = ", var,ar_idx, "; // ADmod.R: ",l,sep=""));
103-
} else if (grepl("lookreal", l)) {
103+
} else if (grepl("look", l)) {
104104
name = paste(tmpname, idx, sep="_")
105105
buf = c(buf, paste(var,ar_idx, " = ", name,ar_idx,"; // ADmod.R: ",l,sep=""));
106-
} else {
106+
} else if (grepl("pop", l)) {
107107
name = paste(tmpname, idx, sep="_")
108108
buf = c(buf, paste(var,ar_idx, " = ", name,ar_idx,"; // ADmod.R: ",l,sep=""));
109109
idx = idx - 1;
110+
} else {
111+
stop("Unknown type of push/pop: ",l);
110112
}
111113
}
112114
}

tools/makeAD

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,18 @@ echo tapenade -html -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o DynamicsS
3232
$TAPENADE -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o DynamicsS -vars "$VARIABLES $SETTINGS" -outvars "$VARIABLES $SETTINGS"
3333
echo "#define CONST_SETTINGS" > ADpre_.h
3434
cat ADpre.h >> ADpre_.h
35-
echo tapenade -html -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o DynamicsS -vars "$VARIABLES $SETTINGS" -outvars "$VARIABLES $SETTINGS"
35+
echo tapenade -html -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o DynamicsS -vars "$VARIABLES" -outvars "$VARIABLES"
3636
$TAPENADE -msglevel 12 -b Dynamics_tmp.c -root $MAIN_FUN -o Dynamics -vars "$VARIABLES" -outvars "$VARIABLES"
3737
for f in Dynamics_b.c DynamicsS_b.c
3838
do
3939
test -f $f || { echo "Tapenade failed"; exit -1; }
40+
cp $f ${f}_tapenade_raw
4041
$path_to_script/ADmod.R -f $f -o ${f}_ -x "$FIX"
4142
mv ${f}_ $f
4243
while read -r line; do
4344
if test ! -z "$line"
4445
then
45-
sed "$line" $f > ${f}_
46+
sed -E "$line" $f > ${f}_
4647
mv ${f}_ $f
4748
fi
4849
done <ADpost.sed

0 commit comments

Comments
 (0)