30 if (SgSourceFile * source = isSgSourceFile(file)) {
31 sg = source->get_globalScope();
41 #ifdef AD_FORTRAN_SPECIFIC
42 std::string incstr =
"";
46 incstr+=
"\n\n#ifdef ADIC_DENSE";
47 incstr+=
"\n#include \"ad_types.h\"";
49 incstr+=
"\n#include \"ad_grad_saxpy-n_dense.h\"";
52 incstr+=
"\n\n#ifdef ADIC_DENSE_REVERSE";
53 incstr+=
"\n#include \"ad_types.hpp\"";
55 incstr+=
"\n#include \"ad_grad_saxpy-n_dense.h\"";
58 incstr+=
"\n#include \"adic_class_initialization_header.h\"";
60 incstr+=
"\n\n#ifdef ADIC_DENSE_SEED";
61 incstr+=
"\n#include \"ad_types.h\"";
63 incstr+=
"\n#include \"ad_grad_saxpy-n_dense.h\"";
66 incstr+=
"\n\n#ifdef ADIC_GRAD_LENGTH";
67 incstr+=
"\n#include \"ad_grad_length_types.h\"";
69 incstr+=
"\n#include \"ad_grad_saxpy-n_dense.h\"";
71 incstr+=
"\n#endif\n\n";
72 incstr+=
"\n\n#ifdef ADIC_SPARSE_NO_GRAD";
73 incstr+=
"\n#include \"noderiv_sparslinc.h\"";
75 incstr+=
"\n#include \"ad_grad_saxpy-n_sparse.h\"";
77 incstr+=
"\n#endif\n\n";
78 incstr+=
"\n\n#ifdef ADIC_SPARSE";
79 incstr+=
"\n#include \"sparslinc.h\"";
81 incstr+=
"\n#include \"ad_grad_saxpy-n_sparse.h\"";
83 incstr+=
"\n#endif\n\n";
85 SgDeclarationStatementPtrList & plst = sg->getDeclarationList();
86 SgDeclarationStatementPtrList::iterator liter = plst.begin();
87 for (liter; liter != plst.end(); liter++) {
88 std::string stmt_file = (*liter)->get_file_info()->get_filename();
89 if (stmt_file == fileName)
92 SgStatement *first_stmt = NULL;
93 if (liter != plst.end()) {
94 first_stmt = (*liter);
101 bool unparsed =
false;
103 std::string user =
"user-generated";
104 #ifndef AD_FORTRAN_SPECIFIC
105 PreprocessingInfo * toadd =
new PreprocessingInfo(
106 PreprocessingInfo::CplusplusStyleComment, incstr, user, alineno,
107 acolno, nol, PreprocessingInfo::before);
110 first_stmt->addToAttachedPreprocessingInfo(toadd,
111 PreprocessingInfo::before);
114 debugMsg(3,
"added preproc "<< incstr.c_str());
119 int found = fileName.find_last_of(
".");
120 std::string suffix =
".cn.xaif";
121 std::string origfilenamewithsuffixbeforelastandpath = fileName.substr(0,found);
122 std::string xaiffilename = origfilenamewithsuffixbeforelastandpath + suffix;
125 struct stat statStruct;
128 debugMsg(1,
"******************* AD step, calling xaifBooster ****************");
130 suffix =
".cn.xb.xaif";
131 std::string adxaiffilename = origfilenamewithsuffixbeforelastandpath + suffix;
133 if (!stat(adxaiffilename.c_str(), &statStruct))
134 unlink(adxaiffilename.c_str());
145 command +=
" -v -w free -i " + xaiffilename +
146 " -o " + adxaiffilename +
148 " -c " + inlinableintrinsicsfilename +
149 " -N " + noninlinableintrinsicsfilename;
152 ++stringListIt) command +=
" "+(*stringListIt);
155 debugMsg(0,
"xaifBooster call: "<< command.c_str());
156 FILE *pFile_p=popen(command.c_str(),
"r");
161 std::ostringstream xaifBoosterOutput;
163 while (fread(buffer, 1, 1, pFile_p) != 0) {
164 xaifBoosterOutput << buffer[0];
166 int rc=pclose(pFile_p);
168 std::cerr << xaifBoosterOutput.str().c_str() << std::endl;
171 if (xaifBoosterOutput.str().length()) std::cout << xaifBoosterOutput.str().c_str() << std::endl;
172 return adxaiffilename;
180 struct stat statStruct;
181 if (stat(xaiffilename.c_str(), &statStruct)<0)
182 fatal(
"Differentiated XAIF file not found (check differentiation module errors).");
184 debugMsg(2,
"****************** reading produced XAIF back ****************");
186 XAIFParser debuggingParser(theTransformedXAIFCallGraph,theInlinableIntrinsicDefinitions,theNonInlinableIntrinsicDefinitions);
187 debuggingParser.
parse(xaiffilename);
188 debugMsg(3,
"---- Successfully Parsed XAIF Graph in "<< xaiffilename.c_str());
193 dfsTraversal.
addVisitor(debuggingPrintVisitor);
194 dfsTraversal.
traverse(&theTransformedXAIFCallGraph);
198 debugMsg(2,
"****************** converting XAIF to Sage ****************");
200 xaif2SageVisitor.
setCallGraph(&theTransformedXAIFCallGraph);
201 xaif2SageVisitor.
setIntrinsics(&theInlinableIntrinsicDefinitions,&theNonInlinableIntrinsicDefinitions);
204 dfsTraversal.
traverse(&theTransformedXAIFCallGraph);
206 #ifdef AD_FORTRAN_SPECIFIC
207 DumpAsDot().
doIt(psgproj,
"adic_after_unparse_before_conversion");
208 DumpAsDot().
doIt(
"adic_all_after_unparse_before_conversion");
212 #ifndef AD_FORTRAN_SPECIFIC
224 #ifdef AD_FORTRAN_SPECIFIC
229 for (SgFilePtrList::iterator iter = fptr->begin(); iter != fptr->end(); iter++)
233 debugMsg(1,
"Creating the dense saxpy array operations files");
247 SgFile * templatefileptr=0;
249 for (SgFilePtrList::iterator iter = fptr->begin(); iter != fptr->end(); iter++) {
250 std::string curfilename = (*iter)->getFileName();
252 SgNode * copy_node = (*iter)->copy(deepcopy);
253 templatefileptr = isSgFile(copy_node);
258 if (!templatefileptr) {
268 std::string origfilenamewithsuffixandpath = std::string(file->getFileName());
269 int found = origfilenamewithsuffixandpath.find_last_of(
"/");
271 if(
isSymlink(origfilenamewithsuffixandpath))
272 folder = origfilenamewithsuffixandpath.substr(0,found);
275 std::string origfilenamewithsuffix = origfilenamewithsuffixandpath.substr(found+1);
276 std::string rosefilenamewithsuffixandpath = folder +
"/rose_" + origfilenamewithsuffix;
281 case R_ONLY : suffix =
".r.";
break;
282 case CN_ONLY : suffix =
".cn.";
break;
283 case CN_PP : suffix =
".cn.pp.";
break;
284 case CN_XB_PP : suffix =
".cn.xb.pp.";
break;
286 fatal(
"Unknown stage " << stage);
289 found = origfilenamewithsuffixandpath.find_last_of(
".");
290 std::string origfilenamewithsuffixbeforelastandpath = origfilenamewithsuffixandpath.substr(0,found);
291 std::string origfilenamesfinalsuffix = origfilenamewithsuffixandpath.substr(found+1);
292 std::string destinationfilename = origfilenamewithsuffixbeforelastandpath + suffix + origfilenamesfinalsuffix;
301 command =
"mv " + src +
" "+ target;
302 assert(::system(command.c_str())==0);
307 int flags = 0, nOrder = 1;
309 std::string mapModel, headerFile =
"ad_deriv.h";
311 derivNames.push_back(
"Jacobian");
312 state->
init(flags, derivNames, mapModel, headerFile, defines, dirs, nOrder);
317 XAIFParser intrinsicsParser(theInlinableIntrinsicDefinitions,theNonInlinableIntrinsicDefinitions);