[ClavaLaraApi] Adds function Parallelize.getForLoopsPragmas()
@@ -17,7 +17,7 @@ var Parallelize = {};
* @param $loops {$loop[]} an array of for loops to attempt to parallelize. If undefined, tries to parallelize all for loops in the program.
*/
Parallelize.forLoops = function($loops) {
-
+ /*
// Initialize loops if undefined
if($loops === undefined) {
$loops = Clava.getProgram().descendants('loop');
@@ -81,6 +81,9 @@ Parallelize.forLoops = function($loops) {
// Revert AST changes
Clava.popAst();
+*/
+
+ var parallelLoops = Parallelize.getForLoopsPragmas($loops);
// Add pragmas to loops
for(var $loop of $loops) {
@@ -98,3 +101,74 @@ Parallelize.forLoops = function($loops) {
println('Parallelization finished');
}
+
+
+Parallelize.getForLoopsPragmas = function($loops) {
+
+ // Initialize loops if undefined
+ if($loops === undefined) {
+ $loops = Clava.getProgram().descendants('loop');
+ }
+
+ // Filter any loop that is not a for loop
+ var $forLoops = [];
+ for(var $loop of $loops) {
+ if($loop.kind !== "for") {
+ continue;
+ }
+
+ $forLoops.push($loop);
+ }
+
+ // Save the current AST, before applying modifications that help analysis
+ Clava.pushAst();
+
+
+ // Mark all for loops with pragmas
+ for($originalLoop of $forLoops) {
+ if($originalLoop.kind !== "for") {
+ continue;
+ }
+
+ var $loop = Clava.findJp($originalLoop);
+
+ $loop.insertBefore("#pragma parallelize_id " + $originalLoop.astId);
+ }
+
+ // Transformations to help analysis
+ call InlineFunctionCalls;
+ call RemoveNakedloops;
+ call NormalizedBinaryOp;
+
+ // Rebuild tree
+ Clava.rebuild();
+
+
+ println('Parallelizing ' + $forLoops.length + ' for loops...');
+
+ // Find all loops marked for parallelization
+ //var loopPragmas = {};
+ var parallelLoops = {};
+ var unparallelizableLoops = {};
+
+ $pragmas = Clava.getProgram().descendants('pragma');
+ for(var $pragma of $pragmas) {
+ if($pragma.name !== "parallelize_id") {
+ continue;
+ }
+
+ var parallelization = call ParallelizeLoop($pragma.target);
+
+ if(parallelization.ompPragma === undefined) {
+ unparallelizableLoops[$pragma.content] = parallelization.errorMsg;
+ } else {
+ parallelLoops[$pragma.content] = parallelization.ompPragma;
+ }
+ }
+
+ // Revert AST changes
+ Clava.popAst();
+
+ return parallelLoops;
+}
+
\ No newline at end of file
