dol: initial dol commit
[jump.git] / dol / src / dol / util / ApplicationGenerator.java
diff --git a/dol/src/dol/util/ApplicationGenerator.java b/dol/src/dol/util/ApplicationGenerator.java
new file mode 100644 (file)
index 0000000..a193614
--- /dev/null
@@ -0,0 +1,914 @@
+/* $Id: ApplicationGenerator.java 1 2010-02-24 13:03:05Z haidw $ */\r
+package dol.util;\r
+\r
+import java.io.BufferedWriter;\r
+import java.io.File;\r
+import java.io.FileWriter;\r
+import java.util.Random;\r
+import java.util.Vector;\r
+import java.util.regex.Matcher;\r
+import java.util.regex.Pattern;\r
+\r
+import dol.datamodel.architecture.Processor;\r
+import dol.datamodel.architecture.ReadPath;\r
+import dol.datamodel.architecture.WritePath;\r
+import dol.datamodel.mapping.CommunicationBinding;\r
+import dol.datamodel.mapping.ComputationBinding;\r
+import dol.datamodel.mapping.Mapping;\r
+import dol.datamodel.mapping.Schedule;\r
+import dol.datamodel.mapping.ScheduleEntry;\r
+import dol.datamodel.mapping.SchedulingPolicy;\r
+import dol.datamodel.pn.Channel;\r
+import dol.datamodel.pn.Connection;\r
+import dol.datamodel.pn.Port;\r
+import dol.datamodel.pn.Process;\r
+import dol.datamodel.pn.ProcessNetwork;\r
+import dol.datamodel.pn.ProfilingConfiguration;\r
+import dol.datamodel.pn.SourceCode;\r
+import dol.visitor.xml.MapXmlVisitor;\r
+import dol.visitor.xml.PNXmlVisitor;\r
+\r
+/**\r
+ *\r
+ */\r
+public class ApplicationGenerator {\r
+    /*\r
+    protected String _processes[] =\r
+        {"producer", "consumer"};\r
+\r
+    protected int _computation[] =\r
+        {1000, 1000};\r
+\r
+    protected int _communication[][] =\r
+        {{0, 4}, {-4, 0}};\r
+\r
+    protected String _binding[] =\r
+        {"tile_0.arm", "tile_0.arm"};\r
+\r
+    protected int _iterations = 1000;\r
+    */\r
+\r
+    /*\r
+    protected String _processes[] =\r
+        {"producer", "forwarder", "consumer"};\r
+\r
+    protected int _computation[] =\r
+        {1000, 1000, 1000};\r
+\r
+    protected int _communication[][] =\r
+        {{ 0,  4,  0},\r
+         {-4,  0,  4},\r
+         { 0, -4,  0}};\r
+\r
+    protected String _binding[] =\r
+        {"tile_0.arm", "tile_0.arm", "tile_0.arm"};\r
+\r
+    protected int _iterations = 10;\r
+    */\r
+\r
+    /*\r
+    protected String _processes[] =\r
+        {"stageA", "stageB", "stageC", "stageD",\r
+         "stageE", "stageF", "stageG", "stageH",\r
+         "stageI", "stageJ", "stageK", "stageL",\r
+         "stageM", "stageN", "stageO", "stageP"};\r
+\r
+    protected int _computation[] =\r
+        {1, 2, 3, 4, 5, 6, 7, 8,\r
+         9, 10, 11, 12, 13, 14, 15, 16};\r
+\r
+    protected int _communication[][] =\r
+        {{    0,  1024,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {-1024,     0,  1024,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0, -1024,     0,  1024,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,     0, -1024,     0,  1024,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,     0,     0, -1024,     0,  1024,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,     0,     0,     0, -1024,     0,  1024,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,     0,     0,     0,     0, -1024,     0,  1024,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,     0,     0,     0,     0,     0, -1024,     0,  1024,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0, -1024,     0,  1024,     0,     0,     0,     0,     0,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0, -1024,     0,  1024,     0,     0,     0,     0,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0, -1024,     0,  1024,     0,     0,     0,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0,     0, -1024,     0,  1024,     0,     0,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, -1024,     0,  1024,     0,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, -1024,     0,  1024,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, -1024,     0,  1024},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0, -1024,     0}};\r
+\r
+\r
+    //protected String _binding[] =\r
+    //    {"tile_0.arm", "tile_0.arm", "tile_1.arm", "tile_1.arm",\r
+    //     "tile_2.arm", "tile_2.arm", "tile_3.arm", "tile_3.arm",\r
+    //     "tile_4.arm", "tile_4.arm", "tile_5.arm", "tile_5.arm",\r
+    //     "tile_6.arm", "tile_6.arm", "tile_7.arm", "tile_7.arm"};\r
+\r
+    //protected String _binding[] =\r
+    //    {"tile_0.arm", "tile_1.arm", "tile_2.arm", "tile_3.arm",\r
+    //     "tile_4.arm", "tile_5.arm", "tile_6.arm", "tile_7.arm",\r
+    //     "tile_0.arm", "tile_1.arm", "tile_2.arm", "tile_3.arm",\r
+    //     "tile_4.arm", "tile_5.arm", "tile_6.arm", "tile_7.arm"};\r
+\r
+    protected String _binding[] =\r
+        {"tile_0.arm", "tile_1.arm", "tile_2.arm", "tile_3.arm",\r
+         "tile_4.arm", "tile_5.arm", "tile_6.arm", "tile_7.arm",\r
+         "tile_7.arm", "tile_6.arm", "tile_5.arm", "tile_4.arm",\r
+         "tile_3.arm", "tile_2.arm", "tile_1.arm", "tile_0.arm"};\r
+\r
+    protected int _iterations = 10;\r
+    */\r
+\r
+    protected String _processes[] =\r
+        {"splitAA", "splitBA", "splitBB",\r
+         "pipeAA", "pipeBA", "pipeCA", "pipeDA",\r
+         "pipeEA", "pipeFA", "pipeAB", "pipeBB",\r
+         "pipeCB", "pipeDB", "pipeEB", "pipeFB",\r
+         "mergeBA", "mergeBB", "mergeAA"};\r
+\r
+    protected int _armComputation[] =\r
+        {1, 2, 3, 4, 5, 6, 7, 8,\r
+         9, 10, 11, 12, 13, 14, 15, 16, 17, 18};\r
+    protected int _magicComputation[] =\r
+        {1, 2, 3, 4, 5, 6, 7, 8,\r
+         9, 10, 11, 12, 13, 14, 15, 16, 17, 18};\r
+\r
+\r
+    protected int _communication[][] =\r
+        {{    0,     4,     4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {   -4,     0,     0,     4,     4,     4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {   -4,     0,     0,     0,     0,     0,     4,     4,     4,     0,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,    -4,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0,     0,     0,     0,     0,     0},\r
+         {    0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0,     0,     0,     0,     0},\r
+         {    0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0,     0,     0,     0},\r
+         {    0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0,     0,     0},\r
+         {    0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0,     0},\r
+         {    0,     0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0},\r
+         {    0,     0,     0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0},\r
+         {    0,     0,     0,     0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0,     0},\r
+         {    0,     0,     0,     0,     0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     0,     4,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,    -4,     0,     0,     0,     0,     0,     0,     0,     4,     0},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0,    -4,    -4,    -4,     0,     0,     0,     0,     0,     4},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,    -4,    -4,    -4,     0,     0,     4},\r
+         {    0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,     0,    -4,    -4,     0}};\r
+\r
+\r
+    //working\r
+    protected String _binding[] =\r
+        {"tile_0.arm", "tile_1.arm", "tile_4.arm",\r
+         "tile_1.arm", "tile_2.arm", "tile_3.arm", "tile_4.arm",\r
+         "tile_5.arm", "tile_6.arm", "tile_1.arm", "tile_2.arm",\r
+         "tile_3.arm", "tile_4.arm", "tile_5.arm", "tile_6.arm",\r
+         "tile_3.arm", "tile_7.arm", "tile_0.arm"};\r
+\r
+    /*\r
+    protected String _binding[] =\r
+        {"tile_0.arm", "tile_1.arm", "tile_3.arm",\r
+         "tile_1.arm", "tile_1.arm", "tile_2.arm", "tile_2.arm",\r
+         "tile_3.arm", "tile_3.arm", "tile_4.arm", "tile_4.arm",\r
+         "tile_5.arm", "tile_5.arm", "tile_6.arm", "tile_6.arm",\r
+         "tile_7.arm", "tile_7.arm", "tile_0.arm"};\r
+\r
+    protected String _binding[] =\r
+        {"tile_0.arm", "tile_1.arm", "tile_7.arm",\r
+         "tile_1.arm", "tile_1.arm", "tile_2.arm", "tile_2.arm",\r
+         "tile_3.arm", "tile_3.arm", "tile_4.arm", "tile_4.arm",\r
+         "tile_5.arm", "tile_5.arm", "tile_6.arm", "tile_6.arm",\r
+         "tile_7.arm", "tile_3.arm", "tile_0.arm"};\r
+    */\r
+\r
+    //not working\r
+    /*\r
+    protected String _binding[] =\r
+        {"tile_0.arm", "tile_1.arm", "tile_2.arm", "tile_3.arm",\r
+         "tile_4.arm", "tile_5.arm", "tile_6.arm", "tile_7.arm",\r
+         "tile_7.arm", "tile_6.arm", "tile_5.arm", "tile_4.arm",\r
+         "tile_3.arm", "tile_2.arm", "tile_1.arm", "tile_0.arm",\r
+         "tile_0.arm", "tile_0.arm"};\r
+    */\r
+\r
+    protected int _iterations = 10;\r
+\r
+    public String getStringEncoding(int i, int total) {\r
+        if (total > 26 * 26) {\r
+            System.out.println("\"total\" needs to be less than "\r
+                    + 26 * 26 + ".");\r
+            return "";\r
+        } else if (total <= 26) {\r
+            return  Character.toString((char)('A' + (i % 26)));\r
+        }\r
+        return Character.toString((char)('A' + (i / 26)))\r
+            + Character.toString((char)('A' + (i % 26)));\r
+    }\r
+\r
+    /**\r
+     *\r
+     * @param stages\r
+     * @param communication\r
+     */\r
+    public void generateIndependentTasks(int numberOfTasks) {\r
+          _processes = new String[numberOfTasks];\r
+          _armComputation = new int[numberOfTasks];\r
+          _magicComputation = new int[numberOfTasks];\r
+          _communication = new int[numberOfTasks][numberOfTasks];\r
+          _binding = new String[numberOfTasks];\r
+          _iterations = 1000;\r
+\r
+          for (int i = 0; i < numberOfTasks; i++) {\r
+              _processes[i] = ((i < numberOfTasks / 2) ? "armProcess"\r
+                  : "magicProcess")\r
+                  + getStringEncoding(i, numberOfTasks);\r
+              System.out.println(_processes[i]);\r
+              _armComputation[i] =\r
+                  (i < numberOfTasks / 2) ? 100000000 : 200000000;\r
+              _magicComputation[i] =\r
+                  (i < numberOfTasks / 2) ? 200000000 : 100000000;\r
+              _binding[i] = (i < numberOfTasks / 2) ? "tile_0.arm"\r
+                      : "tile_0.magic";\r
+          }\r
+\r
+          //no communication\r
+          for (int i = 0; i < numberOfTasks; i++) {\r
+              for (int j = 0; j < numberOfTasks; j++) {\r
+                  _communication[i][j] = 0;\r
+              }\r
+          }\r
+    }\r
+\r
+    /**\r
+     *\r
+     * @param pipelines\r
+     * @param stages\r
+     * @param communication\r
+     */\r
+    public void generateIndpendentPipelines(int pipelines, int stages, int communication) {\r
+        Random random = new Random();\r
+        _processes = new String[stages * pipelines];\r
+        _armComputation = new int[stages * pipelines];\r
+        _magicComputation = new int[stages * pipelines];\r
+        _communication = new int[stages * pipelines][stages * pipelines];\r
+        _binding = new String[stages * pipelines];\r
+        _iterations = 1000;\r
+\r
+        for (int i = 0; i < pipelines; i++) {\r
+            for (int j = 0; j < stages; j++) {\r
+               _processes[i * stages + j] =\r
+                   ((i < pipelines / 2) ? "arm" : "magic")\r
+                   + "stage"\r
+                   + getStringEncoding(i, pipelines) + "x"\r
+                   + getStringEncoding(j, stages);\r
+               System.out.println(_processes[i * stages + j]);\r
+              _armComputation[i * stages + j] =\r
+                  0 * random.nextInt(10000000) +\r
+                  ((i < pipelines / 2) ? 100000000 : 200000000);\r
+              _magicComputation[i * stages + j] =\r
+                  0 * random.nextInt(10000000) +\r
+                  ((i < pipelines / 2) ? 200000000 : 100000000);\r
+              _binding[i * stages + j] = "tile_0.arm";\r
+            }\r
+        }\r
+\r
+        for (int i = 0; i < pipelines; i++) {\r
+            for (int j = 0; j < stages; j++) {\r
+                for (int k = 0; k < pipelines; k++) {\r
+                    for (int l = 0; l < stages; l++) {\r
+                        _communication[i * stages + j][k * stages + l] = 0;\r
+                        if (i == k && l == j + 1) {\r
+                            _communication[i * stages + j][k * stages + l] = communication;\r
+                        } else if (i == k && j == l + 1) {\r
+                            _communication[i * stages + j][k * stages + l] = -communication;\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+    /**\r
+     *\r
+     * @param pipelines\r
+     * @param stages\r
+     * @param communication\r
+     */\r
+    public void generateIndpendentPipelines2(int pipelines, int stages, int communication) {\r
+        Random random = new Random();\r
+        _processes = new String[stages * pipelines];\r
+        _armComputation = new int[stages * pipelines];\r
+        _magicComputation = new int[stages * pipelines];\r
+        _communication = new int[stages * pipelines][stages * pipelines];\r
+        _binding = new String[stages * pipelines];\r
+        _iterations = 1000;\r
+\r
+        for (int i = 0; i < pipelines; i++) {\r
+            for (int j = 0; j < stages; j++) {\r
+               _processes[i * stages + j] =\r
+                   ((j < stages / 2) ? "arm" : "magic")\r
+                   + "stage"\r
+                   + getStringEncoding(i, pipelines) + "x"\r
+                   + getStringEncoding(j, stages);\r
+               System.out.println(_processes[i * stages + j]);\r
+              _armComputation[i * stages + j] =\r
+                  0 * random.nextInt(10000000) +\r
+                  ((j < stages / 2) ? 100000000 : 200000000);\r
+              _magicComputation[i * stages + j] =\r
+                  0 * random.nextInt(10000000) +\r
+                  ((j < stages / 2) ? 200000000 : 100000000);\r
+              _binding[i * stages + j] = "tile_0.arm";\r
+            }\r
+        }\r
+\r
+        for (int i = 0; i < pipelines; i++) {\r
+            for (int j = 0; j < stages; j++) {\r
+                for (int k = 0; k < pipelines; k++) {\r
+                    for (int l = 0; l < stages; l++) {\r
+                        _communication[i * stages + j][k * stages + l] = 0;\r
+                        if (i == k && l == j + 1) {\r
+                            _communication[i * stages + j][k * stages + l] = communication;\r
+                        } else if (i == k && j == l + 1) {\r
+                            _communication[i * stages + j][k * stages + l] = -communication;\r
+                        }\r
+                    }\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+    /**\r
+     *\r
+     * @param stages\r
+     * @param communication\r
+     */\r
+    public void generatePipeline(int stages, int communication) {\r
+        _processes = new String[stages];\r
+        _armComputation = new int[stages];\r
+        _magicComputation = new int[stages];\r
+        _communication = new int[stages][stages];\r
+        _binding = new String[stages];\r
+        //_iterations = 1000;\r
+        _iterations = 1000;\r
+\r
+        for (int i = 0; i < stages; i++) {\r
+            _processes[i] = ((i % 8 < 4) ? "arm" : "magic")\r
+                + "stage" + getStringEncoding(i, stages);\r
+            System.out.println(_processes[i]);\r
+            _armComputation[i] =\r
+                (i % 8 < 4) ? 100 : 200;\r
+            _magicComputation[i] =\r
+                (i % 8 < 4) ? 200 : 100;\r
+            _binding[i] = "tile_0.arm";\r
+        }\r
+\r
+        for (int i = 0; i < stages; i++) {\r
+            for (int j = 0; j < stages; j++) {\r
+                _communication[i][j] = 0;\r
+                if (j == i + 1) {\r
+                    _communication[i][j] = communication;\r
+                } else if (i == j + 1) {\r
+                    _communication[i][j] = -communication;\r
+                }\r
+            }\r
+        }\r
+    }\r
+\r
+\r
+    /**\r
+     *\r
+     * @param pn\r
+     */\r
+    public void generateProcessNetwork(ProcessNetwork pn) {\r
+        System.out.print("Generate process network. ");\r
+        int numberOfProcesses = 0;\r
+        int numberOfChannels = 0;\r
+\r
+        for (int j = 0; j < _processes.length; j++) {\r
+            String processName = _processes[j];\r
+            Process p = new Process(processName);\r
+            SourceCode srcCode = new SourceCode(processName);\r
+            srcCode.setLocality(processName + ".c");\r
+            srcCode.setType("c");\r
+            p.getSrcList().add(srcCode);\r
+            pn.getProcessList().add(p);\r
+            numberOfProcesses++;\r
+            for (int i = 0; i < 8; i++) {\r
+                ProfilingConfiguration c = new ProfilingConfiguration(\r
+                        "BCED tile_" + i + ".arm");\r
+                c.setValue(Integer.toString(_armComputation[j]));\r
+                p.getProfilingList().add(c);\r
+                c = new ProfilingConfiguration(\r
+                        "BCED tile_" + i + ".magic");\r
+                c.setValue(Integer.toString(_magicComputation[j]));\r
+                p.getProfilingList().add(c);\r
+            }\r
+        }\r
+\r
+        //check whether communication matrix is symmetric\r
+        if (_communication[0].length != numberOfProcesses) {\r
+            System.out.println();\r
+            System.out.println("Error: Size of communication matrix ("\r
+                    + _communication[0].length + " columns) must match "\r
+                    + "number of processes (" + numberOfProcesses + ").");\r
+            System.exit(-1);\r
+        }\r
+        for (int row = 0; row < numberOfProcesses; row++) {\r
+            for (int col = 0; col < numberOfProcesses; col++) {\r
+                if (row == col && _communication[row][col] != 0) {\r
+                    System.out.println();\r
+                    System.out.println("Error: No self-channels allowed. "\r
+                            + "Problem for process " + row + " ("\r
+                            + _processes[row] + ").");\r
+                    System.exit(-1);\r
+                }\r
+                if (_communication[row][col] !=\r
+                    -_communication[col][row]) {\r
+                    System.out.println();\r
+                    System.out.println("Error: Communication matrix "\r
+                            + "needs to be symmetric. Mismatch for row "\r
+                            + row + " column " + col + ".");\r
+                    System.exit(-1);\r
+                }\r
+            }\r
+        }\r
+\r
+        for (int row = 0; row < numberOfProcesses; row++) {\r
+            for (int col = row; col < numberOfProcesses; col++) {\r
+                if (_communication[row][col] == 0) {\r
+                    continue;\r
+                }\r
+                int src = row;\r
+                int dst = col;\r
+\r
+                if (_communication[row][col] < 0) {\r
+                    src = col;\r
+                    dst = row;\r
+                }\r
+\r
+                Channel c = new Channel("channel" + _processes[src]\r
+                        + _processes[dst]);\r
+                c.setSize(Math.abs(2 * _communication[src][dst]));\r
+                c.setType("fifo");\r
+                ProfilingConfiguration p = new ProfilingConfiguration(\r
+                        "TotalReadData");\r
+                p.setValue(Integer.toString(_communication[row][col]));\r
+                c.getProfilingList().add(p);\r
+                pn.getChannelList().add(c);\r
+                numberOfChannels++;\r
+\r
+                Port channelPort0 = new Port("0", Port.INPORT);\r
+                Port channelPort1 = new Port("1", Port.OUTPORT);\r
+                c.getPortList().add(channelPort0);\r
+                c.getPortList().add(channelPort1);\r
+\r
+                Connection c1 = new Connection(\r
+                        "c1" + _processes[src] + _processes[dst]);\r
+                Connection c2 = new Connection(\r
+                        "c2" + _processes[src] + _processes[dst]);\r
+                pn.getConnectionList().add(c1);\r
+                pn.getConnectionList().add(c2);\r
+\r
+                Port p0 = new Port(Integer.toString(pn.getProcess(\r
+                        _processes[src]).getPortList().size()),\r
+                        Port.OUTPORT);\r
+                Port p1 = new Port(Integer.toString(pn.getProcess(\r
+                        _processes[dst]).getPortList().size()),\r
+                        Port.INPORT);\r
+                pn.getProcess(_processes[src]).getPortList().add(p0);\r
+                pn.getProcess(_processes[dst]).getPortList().add(p1);\r
+\r
+                c1.setOriginPort(p0);\r
+                c1.setTargetPort(channelPort0);\r
+                c1.setOrigin(pn.getProcess(_processes[src]));\r
+                c1.setTarget(c);\r
+                p0.setPeerResource(c);\r
+                p0.setPeerPort(channelPort0);\r
+                channelPort0.setPeerResource(pn.getProcess(\r
+                        _processes[src]));\r
+                channelPort0.setPeerPort(p0);\r
+\r
+                c2.setOriginPort(channelPort1);\r
+                c2.setTargetPort(p1);\r
+                c2.setOrigin(c);\r
+                c2.setTarget(pn.getProcess(_processes[dst]));\r
+                channelPort1.setPeerResource(pn.getProcess(\r
+                        _processes[dst]));\r
+                channelPort1.setPeerPort(p1);\r
+                p1.setPeerResource(c);\r
+                p1.setPeerPort(channelPort1);\r
+\r
+                c.setOrigin(pn.getProcess(_processes[src]));\r
+                c.setTarget(pn.getProcess(_processes[dst]));\r
+            }\r
+        }\r
+\r
+        System.out.println("Finished.");\r
+    }\r
+\r
+    /**\r
+     *\r
+     * @param pn\r
+     */\r
+    public void generateProcessNetworkXml(ProcessNetwork pn,\r
+            String filename) {\r
+        System.out.print("Generate process network XML. ");\r
+        StringBuffer buffer = new StringBuffer();\r
+        pn.accept(new PNXmlVisitor(buffer));\r
+        try {\r
+            java.io.BufferedWriter writer =\r
+                    new java.io.BufferedWriter(\r
+                    new java.io.FileWriter(filename));\r
+            writer.write(buffer.toString());\r
+            writer.close();\r
+        } catch (java.io.IOException e) {\r
+            System.out.println();\r
+            System.out.println("Error: Could not write XML file.");\r
+            System.exit(-1);\r
+        }\r
+        System.out.println("Finished.");\r
+    }\r
+\r
+    /**\r
+     *\r
+     * @param pn\r
+     * @param path\r
+     */\r
+    public void generateCode(ProcessNetwork pn, String path) {\r
+        System.out.print("Generate source code of processes. ");\r
+\r
+        String newline = System.getProperty("line.separator");\r
+        int maxProcessNameLength = 0;\r
+        for (String processName : _processes) {\r
+            maxProcessNameLength = Math.max(maxProcessNameLength,\r
+                    processName.length());\r
+        }\r
+\r
+        String global = "";\r
+        global += "#ifndef GLOBAL_H" + newline;\r
+        global += "#define GLOBAL_H" + newline;\r
+        global += newline;\r
+\r
+        global += "#define ITERATIONS    " + _iterations + newline;\r
+        global += newline;\r
+\r
+        for (int i = 0; i < _processes.length; i++) {\r
+            global += "#define LOOPS_ARM_" + _processes[i].toUpperCase()\r
+                + "    " + _armComputation[i] + newline;\r
+            global += "#define LOOPS_MAGIC_" + _processes[i].toUpperCase()\r
+                + "    " + _magicComputation[i] + newline;\r
+        }\r
+\r
+        for (int row = 0; row < _communication[0].length; row++) {\r
+            for (int col = row; col < _communication[0].length; col++) {\r
+                if (_communication[row][col] == 0) {\r
+                    continue;\r
+                }\r
+                int src = row;\r
+                int dst = col;\r
+\r
+                if (_communication[row][col] < 0) {\r
+                    src = col;\r
+                    dst = row;\r
+                }\r
+\r
+                global += "#define TOKEN_SIZE_"\r
+                        + _processes[src].toUpperCase() + "_"\r
+                        + _processes[dst].toUpperCase() + "    "\r
+                        + _communication[src][dst] + newline;\r
+            }\r
+        }\r
+        global += newline;\r
+        global += "#endif" + newline;\r
+\r
+        try {\r
+            BufferedWriter out = new BufferedWriter(\r
+                    new FileWriter(path + "global.h"));\r
+            out.write(global);\r
+            out.close();\r
+        } catch (Exception e) {\r
+            System.out.println();\r
+            System.out.println("Error: While writing global.h file.");\r
+            System.exit(-1);\r
+        }\r
+\r
+\r
+        for (Process p : pn.getProcessList()) {\r
+            String state = p.getName().substring(0, 1).toUpperCase()\r
+                    + p.getName().substring(1) + "_State";\r
+\r
+            String h = "";\r
+            h += "#ifndef " + p.getName().toUpperCase() + "_H" + newline;\r
+            h += "#define " + p.getName().toUpperCase() + "_H" + newline;\r
+            h += newline;\r
+            h += "#include <dol.h>" + newline;\r
+            h += newline;\r
+            for (Port port : p.getPortList()) {\r
+                h += "#define PORT_" + p.getName().toUpperCase() + "_"\r
+                       + (port.isInPort() ? "IN_" : "OUT_" )\r
+                       + port.getName() + " " + port.getName() + newline;\r
+            }\r
+            h += newline;\r
+            h += "typedef struct {" + newline;\r
+            h += "    int iterations;" + newline;\r
+            h += "} " + state + ";" + newline;\r
+            h += newline;\r
+            h += "void " + p.getName() + "_init(DOLProcess *p);"\r
+                    + newline;\r
+            h += "int " + p.getName() + "_fire(DOLProcess *p);" + newline;\r
+            h += newline;\r
+            h += "#endif" + newline;\r
+\r
+            String c = "";\r
+            String printPrefix = String.format("    printf(\"[%-"\r
+                    + maxProcessNameLength + "s] ", p.getName());\r
+            c += "#include <stdio.h>" + newline;\r
+            c += newline;\r
+            c += "#include \"" + p.getName() + ".h\"" + newline;\r
+            c += "#include \"global.h\"" + newline;\r
+            c += newline;\r
+            c += "void " + p.getName() + "_init(DOLProcess *p) {"\r
+                    + newline;\r
+            c += "    " + state + " *state = (" + state + "*)p->local;"\r
+                    + newline;\r
+            c += "    state->iterations = 0;" + newline;\r
+            c += "}" + newline;\r
+            c += newline;\r
+            c += "int " + p.getName() + "_fire(DOLProcess *p) {"\r
+                    + newline;\r
+\r
+            int processIndex = getProcessIndex(p.getName());\r
+            int maxBuffer = 0;\r
+            for (int i = 0; i < _communication[processIndex].length; i++) {\r
+                maxBuffer = Math.max(maxBuffer,\r
+                        Math.abs(_communication[processIndex][i]));\r
+            }\r
+            c += "    int buffer[" + ((maxBuffer + (4 - 1)) / 4) + "];" + newline;\r
+            c += "    int i;" + newline;\r
+            c += "    " + state + " *state = (" + state + "*)p->local;";\r
+            c += newline + newline;\r
+\r
+            for (Port port : p.getPortList()) {\r
+                if (port.isInPort()) {\r
+                    int originIndex = getProcessIndex(\r
+                        ((Channel)port.getPeerResource()).getOrigin()\r
+                        .getName());\r
+                    String tokenSize = "TOKEN_SIZE_"\r
+                        + _processes[originIndex].toUpperCase() + "_"\r
+                        + _processes[processIndex].toUpperCase();\r
+                    c += printPrefix + "read %d bytes from "\r
+                        + _processes[originIndex] + ".\\n\", " + tokenSize\r
+                        + ");" + newline;\r
+                    c += "    DOL_read((void*)"\r
+                        + "PORT_" + p.getName().toUpperCase() + "_IN_"\r
+                        + port.getName() + ", buffer, " + tokenSize\r
+                        + ", p);" + newline;\r
+                }\r
+            }\r
+            c += newline;\r
+            //c += "    printf(\"[%-20s ] iteration %d/n\", \""\r
+            //        + p.getName() + "\", state->iterations);" + newline;\r
+            c += printPrefix + "iteration %d.\\n\" , "\r
+                    + "state->iterations);" + newline;\r
+            c += newline;\r
+            c += "#ifdef __arm__" + newline;\r
+            c += "    for (i = 0; i < LOOPS_ARM_" + p.getName().toUpperCase()\r
+                + "; i++) { ; }" + newline;\r
+            c += "#else" + newline;\r
+            c += "    for (i = 0; i < LOOPS_MAGIC_" + p.getName().toUpperCase()\r
+                + "; i++) { ; }" + newline;\r
+            c += "#endif" + newline;\r
+            for (Port port : p.getPortList()) {\r
+                if (port.isOutPort()) {\r
+                    int targetIndex = getProcessIndex(\r
+                            ((Channel)port.getPeerResource()).getTarget()\r
+                            .getName());\r
+                    String tokenSize = "TOKEN_SIZE_"\r
+                        + _processes[processIndex].toUpperCase() + "_"\r
+                        + _processes[targetIndex].toUpperCase();\r
+                    c += printPrefix + "write %d bytes to "\r
+                        + _processes[targetIndex] + ".\\n\", " + tokenSize\r
+                        + ");" + newline;\r
+                    c += "    DOL_write((void*)"\r
+                        + "PORT_" + p.getName().toUpperCase() + "_OUT_"\r
+                        + port.getName() + ", buffer, "+ tokenSize\r
+                        + ", p);" + newline;\r
+                }\r
+            }\r
+            c += newline;\r
+            c += "    state->iterations++;" + newline;\r
+            c += "    if (state->iterations >= ITERATIONS) {"\r
+                    + newline;\r
+            c += "        DOL_detach(p);" + newline;\r
+            c += "        return -1;" + newline;\r
+            c += "    }" + newline;\r
+            c += newline;\r
+            c += "    return 0;" + newline;\r
+            c += "}" + newline;\r
+\r
+            try {\r
+                BufferedWriter out = new BufferedWriter(\r
+                        new FileWriter(path + p.getName() + ".h"));\r
+                out.write(h);\r
+                out.close();\r
+                out = new BufferedWriter(\r
+                        new FileWriter(path + p.getName() + ".c"));\r
+                out.write(c);\r
+                out.close();\r
+            } catch (Exception e) {\r
+                System.out.println();\r
+                System.out.println("Error: While writing source files.");\r
+                System.exit(-1);\r
+            }\r
+        }\r
+        System.out.println("Finished.");\r
+    }\r
+\r
+\r
+    /**\r
+     *\r
+     * @param map\r
+     * @param pn\r
+     */\r
+    public void generateMapping(ProcessNetwork pn, Mapping map) {\r
+        System.out.print("Generate mapping. ");\r
+        map.setPN(pn);\r
+\r
+        //binding of processes\r
+        Vector<Processor> processors = new Vector<Processor>();\r
+        for (int i = 0; i < _binding.length; i++) {\r
+            String processName =  _processes[i];\r
+            String processorName = _binding[i];\r
+            Processor processor = null;\r
+\r
+            boolean processorExists = false;\r
+            for (Processor proc : processors) {\r
+                if (proc.getName().equals(processorName)) {\r
+                    processor = proc;\r
+                    processorExists = true;\r
+                    break;\r
+                }\r
+            }\r
+\r
+            if (!processorExists) {\r
+                processor = new Processor(processorName);\r
+                processors.add(processor);\r
+            }\r
+\r
+            ComputationBinding compBinding = new ComputationBinding(\r
+                    processName + "binding");\r
+            compBinding.setProcess(pn.getProcess(processName));\r
+            compBinding.setProcessor(processor);\r
+            processor.getProcessList().add(pn.getProcess(processName));\r
+            map.getCompBindList().add(compBinding);\r
+        }\r
+\r
+        //schedules\r
+        for (Processor p : processors) {\r
+            Schedule s = new Schedule(p.getName() + "schedule");\r
+            s.setSchedPolicy(SchedulingPolicy.FIFO);\r
+            s.setResource(p);\r
+            for (Process process : p.getProcessList()) {\r
+                ScheduleEntry entry = new ScheduleEntry(\r
+                        process.getName());\r
+                entry.setConsumer(process);\r
+                s.getEntryList().add(entry);\r
+            }\r
+            map.getScheduleList().add(s);\r
+        }\r
+\r
+        //binding of channels\r
+        for (Channel c : pn.getChannelList()) {\r
+            String originProcess = c.getOrigin().getName();\r
+            String targetProcess = c.getTarget().getName();\r
+\r
+            String originBinding = _binding[getProcessIndex(\r
+                    originProcess)];\r
+            String targetBinding = _binding[getProcessIndex(\r
+                    targetProcess)];\r
+\r
+            Pattern pattern0 = Pattern.compile(\r
+                    "tile_(\\d)\\.(arm)|tile_(\\d)\\.(magic)");\r
+            Matcher matcher0 = pattern0.matcher(originBinding);\r
+            Pattern pattern1 = Pattern.compile(\r
+                    "tile_(\\d)\\.(arm)|tile_(\\d)\\.(magic)");\r
+            Matcher matcher1 = pattern1.matcher(targetBinding);\r
+\r
+            if (!matcher0.matches() || !matcher1.matches()) {\r
+                System.out.println("binding needs to comply to the"\r
+                        + " following regular expression: "\r
+                        + "tile_(\\d)\\.(arm)|tile_(\\d)\\.(magic)");\r
+                System.exit(-1);\r
+            }\r
+\r
+            int srcIndex = Integer.valueOf(matcher0.group(1));\r
+            int dstIndex = Integer.valueOf(matcher1.group(1));\r
+            String srcProcessor = matcher0.group(2);\r
+            String dstProcessor = matcher1.group(2);\r
+\r
+            String writePath = "";\r
+            String readPath = "";\r
+\r
+            if (srcIndex == dstIndex) {\r
+                if (srcProcessor.equals("arm")) {\r
+                    writePath = "tile_" + srcIndex + ".rdmtodxm";\r
+                } else {\r
+                    writePath = "tile_" + srcIndex + ".ddmtodxm";\r
+                }\r
+            } else {\r
+                if (srcProcessor.equals("arm")) {\r
+                    writePath = "tile_" + srcIndex + ".rdmtodnp_"\r
+                            + dstIndex;\r
+                } else {\r
+                    writePath = "tile_" + srcIndex + ".ddmtodnp_"\r
+                            + dstIndex;\r
+                }\r
+            }\r
+\r
+            if (dstProcessor.equals("arm")) {\r
+                readPath = "tile_" + dstIndex + ".rdmfromdxm";\r
+            } else {\r
+                readPath = "tile_" + dstIndex + ".ddmfromdxm";\r
+            }\r
+\r
+            CommunicationBinding commBinding = new CommunicationBinding(\r
+                    c.getName() + "binding");\r
+            commBinding.setChannel(c);\r
+            commBinding.setWritePath(new WritePath(writePath));\r
+            commBinding.setReadPath(new ReadPath(readPath));\r
+            map.getCommBindList().add(commBinding);\r
+        }\r
+        System.out.println("Finished.");\r
+    }\r
+\r
+    /**\r
+     *\r
+     * @param processName\r
+     * @return\r
+     */\r
+    protected int getProcessIndex(String processName) {\r
+        for (int i = 0; i < _processes.length; i++) {\r
+            if (_processes[i].equals(processName)) {\r
+                return i;\r
+            }\r
+        }\r
+        System.out.println("Error: Could not find process "\r
+                + processName + ".");\r
+        System.exit(-1);\r
+        return 0;\r
+    }\r
+\r
+    /**\r
+     *\r
+     * @param map\r
+     */\r
+    public void generateMappingXml(Mapping map, String filename) {\r
+        System.out.print("Generate mapping XML. ");\r
+        StringBuffer buffer = new StringBuffer();\r
+        map.accept(new MapXmlVisitor(buffer));\r
+        try {\r
+            java.io.BufferedWriter writer =\r
+                    new java.io.BufferedWriter(\r
+                    new java.io.FileWriter(filename));\r
+            writer.write(buffer.toString());\r
+            writer.close();\r
+        } catch (java.io.IOException e) {\r
+            System.out.println("Could not write XML file.");\r
+            System.exit(-1);\r
+        }\r
+        System.out.println("Finished.");\r
+    }\r
+\r
+    /**\r
+     *\r
+     * @param args\r
+     */\r
+    public static void main(String args[]) {\r
+        /*\r
+        Pattern pattern = Pattern.compile("tile_(\\d)\\.");\r
+        Matcher matcher = pattern.matcher("tile_3.");\r
+        matcher.matches();\r
+        System.out.println(matcher.group(1));\r
+        */\r
+\r
+        String appName = "exampleAuto";\r
+        String path = System.getProperty("user.dir") + "/" + appName + "/";\r
+        File dir = new File(path);\r
+        dir.mkdirs();\r
+        dir = new File(path + "src/");\r
+        dir.mkdirs();\r
+\r
+        System.out.println("Generate application \"" + appName + "\""\r
+                + " in directory \"" + path + "\".");\r
+        ApplicationGenerator appGen = new ApplicationGenerator();\r
+        //appGen.generateIndpendentPipelines2(16, 4, 10000000);\r
+        appGen.generatePipeline(64, 10);\r
+        //appGen.generateIndependentTasks(64);\r
+        ProcessNetwork pn = new ProcessNetwork(appName);\r
+        appGen.generateProcessNetwork(pn);\r
+        appGen.generateProcessNetworkXml(pn, path + appName + ".xml");\r
+        appGen.generateCode(pn, path + "src/");\r
+        Mapping map = new Mapping("mapping");\r
+        appGen.generateMapping(pn, map);\r
+        appGen.generateMappingXml(map, path + "mapping.xml");\r
+        System.out.println("Done.");\r
+    }\r
+}
\ No newline at end of file