From 651f16b3d46a0a7c0bbf20dfa77998c73122af78 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 10 Nov 2021 01:27:00 -0600 Subject: [PATCH 001/121] First prototype of the scheduler --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 7 ++++--- test/C/src/concurrent/ThreadedThreaded.lf | 4 +++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 0a48d7a904..8751a5947c 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 0a48d7a9046b65b3af20e003375355abc1f5d103 +Subproject commit 8751a5947c3b4be46a957227285e7832fff65d71 diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index c1cccd513a..448392b907 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -532,7 +532,8 @@ class CGenerator extends GeneratorBase { if (targetConfig.threads === 0) { coreFiles.add("reactor.c") } else { - coreFiles.add("reactor_threaded.c") + coreFiles.add("threaded/scheduler.c") + coreFiles.add("threaded/reactor_threaded.c") } addPlatformFiles(coreFiles); @@ -4958,7 +4959,7 @@ class CGenerator extends GeneratorBase { } } - /** Generate #include of pqueue.c and either reactor.c or reactor_threaded.c + /** Generate #include of pqueue.c and either reactor.c or threaded/reactor_threaded.c * depending on whether threads are specified in target directive. * As a side effect, this populates the runCommand and compileCommand * private variables if such commands are specified in the target directive. @@ -5084,7 +5085,7 @@ class CGenerator extends GeneratorBase { /** Add necessary source files specific to the target language. */ protected def includeTargetLanguageSourceFiles() { if (targetConfig.threads > 0) { - pr("#include \"core/reactor_threaded.c\"") + pr("#include \"core/threaded/reactor_threaded.c\"") } else { pr("#include \"core/reactor.c\"") } diff --git a/test/C/src/concurrent/ThreadedThreaded.lf b/test/C/src/concurrent/ThreadedThreaded.lf index 4b582acee4..3ef5d921ee 100644 --- a/test/C/src/concurrent/ThreadedThreaded.lf +++ b/test/C/src/concurrent/ThreadedThreaded.lf @@ -10,7 +10,9 @@ target C { timeout: 2 sec, tracing: true, flags: "", // Disable compiler optimization so that TakeTime actually takes time. - threads: 4 + threads: 4, + build-type: RelWithDebInfo, + logging: DEBUG }; reactor Source { timer t(0, 200 msec); From 5945c88fe9c9d7fb4f72c1d89c84f3f1799c717d Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 10 Nov 2021 23:54:19 -0600 Subject: [PATCH 002/121] Updated reactor c submodule Using a still new and very rough but functional multi-threaded scheduler --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 8751a5947c..64be80c9b8 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 8751a5947c3b4be46a957227285e7832fff65d71 +Subproject commit 64be80c9b827235b6cfc0c488272496af4a9a98e diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 448392b907..b618845db3 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -818,7 +818,7 @@ class CGenerator extends GeneratorBase { bool _lf_trigger_shutdown_reactions() { for (int i = 0; i < _lf_shutdown_reactions_size; i++) { if (_lf_shutdown_reactions[i] != NULL) { - _lf_enqueue_reaction(_lf_shutdown_reactions[i]); + _lf_enqueue_reaction(_lf_shutdown_reactions[i], -1); } } // Return true if there are shutdown reactions. @@ -929,7 +929,7 @@ class CGenerator extends GeneratorBase { pr(''' for (int i = 0; i < _lf_startup_reactions_size; i++) { if (_lf_startup_reactions[i] != NULL) { - _lf_enqueue_reaction(_lf_startup_reactions[i]); + _lf_enqueue_reaction(_lf_startup_reactions[i], -1); } } ''') From 14232304ae1dd9908b641d229ec3ff4a2fb801ee Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 11 Nov 2021 00:16:04 -0600 Subject: [PATCH 003/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 64be80c9b8..088df58bae 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 64be80c9b827235b6cfc0c488272496af4a9a98e +Subproject commit 088df58bae7577ebeb0094da348616b0cc2b1ce1 From 449e34cf862ded2db93ea6f2768f809a0b5e956a Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 11 Nov 2021 00:29:46 -0600 Subject: [PATCH 004/121] Updated reactor c --- org.lflang/src/lib/c/reactor-c | 2 +- test/C/src/concurrent/ThreadedThreaded.lf | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 088df58bae..508f36de8e 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 088df58bae7577ebeb0094da348616b0cc2b1ce1 +Subproject commit 508f36de8ecedf6a1093dd4451355cbdd5a2d6e2 diff --git a/test/C/src/concurrent/ThreadedThreaded.lf b/test/C/src/concurrent/ThreadedThreaded.lf index 3ef5d921ee..4b582acee4 100644 --- a/test/C/src/concurrent/ThreadedThreaded.lf +++ b/test/C/src/concurrent/ThreadedThreaded.lf @@ -10,9 +10,7 @@ target C { timeout: 2 sec, tracing: true, flags: "", // Disable compiler optimization so that TakeTime actually takes time. - threads: 4, - build-type: RelWithDebInfo, - logging: DEBUG + threads: 4 }; reactor Source { timer t(0, 200 msec); From b87e13f080f64a3e856d96c5253b62e2636da050 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 11 Nov 2021 00:33:04 -0600 Subject: [PATCH 005/121] Removed tracing from benchmark --- benchmark/C/Savina/src/micro/Throughput.lf | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/benchmark/C/Savina/src/micro/Throughput.lf b/benchmark/C/Savina/src/micro/Throughput.lf index 4571428197..2221d46b5a 100644 --- a/benchmark/C/Savina/src/micro/Throughput.lf +++ b/benchmark/C/Savina/src/micro/Throughput.lf @@ -61,8 +61,7 @@ target C { ]]] */ threads: 2, /// [[[end]]] - flags: "-lm", - tracing: true + flags: "-lm" }; From 796d27270c58f65d4f1956712371afd838e7d599 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 11 Nov 2021 00:33:45 -0600 Subject: [PATCH 006/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 508f36de8e..e65ce7c3bb 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 508f36de8ecedf6a1093dd4451355cbdd5a2d6e2 +Subproject commit e65ce7c3bb07d93612120a204b9121b4179d0a27 From 2978eb002e3b735f76e36ef1a8e62f4b8227067c Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 11 Nov 2021 00:41:17 -0600 Subject: [PATCH 007/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index e65ce7c3bb..2ec4eb8374 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit e65ce7c3bb07d93612120a204b9121b4179d0a27 +Subproject commit 2ec4eb8374a9f002e01cb310a07464c99948c838 From 70d32d8812f0efbe1c1de65bce0c46f61fbb1011 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Fri, 12 Nov 2021 01:03:19 -0600 Subject: [PATCH 008/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 4a89e8eb11..9283c76845 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 4a89e8eb112000e4bd9343bff76d8518f552968d +Subproject commit 9283c7684537a4f545638ba866f9c431b73f079e From 3ea5dede59dfcd8b53602bfe6520057dc074bbec Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Fri, 12 Nov 2021 20:42:45 -0600 Subject: [PATCH 009/121] Adjusted path to util files --- .../src/org/lflang/generator/c/CGenerator.xtend | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index fdfa3aa26e..90281d9e8d 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -524,14 +524,18 @@ class CGenerator extends GeneratorBase { var coreFiles = newArrayList( "reactor_common.c", "reactor.h", - "pqueue.c", - "pqueue.h", "tag.h", "tag.c", "trace.h", "trace.c", - "util.h", - "util.c", + "utils/pqueue.c", + "utils/pqueue.h", + "utils/vector.c", + "utils/vector.h", + "utils/semaphore.h", + "utils/semaphore.c", + "utils/util.h", + "utils/util.c", "platform.h" ); if (targetConfig.threads === 0) { @@ -999,8 +1003,8 @@ class CGenerator extends GeneratorBase { // Create the array that will contain pointers to is_present fields to reset on each step. _lf_is_present_fields_size = «startTimeStepIsPresentCount»; _lf_is_present_fields = (bool**)malloc(«startTimeStepIsPresentCount» * sizeof(bool*)); - _lf_is_present_fields_abbreviated = (bool**)malloc(«startTimeStepIsPresentCount» * sizeof(bool*)); - _lf_is_present_fields_abbreviated_size = 0; + _lf_is_present_fields_abbreviated = (bool**)malloc(«startTimeStepIsPresentCount» * sizeof(bool*)); + _lf_is_present_fields_abbreviated_size = 0; ''') } From ddb69365dc979af7824f0f3672bde76c3a324af1 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Fri, 12 Nov 2021 20:43:02 -0600 Subject: [PATCH 010/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 9283c76845..9f30e2d0ed 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 9283c7684537a4f545638ba866f9c431b73f079e +Subproject commit 9f30e2d0ed28c45ddae747813934fc0fc4f73bd6 From 8fc8b8e475bdfba515851d01f895449f04788d19 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 12:04:37 -0600 Subject: [PATCH 011/121] Updated reactor-c-py --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index ca321197e7..d7135de79e 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit ca321197e7b25dbee2d4baccd4bb1e6df23bfc1c +Subproject commit d7135de79e5ad4fa50e4847ed39d7dad719dd1b9 From a65193915157e5bf8b58b89dfbe61a45bef4478c Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 12:05:56 -0600 Subject: [PATCH 012/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 9f30e2d0ed..0e2e6b9a4b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 9f30e2d0ed28c45ddae747813934fc0fc4f73bd6 +Subproject commit 0e2e6b9a4bc1371a248f190c5d1b21336b2c3f42 From 1875e75dadfb3f65a7e0d8e046bcf3ba6519f40f Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 12:09:35 -0600 Subject: [PATCH 013/121] Check that Python functions are loaded properly --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index b4b217e9d7..e5d429c915 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -1681,6 +1681,9 @@ class PythonGenerator extends CGenerator { «nameOfSelfStruct»->_lf_name, «IF (instance.bankIndex > -1)» «instance.bankIndex» «ELSE» «0» «ENDIF», "«pythonFunctionName»"); + if («nameOfSelfStruct»->_lf_py_reaction_function_«reaction.reactionIndex» == NULL) { + error_print_and_exit("Could not load function «instance.name» reaction_function_«reaction.reactionIndex»."); + } ''') if (reaction.definition.deadline !== null) { @@ -1690,6 +1693,10 @@ class PythonGenerator extends CGenerator { «nameOfSelfStruct»->_lf_name, «IF (instance.bankIndex > -1)» «instance.bankIndex» «ELSE» «0» «ENDIF», "deadline_function_«reaction.reactionIndex»"); + + if («nameOfSelfStruct»->_lf_py_deadline_function_«reaction.reactionIndex» == NULL) { + error_print_and_exit("Could not load function «instance.name» deadline_function_«reaction.reactionIndex»."); + } ''') } From 427a2f2133821b15814eb3525817ab4516e92b47 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 13:04:35 -0600 Subject: [PATCH 014/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 0e2e6b9a4b..e017d51ba7 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 0e2e6b9a4bc1371a248f190c5d1b21336b2c3f42 +Subproject commit e017d51ba7f0150267991f9a1549e5fb28e121a8 From ab2ae61636a1e0dee1d8d58d1d0ad5bff15b29b0 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 13:07:47 -0600 Subject: [PATCH 015/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index e017d51ba7..98380fe44c 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit e017d51ba7f0150267991f9a1549e5fb28e121a8 +Subproject commit 98380fe44c674600f1272b3dd8234768dcba0b1c From 572c1e6d7e7d1dcc92d7bebf7b0eb0e341117ba0 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 22:51:44 -0600 Subject: [PATCH 016/121] FIXME: The performance of TimeLimitThreaded is terrible with the new scheduler --- test/C/src/concurrent/TimeLimitThreaded.lf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/C/src/concurrent/TimeLimitThreaded.lf b/test/C/src/concurrent/TimeLimitThreaded.lf index b667c6ca4c..b59b40547e 100644 --- a/test/C/src/concurrent/TimeLimitThreaded.lf +++ b/test/C/src/concurrent/TimeLimitThreaded.lf @@ -31,15 +31,15 @@ reactor Destination { =} reaction(shutdown) {= printf("**** shutdown reaction invoked.\n"); - if (self->s != 10000002) { - fprintf(stderr, "ERROR: Expected 10000002 but got %d.\n", self->s); + if (self->s != 10002) { + fprintf(stderr, "ERROR: Expected 1000002 but got %d.\n", self->s); exit(1); } info_print("Approx. time per reaction: %lldns", get_elapsed_physical_time()/(self->s+1)); =} } main reactor (period:time(1 usec)) { - timer stop(10 secs); + timer stop(10 msecs); reaction(stop) {= request_stop(); =} From 5e5b70eb32fa74a6e00f9ad040943d2a40e1810c Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 22:52:02 -0600 Subject: [PATCH 017/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 98380fe44c..ed52b77a45 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 98380fe44c674600f1272b3dd8234768dcba0b1c +Subproject commit ed52b77a45d87b9bac05f140ab0ac1ffc27a78c2 From a63303d98bf014efa261373c4d74fce3a35c5f09 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 23:03:48 -0600 Subject: [PATCH 018/121] Added a scheduler.h --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index ed52b77a45..b30dc4429b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit ed52b77a45d87b9bac05f140ab0ac1ffc27a78c2 +Subproject commit b30dc4429bbeb37e1b35073c12752a8276d8d8f8 diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 90281d9e8d..5e7aca9c61 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -541,6 +541,7 @@ class CGenerator extends GeneratorBase { if (targetConfig.threads === 0) { coreFiles.add("reactor.c") } else { + coreFiles.add("threaded/scheduler.h") coreFiles.add("threaded/scheduler.c") coreFiles.add("threaded/reactor_threaded.c") } From 3029508a32fa2601a051697d92bbf2b6888cdef5 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 13 Nov 2021 23:04:56 -0600 Subject: [PATCH 019/121] Updated reactor-c-py --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index d7135de79e..609ebc7322 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit d7135de79e5ad4fa50e4847ed39d7dad719dd1b9 +Subproject commit 609ebc7322e338e439c5d5d394ff3aa11fd26c8f From cdaa951d360d6bf99c7b06442475dcc163f859a8 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 14 Nov 2021 10:42:23 -0600 Subject: [PATCH 020/121] Updated test since port values are read-only --- test/Python/src/StructAsTypeDirect.lf | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/Python/src/StructAsTypeDirect.lf b/test/Python/src/StructAsTypeDirect.lf index 4620decb6d..62d8dcc33a 100644 --- a/test/Python/src/StructAsTypeDirect.lf +++ b/test/Python/src/StructAsTypeDirect.lf @@ -7,17 +7,18 @@ import hello reactor Source { output out; reaction(startup) -> out {= - out.value = hello.hello() - out.value.name = "Earth" - out.value.value = 42 - out.set(out.value) + out_value = out.value + out_value = hello.hello() + out_value.name = "Earth" + out_value.value = 42 + out.set(out_value) =} } // expected parameter is for testing. reactor Print(expected(42)) { input _in; reaction(_in) {= - print("Received: name = {:s}, value = {:d}\n".format(_in.value.name, _in.value.value)) + print("Received: name = {:s}, value = {:d}".format(_in.value.name, _in.value.value)) if _in.value.value != self.expected: sys.stderr.write("ERROR: Expected value to be {:d}.\n".format(self.expected)) exit(1) From 6a74edf26bd888940e6efde47cb262d8765171fa Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 14 Nov 2021 10:50:08 -0600 Subject: [PATCH 021/121] Space in comment --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index e5d429c915..9b7b88b4e2 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -556,7 +556,7 @@ class PythonGenerator extends CGenerator { val reactor = decl.toDefinition var StringBuilder temporary_code = new StringBuilder() - temporary_code.append(''' #Define parameters and their default values + temporary_code.append(''' # Define parameters and their default values ''') for (param : decl.toDefinition.allParameters) { From 5c35c253fa6a3bf153fa3229499b19afc3052246 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 14 Nov 2021 13:11:33 -0600 Subject: [PATCH 022/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index b30dc4429b..545b9b0c96 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit b30dc4429bbeb37e1b35073c12752a8276d8d8f8 +Subproject commit 545b9b0c96f77f13137ab889b2cb6f3307d524f8 From 8ddb81f61ae93dfeac17b9ee332c1f8c6d6b8ade Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 5 Dec 2021 00:31:50 -0600 Subject: [PATCH 023/121] Added a scheduler target property --- org.lflang/src/org/lflang/TargetConfig.java | 3 +++ org.lflang/src/org/lflang/TargetProperty.java | 20 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 1906921fe3..73d3f68224 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -36,6 +36,7 @@ import org.lflang.TargetProperty.ClockSyncMode; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TargetProperty.LogLevel; +import org.lflang.TargetProperty.SchedulerOptions; import org.lflang.generator.rust.CargoDependencySpec; import org.lflang.generator.rust.RustTargetConfig; import org.lflang.lf.TimeUnit; @@ -194,6 +195,8 @@ public class TargetConfig { /** Whether all reactors are to be generated into a single target language file. */ public boolean singleFileProject = false; + + public SchedulerOptions schedulerType = SchedulerOptions.GEDF_NP; /** * The number of worker threads to deploy. The default is zero (i.e., diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 2518ac396e..df89a3c719 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -314,6 +314,16 @@ public enum TargetProperty { Arrays.asList(Target.CPP), (config, value, err) -> { config.runtimeVersion = ASTUtils.toText(value); }), + + + /** + * Directive for specifying a specific runtime scheduler, if supported. + */ + SCHEDULER("scheduler", UnionType.SCHEDULER_UNION, + Arrays.asList(Target.C, Target.CCPP, Target.Python), (config, value, err) -> { + config.schedulerType = (SchedulerOptions) UnionType.SCHEDULER_UNION + .forName(ASTUtils.toText(value)); + }), /** * Directive to specify that all code is generated in a single file. @@ -750,6 +760,7 @@ public enum UnionType implements TargetPropertyType { BUILD_TYPE_UNION(Arrays.asList(BuildType.values()), null), COORDINATION_UNION(Arrays.asList(CoordinationType.values()), CoordinationType.CENTRALIZED), + SCHEDULER_UNION(Arrays.asList(SchedulerOptions.values()), SchedulerOptions.GEDF_NP), LOGGING_UNION(Arrays.asList(LogLevel.values()), LogLevel.INFO), CLOCK_SYNC_UNION(Arrays.asList(ClockSyncMode.values()), ClockSyncMode.INITIAL), @@ -1265,6 +1276,15 @@ public String toString() { return this.name().toLowerCase(); } } + + /** + * Supported schedulers. + * @author{Soroush Bateni } + */ + public enum SchedulerOptions { + GEDF_NP, // Global EDF non-preemptive + PEDF_NP; // Partitioned EDF non-preemptive + } /** * Tracing options. From 43ed890b49c5fd8e1a3f690ab75f793c031dd1bf Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 5 Dec 2021 00:36:49 -0600 Subject: [PATCH 024/121] Added support for swapping schedulers to the CGenerator --- .../src/org/lflang/generator/c/CGenerator.xtend | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 5e7aca9c61..7051021a49 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -530,6 +530,7 @@ class CGenerator extends GeneratorBase { "trace.c", "utils/pqueue.c", "utils/pqueue.h", + "utils/pqueue_support.h", "utils/vector.c", "utils/vector.h", "utils/semaphore.h", @@ -541,8 +542,7 @@ class CGenerator extends GeneratorBase { if (targetConfig.threads === 0) { coreFiles.add("reactor.c") } else { - coreFiles.add("threaded/scheduler.h") - coreFiles.add("threaded/scheduler.c") + addSchedulerFiles(coreFiles); coreFiles.add("threaded/reactor_threaded.c") } @@ -925,6 +925,19 @@ class CGenerator extends GeneratorBase { refreshProject() } + /** + * Add files needed for the proper function of the runtime scheduler to + * {@code coreFiles} and {@link TargetConfig#compileAdditionalSources}. + */ + def addSchedulerFiles(ArrayList coreFiles) { + coreFiles.add("threaded/scheduler.h") + coreFiles.add("threaded/scheduler_" + targetConfig.schedulerType.toString() + ".c"); + targetConfig.compileAdditionalSources.add( + "core" + File.separator + "threaded" + File.separator + + "scheduler_" + targetConfig.schedulerType.toString() + ".c" + ); + } + /** * Generate the _lf_trigger_startup_reactions function. */ From 56ad39ff771bff2215dcb7d0f0743a3b1cc507fd Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 5 Dec 2021 00:41:29 -0600 Subject: [PATCH 025/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 545b9b0c96..f37671ff6c 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 545b9b0c96f77f13137ab889b2cb6f3307d524f8 +Subproject commit f37671ff6c40f877dd6f107519c0278864ac949f From ff098e997533446c0d353239a5b8db8066010cb0 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 5 Dec 2021 00:51:49 -0600 Subject: [PATCH 026/121] Fixed compile error --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index d4a0459682..0933215f31 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -1684,8 +1684,8 @@ class PythonGenerator extends CGenerator { «nameOfSelfStruct»->_lf_name, «IF (instance.bankIndex > -1)» «instance.bankIndex» «ELSE» «0» «ENDIF», "«pythonFunctionName»"); - if («nameOfSelfStruct»->_lf_py_reaction_function_«reaction.reactionIndex» == NULL) { - error_print_and_exit("Could not load function «instance.name» reaction_function_«reaction.reactionIndex»."); + if («nameOfSelfStruct»->_lf_py_reaction_function_«reaction.index» == NULL) { + error_print_and_exit("Could not load function «instance.name» reaction_function_«reaction.index»."); } ''') From 69386f47b109e12754c5347caa93c308b4c4a02a Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 5 Dec 2021 11:36:55 -0600 Subject: [PATCH 027/121] Updated reactor-c module --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index f37671ff6c..fff8933144 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit f37671ff6c40f877dd6f107519c0278864ac949f +Subproject commit fff8933144a8487ab071c8a0646b67a1f6dfe6dd From b6487676d84c8e392dd5cdb7062f878fb9127a11 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 5 Dec 2021 14:10:46 -0600 Subject: [PATCH 028/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index fff8933144..a10e71660e 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit fff8933144a8487ab071c8a0646b67a1f6dfe6dd +Subproject commit a10e71660e6a4f215e0b08ebb4bf2efa2af93463 From 3e7fb1f282ebfc1868ff73806eccb583fada4dc5 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 5 Dec 2021 21:43:58 -0600 Subject: [PATCH 029/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index a10e71660e..fbfddae837 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit a10e71660e6a4f215e0b08ebb4bf2efa2af93463 +Subproject commit fbfddae8373c00a4f692fdd5f4d0ea61706a6391 From 3adcafcc099ea876cfc65af8bcf218450ba656dd Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 6 Dec 2021 08:09:09 -0600 Subject: [PATCH 030/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index fbfddae837..6c7b45bbff 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit fbfddae8373c00a4f692fdd5f4d0ea61706a6391 +Subproject commit 6c7b45bbff6135ac4de2c63899df26443399755f From 4f9fa739a1ce2ff473d92383cec18027db03cb80 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 6 Dec 2021 19:04:24 -0600 Subject: [PATCH 031/121] Fixed an issue with Windows-style paths for the Python target --- org.lflang/src/org/lflang/FileConfig.java | 9 +++++++++ .../org/lflang/generator/python/PythonGenerator.xtend | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/FileConfig.java b/org.lflang/src/org/lflang/FileConfig.java index c243d13331..abaca55502 100644 --- a/org.lflang/src/org/lflang/FileConfig.java +++ b/org.lflang/src/org/lflang/FileConfig.java @@ -713,6 +713,15 @@ public static IPath toIPath(URI uri) throws IOException { public static String toUnixString(Path path) { return path.toString().replace('\\', '/'); } + + /** + * Convert a given string path to a unix-style string. + * + * This ensures that '/' is used instead of '\' as file separator. + */ + public static String toUnixString(String path) { + return path.replace('\\', '/'); + } /** * Check whether a given file (i.e., a relative path) exists in the given diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index 0933215f31..60ace37d21 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -781,7 +781,7 @@ class PythonGenerator extends CGenerator { from setuptools import setup, Extension linguafranca«topLevelName»module = Extension("LinguaFranca«topLevelName»", - sources = ["«topLevelName».c", «FOR src : targetConfig.compileAdditionalSources SEPARATOR ", "» "«src»"«ENDFOR»], + sources = ["«topLevelName».c", «FOR src : targetConfig.compileAdditionalSources SEPARATOR ", "» "«FileConfig.toUnixString(src)»"«ENDFOR»], define_macros=[('MODULE_NAME', 'LinguaFranca«topLevelName»')«IF (targetConfig.threads !== 0 || (targetConfig.tracing !== null))», ('NUMBER_OF_WORKERS', '«targetConfig.threads»')«ENDIF»]) From bb8e9671b86796b4b8f2559a4a0ecf99ba3a8de2 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 7 Dec 2021 17:59:45 -0600 Subject: [PATCH 032/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 6c7b45bbff..3f0629bc91 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 6c7b45bbff6135ac4de2c63899df26443399755f +Subproject commit 3f0629bc9145e45a386b24f9169cd2a323b9f054 From 515055a6b75d050d66cf89bc985d3b3fa9df8150 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 7 Dec 2021 18:01:32 -0600 Subject: [PATCH 033/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 3f0629bc91..2316892b2b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 3f0629bc9145e45a386b24f9169cd2a323b9f054 +Subproject commit 2316892b2b1f27de5b87b91e84bcc180c1016d6e From 03b9deaf2bf31f6ebec277aa333f227d257f18a5 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 7 Dec 2021 18:05:25 -0600 Subject: [PATCH 034/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 2316892b2b..418125db83 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 2316892b2b1f27de5b87b91e84bcc180c1016d6e +Subproject commit 418125db83092700faed6536ea6ab711c5186fce From 0a230cb9f240567cc542526ec8c5b2f96ffab85e Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 8 Dec 2021 00:17:08 -0600 Subject: [PATCH 035/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 418125db83..c4c42b823d 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 418125db83092700faed6536ea6ab711c5186fce +Subproject commit c4c42b823d6a314702c4496425e8df6992230553 From 26c4f9b16a2e4cc747915d22500521619f300709 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 8 Dec 2021 14:41:06 -0600 Subject: [PATCH 036/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c4c42b823d..86a0e2843b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c4c42b823d6a314702c4496425e8df6992230553 +Subproject commit 86a0e2843b58c4449dab56780745548d8df2d344 From 82e315d5cdc2c6c1ec7f31262d7cdeacbd843500 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 8 Dec 2021 18:30:28 -0600 Subject: [PATCH 037/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 86a0e2843b..e8dd8a5102 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 86a0e2843b58c4449dab56780745548d8df2d344 +Subproject commit e8dd8a51020f4b53ed26462f1af98a01531e2f5d From 2c00f0f58e55389c5cd319985ea79e2a1f69704b Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 8 Dec 2021 19:51:37 -0600 Subject: [PATCH 038/121] Added test for all non-default schedulers --- .../src/org/lflang/tests/AbstractTest.java | 32 +++++++++++++++++++ .../src/org/lflang/tests/Configurators.java | 7 ++++ .../src/org/lflang/tests/TestBase.java | 2 ++ .../src/org/lflang/tests/runtime/CTest.java | 5 +++ org.lflang/src/org/lflang/TargetConfig.java | 3 +- org.lflang/src/org/lflang/TargetProperty.java | 7 +++- .../org/lflang/generator/GeneratorBase.xtend | 7 ++++ 7 files changed, 61 insertions(+), 2 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java index 02b0d42196..dba6489b1d 100644 --- a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java +++ b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java @@ -7,6 +7,7 @@ import org.junit.jupiter.api.Test; import org.lflang.ASTUtils; import org.lflang.Target; +import org.lflang.TargetProperty.SchedulerOptions; import org.lflang.tests.TestRegistry.TestCategory; /** @@ -63,6 +64,13 @@ protected boolean supportsDockerOption() { return false; } + + /** + * Whether to test different {@link org.lflang.TargetProperty#SchedulerOptions}. + */ + protected boolean supportsSchedulerSwapping() { + return false; + } @Test public void runExampleTests() { @@ -192,4 +200,28 @@ public void runWithFourThreads() { true ); } + + @Test + public void runWithNonDefaultSchedulers() { + Assumptions.assumeTrue(supportsSchedulerSwapping(), Message.NO_SCHED_SWAPPING_SUPPORT); + for (SchedulerOptions scheduler: SchedulerOptions.values()) { + if (scheduler == SchedulerOptions.getDefault()) continue; + + this.runTestsForTargets( + Message.DESC_SCHED_SWAPPING + scheduler.toString() +".", + Configurators::noneExcluded, + test -> { + test.getContext() + .getArgs() + .setProperty( + "scheduler", + scheduler.toString() + ); + return true; + }, + TestLevel.EXECUTION, + true + ); + } + } } diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index 872a4341b7..b1847cfe82 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -95,4 +95,11 @@ public static boolean isExcluded(TestCategory category) { excluded |= (TestBase.isWindows() && (category == TestCategory.SERIALIZATION || category == TestCategory.TARGET)); return !excluded; } + + /** + * Report all test categories as included. + */ + public static boolean noneExcluded(TestCategory category) { + return true; + } } diff --git a/org.lflang.tests/src/org/lflang/tests/TestBase.java b/org.lflang.tests/src/org/lflang/tests/TestBase.java index 3c558c8ea7..a6e69a9897 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestBase.java +++ b/org.lflang.tests/src/org/lflang/tests/TestBase.java @@ -126,6 +126,7 @@ public static class Message { public static final String NO_DOCKER_SUPPORT = "Target does not support the 'docker' property."; public static final String NO_DOCKER_TEST_SUPPORT = "Docker tests are only supported on Linux."; public static final String NO_GENERICS_SUPPORT = "Target does not support generic types."; + public static final String NO_SCHED_SWAPPING_SUPPORT = "Target does not support runtime scheduler swapping."; /* Descriptions of collections of tests. */ public static final String DESC_SERIALIZATION = "Run serialization tests (threads = 0)."; @@ -142,6 +143,7 @@ public static class Message { public static final String DESC_TARGET_SPECIFIC = "Run target-specific tests (threads = 0)"; public static final String DESC_AS_CCPP = "Running C tests as CCpp."; public static final String DESC_FOUR_THREADS = "Run non-concurrent and non-federated tests (threads = 4)."; + public static final String DESC_SCHED_SWAPPING = "Running with non-default runtime scheduler "; /* Missing dependency messages */ public static final String MISSING_DOCKER = "Executable 'docker' not found or 'docker' daemon thread not running"; diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index c8909202f2..5ce0b0b89f 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -63,6 +63,11 @@ protected boolean supportsFederatedExecution() { protected boolean supportsDockerOption() { return true; } + + @Override + protected boolean supportsSchedulerSwapping() { + return true; + } @Test @Override diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 73d3f68224..5ef62c2147 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -196,7 +196,8 @@ public class TargetConfig { /** Whether all reactors are to be generated into a single target language file. */ public boolean singleFileProject = false; - public SchedulerOptions schedulerType = SchedulerOptions.GEDF_NP; + /** What runtime scheduler to use. */ + public SchedulerOptions schedulerType = SchedulerOptions.getDefault(); /** * The number of worker threads to deploy. The default is zero (i.e., diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index e0bbd0852f..2cd62a2ad7 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -761,7 +761,7 @@ public enum UnionType implements TargetPropertyType { BUILD_TYPE_UNION(Arrays.asList(BuildType.values()), null), COORDINATION_UNION(Arrays.asList(CoordinationType.values()), CoordinationType.CENTRALIZED), - SCHEDULER_UNION(Arrays.asList(SchedulerOptions.values()), SchedulerOptions.GEDF_NP), + SCHEDULER_UNION(Arrays.asList(SchedulerOptions.values()), SchedulerOptions.getDefault()), LOGGING_UNION(Arrays.asList(LogLevel.values()), LogLevel.INFO), CLOCK_SYNC_UNION(Arrays.asList(ClockSyncMode.values()), ClockSyncMode.INITIAL), @@ -1285,6 +1285,11 @@ public String toString() { public enum SchedulerOptions { GEDF_NP, // Global EDF non-preemptive PEDF_NP; // Partitioned EDF non-preemptive + + public static SchedulerOptions getDefault() { + return GEDF_NP; + } + } /** diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.xtend b/org.lflang/src/org/lflang/generator/GeneratorBase.xtend index 322d925bab..1d85a993b0 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.xtend +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.xtend @@ -85,6 +85,7 @@ import org.lflang.validation.AbstractLFValidator import static extension org.lflang.ASTUtils.* import static extension org.lflang.JavaAstUtils.* +import org.lflang.TargetProperty.SchedulerOptions /** * Generator base class for shared code between code generators. @@ -304,6 +305,12 @@ abstract class GeneratorBase extends AbstractLFValidator implements TargetTypes if (context.args.containsKey("threads")) { targetConfig.threads = Integer.parseInt(context.args.getProperty("threads")) } + if (context.args.containsKey("scheduler")) { + targetConfig.schedulerType = SchedulerOptions::valueOf( + SchedulerOptions, + context.args.getProperty("scheduler") + ) + } if (context.args.containsKey("target-compiler")) { targetConfig.compiler = context.args.getProperty("target-compiler") } From bcc27e6b1d1a47e8025d3065787b94fc034a9fa3 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 8 Dec 2021 20:20:46 -0600 Subject: [PATCH 039/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index e8dd8a5102..7c0d499888 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit e8dd8a51020f4b53ed26462f1af98a01531e2f5d +Subproject commit 7c0d499888261b944b7f67f0dd662359e198517f From 15ce710a7cf480e2711e4ce447934c864a483ccb Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 8 Dec 2021 20:25:04 -0600 Subject: [PATCH 040/121] Reverted test to its original form --- test/C/src/concurrent/TimeLimitThreaded.lf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/C/src/concurrent/TimeLimitThreaded.lf b/test/C/src/concurrent/TimeLimitThreaded.lf index b59b40547e..b667c6ca4c 100644 --- a/test/C/src/concurrent/TimeLimitThreaded.lf +++ b/test/C/src/concurrent/TimeLimitThreaded.lf @@ -31,15 +31,15 @@ reactor Destination { =} reaction(shutdown) {= printf("**** shutdown reaction invoked.\n"); - if (self->s != 10002) { - fprintf(stderr, "ERROR: Expected 1000002 but got %d.\n", self->s); + if (self->s != 10000002) { + fprintf(stderr, "ERROR: Expected 10000002 but got %d.\n", self->s); exit(1); } info_print("Approx. time per reaction: %lldns", get_elapsed_physical_time()/(self->s+1)); =} } main reactor (period:time(1 usec)) { - timer stop(10 msecs); + timer stop(10 secs); reaction(stop) {= request_stop(); =} From 98a42e7455d31815b01f22ca043882705ded83db Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 8 Dec 2021 23:14:09 -0600 Subject: [PATCH 041/121] Added option to pass on scheduler to lfc --- org.lflang.lfc/src/org/lflang/lfc/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang.lfc/src/org/lflang/lfc/Main.java b/org.lflang.lfc/src/org/lflang/lfc/Main.java index c408d81b29..705aadef8f 100644 --- a/org.lflang.lfc/src/org/lflang/lfc/Main.java +++ b/org.lflang.lfc/src/org/lflang/lfc/Main.java @@ -108,6 +108,7 @@ enum CLIOption { NO_COMPILE("n", "no-compile", false, false, "Do not invoke target compiler.", true), FEDERATED("f", "federated", false, false, "Treat main reactor as federated.", false), THREADS("t", "threads", true, false, "Specify the default number of threads.", true), + SCHEDULER("s", "scheduler", true, false, "Specify the runtime scheduler (if supported).", true), OUTPUT_PATH("o", "output-path", true, false, "Specify the root output directory.", false), RUNTIME_VERSION(null, "runtime-version", true, false, "Specify the version of the runtime library used for compiling LF programs.", true), EXTERNAL_RUNTIME_PATH(null, "external-runtime-path", true, false, "Specify an external runtime library to be used by the compiled binary.", true); From 3b784b89aa834e28b1c1cc284279c7d3d6f595e9 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 8 Dec 2021 23:25:32 -0600 Subject: [PATCH 042/121] Added LOG_LEVEL as a compile definition for the CMake build system so that the schedulers can follow the appropriate log level. --- org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 54a6daa0bc..f72a4b155a 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -98,7 +98,10 @@ StringBuilder generateCMakeCode( cMakeCode.append("set(CMAKE_CXX_STANDARD_REQUIRED ON)\n"); cMakeCode.append("\n"); - // Follow the + // Set the log level + cMakeCode.append("add_compile_definitions(LOG_LEVEL="+targetConfig.logLevel+")\n"); + + // Set the build type cMakeCode.append("set(DEFAULT_BUILD_TYPE " + targetConfig.cmakeBuildType + ")\n"); cMakeCode.append("if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)\n"); cMakeCode.append(" set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING \"Choose the type of build.\" FORCE)\n"); From 6b4c35890eaa0581f726f075ba3222041fbc5d81 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 9 Dec 2021 00:39:01 -0600 Subject: [PATCH 043/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 7c0d499888..c3ec593deb 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 7c0d499888261b944b7f67f0dd662359e198517f +Subproject commit c3ec593deb9a4c45c39f5c4aaae88006d280c81c From 4ec48ab50c4f0682792a64d989170fc3012f3df5 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 9 Dec 2021 00:40:45 -0600 Subject: [PATCH 044/121] Fixed a bug with the log level --- org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index f72a4b155a..0ebd631c75 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -99,7 +99,7 @@ StringBuilder generateCMakeCode( cMakeCode.append("\n"); // Set the log level - cMakeCode.append("add_compile_definitions(LOG_LEVEL="+targetConfig.logLevel+")\n"); + cMakeCode.append("add_compile_definitions(LOG_LEVEL="+targetConfig.logLevel.ordinal()+")\n"); // Set the build type cMakeCode.append("set(DEFAULT_BUILD_TYPE " + targetConfig.cmakeBuildType + ")\n"); From cde0b9828aa69a873413639b8aaee15d4377c909 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 9 Dec 2021 00:41:40 -0600 Subject: [PATCH 045/121] Updated test --- test/C/src/concurrent/StopThreaded.lf | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/test/C/src/concurrent/StopThreaded.lf b/test/C/src/concurrent/StopThreaded.lf index f73a67e9aa..8a8f8ca911 100644 --- a/test/C/src/concurrent/StopThreaded.lf +++ b/test/C/src/concurrent/StopThreaded.lf @@ -6,7 +6,9 @@ */ target C { timeout: 11 msec, - threads: 4 + threads: 4, + build-type: RelWithDebInfo, + // logging: DEBUG }; import Sender from "../lib/LoopedActionSender.lf" @@ -18,13 +20,15 @@ reactor Consumer { tag_t current_tag = get_current_tag(); if (compare_tags(current_tag, (tag_t) { .time = MSEC(10) + get_start_time(), .microstep = 9}) > 0) { - // The reaction should not have been called at tags larger than (10 msec, 9) - fprintf(stderr, "ERROR: Invoked reaction(in) at tag bigger than shutdown.\n"); - exit(1); + // The reaction should not have been called at tags larger than (10 + // msec, 9) + char time[255]; + error_print_and_exit("Invoked reaction(in) at tag (%llu, %d) which is bigger than shutdown.", + current_tag.time - get_start_time(), current_tag.microstep); } else if (compare_tags(current_tag, (tag_t) { .time = MSEC(10) + get_start_time(), .microstep = 8}) == 0) { // Call request_stop() at relative tag (10 msec, 8) - printf("Requesting stop.\n"); + info_print("Requesting stop."); request_stop(); } else if (compare_tags(current_tag, (tag_t) { .time = MSEC(10) + get_start_time(), .microstep = 9}) == 0) { @@ -36,22 +40,20 @@ reactor Consumer { reaction(shutdown) {= tag_t current_tag = get_current_tag(); - printf("Shutdown invoked at tag (%lld, %u).\n", current_tag.time - get_start_time(), current_tag.microstep); + info_print("Shutdown invoked at tag (%lld, %u).", current_tag.time - get_start_time(), current_tag.microstep); // Check to see if shutdown is called at relative tag (10 msec, 9) if (compare_tags(current_tag, (tag_t) { .time = MSEC(10) + get_start_time(), .microstep = 9}) == 0 && self->reaction_invoked_correctly == true) { - printf("SUCCESS: successfully enforced stop.\n"); + info_print("SUCCESS: successfully enforced stop."); } else if(compare_tags(current_tag, (tag_t) { .time = MSEC(10) + get_start_time(), .microstep = 9}) > 0) { - fprintf(stderr,"ERROR: Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.\n", + error_print_and_exit("Shutdown invoked at tag (%llu, %d). Failed to enforce timeout.", current_tag.time - get_start_time(), current_tag.microstep); - exit(1); } else if (self->reaction_invoked_correctly == false) { // Check to see if reactions were called correctly - fprintf(stderr,"ERROR: Failed to invoke reaction(in) at tag (%llu, %d).\n", + error_print_and_exit("Failed to invoke reaction(in) at tag (%llu, %d).", current_tag.time - get_start_time(), current_tag.microstep); - exit(1); } =} } From 16e8cb4429b3fbcec4f2a4db8621d9432478988f Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 8 Dec 2021 23:14:15 -0800 Subject: [PATCH 046/121] Cog scheduler in benchmarks. --- benchmark/C/Savina/src/concurrency/BoundedBuffer.lf | 1 + benchmark/C/Savina/src/concurrency/CigaretteSmoker.lf | 1 + benchmark/C/Savina/src/concurrency/Dictionary.lf | 1 + benchmark/C/Savina/src/concurrency/LogisticMap.lf | 1 + benchmark/C/Savina/src/concurrency/Philosophers.lf | 1 + benchmark/C/Savina/src/concurrency/ProdCons.lf | 1 + benchmark/C/Savina/src/concurrency/SleepingBarber.lf | 1 + benchmark/C/Savina/src/concurrency/SortedLinkList.lf | 1 + benchmark/C/Savina/src/micro/Big.lf | 1 + benchmark/C/Savina/src/micro/Chameneos.lf | 1 + benchmark/C/Savina/src/micro/Counting.lf | 1 + benchmark/C/Savina/src/micro/PingPong.lf | 1 + benchmark/C/Savina/src/micro/ThreadRing.lf | 1 + benchmark/C/Savina/src/micro/Throughput.lf | 1 + benchmark/C/Savina/src/parallelism/Apsp.lf | 1 + benchmark/C/Savina/src/parallelism/FilterBank.lf | 1 + benchmark/C/Savina/src/parallelism/GuidedSearch.lf | 1 + benchmark/C/Savina/src/parallelism/MatMul.lf | 1 + benchmark/C/Savina/src/parallelism/MatMulBenchmarkRunner.lf | 1 + benchmark/C/Savina/src/parallelism/NQueens.lf | 1 + benchmark/C/Savina/src/parallelism/PiPrecision.lf | 1 + benchmark/C/Savina/src/parallelism/RadixSort.lf | 1 + benchmark/C/Savina/src/parallelism/Trapezoidal.lf | 1 + benchmark/runner/conf/default.yaml | 1 + benchmark/runner/conf/target/lf-c.yaml | 1 + 25 files changed, 25 insertions(+) diff --git a/benchmark/C/Savina/src/concurrency/BoundedBuffer.lf b/benchmark/C/Savina/src/concurrency/BoundedBuffer.lf index a10da7ef74..e55e6718a2 100644 --- a/benchmark/C/Savina/src/concurrency/BoundedBuffer.lf +++ b/benchmark/C/Savina/src/concurrency/BoundedBuffer.lf @@ -24,6 +24,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/concurrency/CigaretteSmoker.lf b/benchmark/C/Savina/src/concurrency/CigaretteSmoker.lf index 93e6f69d09..cb2dce4f32 100644 --- a/benchmark/C/Savina/src/concurrency/CigaretteSmoker.lf +++ b/benchmark/C/Savina/src/concurrency/CigaretteSmoker.lf @@ -63,6 +63,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/concurrency/Dictionary.lf b/benchmark/C/Savina/src/concurrency/Dictionary.lf index b1ce03fa54..fb9521e99d 100644 --- a/benchmark/C/Savina/src/concurrency/Dictionary.lf +++ b/benchmark/C/Savina/src/concurrency/Dictionary.lf @@ -28,6 +28,7 @@ target CCpp { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/concurrency/LogisticMap.lf b/benchmark/C/Savina/src/concurrency/LogisticMap.lf index 7577e18de4..ee5c217656 100644 --- a/benchmark/C/Savina/src/concurrency/LogisticMap.lf +++ b/benchmark/C/Savina/src/concurrency/LogisticMap.lf @@ -12,6 +12,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/concurrency/Philosophers.lf b/benchmark/C/Savina/src/concurrency/Philosophers.lf index 814c6ae293..5f52f63afb 100644 --- a/benchmark/C/Savina/src/concurrency/Philosophers.lf +++ b/benchmark/C/Savina/src/concurrency/Philosophers.lf @@ -11,6 +11,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/concurrency/ProdCons.lf b/benchmark/C/Savina/src/concurrency/ProdCons.lf index 53e9f54bdb..50ec854682 100644 --- a/benchmark/C/Savina/src/concurrency/ProdCons.lf +++ b/benchmark/C/Savina/src/concurrency/ProdCons.lf @@ -10,6 +10,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/concurrency/SleepingBarber.lf b/benchmark/C/Savina/src/concurrency/SleepingBarber.lf index 2aa6752c5b..e469a40003 100644 --- a/benchmark/C/Savina/src/concurrency/SleepingBarber.lf +++ b/benchmark/C/Savina/src/concurrency/SleepingBarber.lf @@ -46,6 +46,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/concurrency/SortedLinkList.lf b/benchmark/C/Savina/src/concurrency/SortedLinkList.lf index c902a1648a..7415dcc464 100644 --- a/benchmark/C/Savina/src/concurrency/SortedLinkList.lf +++ b/benchmark/C/Savina/src/concurrency/SortedLinkList.lf @@ -18,6 +18,7 @@ target CCpp { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/micro/Big.lf b/benchmark/C/Savina/src/micro/Big.lf index 61150f93da..0437dbcdc9 100644 --- a/benchmark/C/Savina/src/micro/Big.lf +++ b/benchmark/C/Savina/src/micro/Big.lf @@ -29,6 +29,7 @@ target C{ /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/micro/Chameneos.lf b/benchmark/C/Savina/src/micro/Chameneos.lf index 0565e97413..a5deb0dd6d 100644 --- a/benchmark/C/Savina/src/micro/Chameneos.lf +++ b/benchmark/C/Savina/src/micro/Chameneos.lf @@ -41,6 +41,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/micro/Counting.lf b/benchmark/C/Savina/src/micro/Counting.lf index 123fbe4f30..54f31bc466 100644 --- a/benchmark/C/Savina/src/micro/Counting.lf +++ b/benchmark/C/Savina/src/micro/Counting.lf @@ -42,6 +42,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/micro/PingPong.lf b/benchmark/C/Savina/src/micro/PingPong.lf index a8df1a48d7..ada69aaf39 100644 --- a/benchmark/C/Savina/src/micro/PingPong.lf +++ b/benchmark/C/Savina/src/micro/PingPong.lf @@ -26,6 +26,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/micro/ThreadRing.lf b/benchmark/C/Savina/src/micro/ThreadRing.lf index 218d7627cf..bffa444897 100644 --- a/benchmark/C/Savina/src/micro/ThreadRing.lf +++ b/benchmark/C/Savina/src/micro/ThreadRing.lf @@ -55,6 +55,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/micro/Throughput.lf b/benchmark/C/Savina/src/micro/Throughput.lf index 2221d46b5a..b12dfa5c37 100644 --- a/benchmark/C/Savina/src/micro/Throughput.lf +++ b/benchmark/C/Savina/src/micro/Throughput.lf @@ -56,6 +56,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/Apsp.lf b/benchmark/C/Savina/src/parallelism/Apsp.lf index efbf2491b8..6301251fb5 100644 --- a/benchmark/C/Savina/src/parallelism/Apsp.lf +++ b/benchmark/C/Savina/src/parallelism/Apsp.lf @@ -21,6 +21,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/FilterBank.lf b/benchmark/C/Savina/src/parallelism/FilterBank.lf index 027ba9200c..65f0aa7f0c 100644 --- a/benchmark/C/Savina/src/parallelism/FilterBank.lf +++ b/benchmark/C/Savina/src/parallelism/FilterBank.lf @@ -33,6 +33,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/GuidedSearch.lf b/benchmark/C/Savina/src/parallelism/GuidedSearch.lf index 5d3941a416..2e109104c2 100644 --- a/benchmark/C/Savina/src/parallelism/GuidedSearch.lf +++ b/benchmark/C/Savina/src/parallelism/GuidedSearch.lf @@ -62,6 +62,7 @@ target CCpp { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/MatMul.lf b/benchmark/C/Savina/src/parallelism/MatMul.lf index 44c49e708d..10f62d667b 100644 --- a/benchmark/C/Savina/src/parallelism/MatMul.lf +++ b/benchmark/C/Savina/src/parallelism/MatMul.lf @@ -10,6 +10,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/MatMulBenchmarkRunner.lf b/benchmark/C/Savina/src/parallelism/MatMulBenchmarkRunner.lf index 9903aec4f9..c67550272d 100644 --- a/benchmark/C/Savina/src/parallelism/MatMulBenchmarkRunner.lf +++ b/benchmark/C/Savina/src/parallelism/MatMulBenchmarkRunner.lf @@ -10,6 +10,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/NQueens.lf b/benchmark/C/Savina/src/parallelism/NQueens.lf index 339c8383bb..fc5e7b5352 100644 --- a/benchmark/C/Savina/src/parallelism/NQueens.lf +++ b/benchmark/C/Savina/src/parallelism/NQueens.lf @@ -41,6 +41,7 @@ target C{ /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/PiPrecision.lf b/benchmark/C/Savina/src/parallelism/PiPrecision.lf index 9191f82b1b..b78ad428a1 100644 --- a/benchmark/C/Savina/src/parallelism/PiPrecision.lf +++ b/benchmark/C/Savina/src/parallelism/PiPrecision.lf @@ -17,6 +17,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/RadixSort.lf b/benchmark/C/Savina/src/parallelism/RadixSort.lf index 4f1d840a27..bcbccd4d06 100644 --- a/benchmark/C/Savina/src/parallelism/RadixSort.lf +++ b/benchmark/C/Savina/src/parallelism/RadixSort.lf @@ -15,6 +15,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/C/Savina/src/parallelism/Trapezoidal.lf b/benchmark/C/Savina/src/parallelism/Trapezoidal.lf index c0c5980c0d..3a4ee0e216 100644 --- a/benchmark/C/Savina/src/parallelism/Trapezoidal.lf +++ b/benchmark/C/Savina/src/parallelism/Trapezoidal.lf @@ -17,6 +17,7 @@ target C { /* [[[cog if (threaded_runtime=="True"): cog.outl(f"threads: {threads},") + cog.outl(f"scheduler: {scheduler},") else: cog.outl("threads: 0,") ]]] */ diff --git a/benchmark/runner/conf/default.yaml b/benchmark/runner/conf/default.yaml index e05cc70293..371e413975 100644 --- a/benchmark/runner/conf/default.yaml +++ b/benchmark/runner/conf/default.yaml @@ -1,5 +1,6 @@ iterations: 12 threads: null +scheduler: GEDF_NP savina_path: "${oc.env:SAVINA_PATH}" lf_path: "${oc.env:LF_PATH}" continue_on_error: False diff --git a/benchmark/runner/conf/target/lf-c.yaml b/benchmark/runner/conf/target/lf-c.yaml index d2156e33ea..b023edd9d0 100644 --- a/benchmark/runner/conf/target/lf-c.yaml +++ b/benchmark/runner/conf/target/lf-c.yaml @@ -3,6 +3,7 @@ prepare: ["mkdir", "src"] copy: ["cp", "-r", "${benchmark.targets.lf-c.copy_sources}", "src"] gen: ["cog", "-r", "${args:benchmark.targets.lf-c.gen_args}", "-D", "threads=${threads}", + "-D", "scheduler=${scheduler}", "-D", "threaded_runtime=True", "src/${benchmark.targets.lf-c.lf_file}"] compile: ["${lf_path}/bin/lfc", "src/${benchmark.targets.lf-c.lf_file}"] From 83ad100abc8bb651d7fdd19bc60e3e3b8f360f39 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Thu, 16 Dec 2021 11:16:28 -0600 Subject: [PATCH 047/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c3ec593deb..873d8afa4b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c3ec593deb9a4c45c39f5c4aaae88006d280c81c +Subproject commit 873d8afa4b42712b1007e8208f4ae5224a162702 From 1bf6679d5f4a6ae5961588dde1eb6fbc555bd728 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Fri, 17 Dec 2021 20:29:44 -0600 Subject: [PATCH 048/121] Added MAX_REACTION_LEVEL and compile definitions --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/TargetConfig.java | 5 +++ org.lflang/src/org/lflang/TargetProperty.java | 6 ++- .../org/lflang/generator/ReactorInstance.java | 17 +++++++- .../lflang/generator/c/CCmakeGenerator.java | 9 +++- .../src/org/lflang/generator/c/CCompiler.java | 6 ++- .../org/lflang/generator/c/CGenerator.xtend | 41 ++++--------------- 7 files changed, 47 insertions(+), 39 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 873d8afa4b..fe4e204f9a 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 873d8afa4b42712b1007e8208f4ae5224a162702 +Subproject commit fe4e204f9af376200949bb13788204b88fd11707 diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 0a9697066e..52f0f0ca23 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -101,6 +101,11 @@ public class TargetConfig { * Additional sources to add to the compile command if appropriate. */ public List compileAdditionalSources = new ArrayList<>(); + + /** + * Additional (preprocessor) definitions to add to the compile command if appropriate. + */ + public List compileDefinitions = new ArrayList<>(); /** * Additional libraries to add to the compile command using the "-l" command-line option. diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index b60b438a8d..659e1cb42f 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -1282,8 +1282,10 @@ public String toString() { * @author{Soroush Bateni } */ public enum SchedulerOptions { - GEDF_NP, // Global EDF non-preemptive - PEDF_NP; // Partitioned EDF non-preemptive + NP, // Non-preemptive + GEDF_NP, // Global EDF non-preemptive + GEDF_NP_CI, // Global EDF non-preemptive with chain ID + PEDF_NP; // Partitioned EDF non-preemptive public static SchedulerOptions getDefault() { return GEDF_NP; diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index ad6eb854e6..fab87e0aa4 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -178,6 +178,9 @@ public boolean assignLevels() { if (candidateLevel > 0 && candidateLevel > downstream.level) { // Can assign a level to downstream. downstream.level = candidateLevel; + if (candidateLevel > maxReactionLevel) { + maxReactionLevel = candidateLevel; + } reactionsWithLevels.add(downstream); } } @@ -289,7 +292,14 @@ public PortInstance getInput(String name) { } return null; } - + + /** + * Return the maximum reaction level in this reactor instance. + */ + public long getMaxReactionLevel() { + return maxReactionLevel; + } + /** * Override the base class to append [index] if this reactor * is in a bank of reactors. @@ -743,6 +753,11 @@ public int width(WidthSpec widthSpec) { * This is 0 for main or federated, 1 for the reactors immediately contained, etc. */ protected int depth = 0; + + /** + * Maximum reaction level of all reactions contained in this reactor instance. + */ + protected long maxReactionLevel = 0; ////////////////////////////////////////////////////// //// Protected methods. diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 0ebd631c75..8c32bdbcad 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -83,6 +83,7 @@ StringBuilder generateCMakeCode( fileConfig.getSrcGenPath().resolve(Paths.get(file))); additionalSources.add(FileConfig.toUnixString(relativePath)); } + cMakeCode.append("\n"); cMakeCode.append("cmake_minimum_required(VERSION 3.13)\n"); cMakeCode.append("project("+executableName+" LANGUAGES C)\n"); @@ -98,14 +99,18 @@ StringBuilder generateCMakeCode( cMakeCode.append("set(CMAKE_CXX_STANDARD_REQUIRED ON)\n"); cMakeCode.append("\n"); - // Set the log level - cMakeCode.append("add_compile_definitions(LOG_LEVEL="+targetConfig.logLevel.ordinal()+")\n"); + cMakeCode.append("# Compile definitions\n"); + for (String definition: targetConfig.compileDefinitions) { + cMakeCode.append("add_compile_definitions("+definition+")\n"); + } + cMakeCode.append("\n"); // Set the build type cMakeCode.append("set(DEFAULT_BUILD_TYPE " + targetConfig.cmakeBuildType + ")\n"); cMakeCode.append("if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)\n"); cMakeCode.append(" set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING \"Choose the type of build.\" FORCE)\n"); cMakeCode.append("endif()\n"); + cMakeCode.append("\n"); cMakeCode.append("set(CoreLib core)\n"); cMakeCode.append("\n"); diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index c37b3ed122..e58c615c45 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -183,8 +183,12 @@ public LFCommand compileCCommand( } compileArgs.addAll(targetConfig.compileLibraries); + // Add compile definitions + for (String definition: targetConfig.compileDefinitions) { + compileArgs.add("-D"+definition); + } + // If threaded computation is requested, add a -pthread option. - if (targetConfig.threads != 0 || targetConfig.tracing != null) { compileArgs.add("-pthread"); // If the LF program itself is threaded or if tracing is enabled, we need to define diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 181c3359e1..c55973d0d2 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -499,6 +499,8 @@ class CGenerator extends GeneratorBase { this.main = new ReactorInstance(mainDef.reactorClass.toDefinition, errorReporter, this.unorderedReactions) this.main.assignLevels(); + // Add the maximum reaction level as a compile-time definition + targetConfig.compileDefinitions.add("MAX_REACTION_LEVEL="+this.main.maxReactionLevel); // Avoid compile errors by removing disconnected network ports. // This must be done after assigning levels. removeRemoteFederateConnectionPorts(main); @@ -3660,25 +3662,10 @@ class CGenerator extends GeneratorBase { * Return a string that defines the log level. */ static def String defineLogLevel(GeneratorBase generator) { - // FIXME: if we align the levels with the ordinals of the - // enum (see CppGenerator), then we don't need this function. - switch(generator.targetConfig.logLevel) { - case ERROR: ''' - #define LOG_LEVEL 0 - ''' - case WARN: ''' - #define LOG_LEVEL 1 - ''' - case INFO: ''' - #define LOG_LEVEL 2 - ''' - case LOG: ''' - #define LOG_LEVEL 3 - ''' - case DEBUG: ''' - #define LOG_LEVEL 4 - ''' - } + generator.targetConfig.compileDefinitions.add("LOG_LEVEL="+generator.targetConfig.logLevel.ordinal); + ''' + #define LOG_LEVEL «generator.targetConfig.logLevel.ordinal» + ''' } /** @@ -5123,23 +5110,13 @@ class CGenerator extends GeneratorBase { pr(this.defineLogLevel) if (isFederated) { - // FIXME: Instead of checking - // #ifdef FEDERATED, we could - // use #if (NUMBER_OF_FEDERATES > 1) - // To me, the former is more accurate. - pr(''' - #define FEDERATED - ''') + targetConfig.compileDefinitions.add("FEDERATED"); if (targetConfig.coordination === CoordinationType.CENTRALIZED) { // The coordination is centralized. - pr(''' - #define FEDERATED_CENTRALIZED - ''') + targetConfig.compileDefinitions.add("FEDERATED_CENTRALIZED"); } else if (targetConfig.coordination === CoordinationType.DECENTRALIZED) { // The coordination is decentralized - pr(''' - #define FEDERATED_DECENTRALIZED - ''') + targetConfig.compileDefinitions.add("FEDERATED_DECENTRALIZED"); } } From 63af3a590f217766c680d12eb7f84d8d8f79b22a Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 18 Dec 2021 23:59:10 -0600 Subject: [PATCH 049/121] Disable testing non-default schedulers for now --- org.lflang.tests/src/org/lflang/tests/runtime/CTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index 5ce0b0b89f..55aee329c2 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -66,7 +66,7 @@ protected boolean supportsDockerOption() { @Override protected boolean supportsSchedulerSwapping() { - return true; + return false; } @Test From 2d17485e294251cebbdfebe12e8da10d4534f1c6 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 18 Dec 2021 23:59:25 -0600 Subject: [PATCH 050/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index fe4e204f9a..b14edfcf12 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit fe4e204f9af376200949bb13788204b88fd11707 +Subproject commit b14edfcf12e9e5960dd38d8e544c44ae826b9b7d From deb246f3ffa4b3fd7d327d1bf8225f6c652c4b95 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 20 Dec 2021 14:33:14 -0600 Subject: [PATCH 051/121] Added a unit test function --- org.lflang.tests/src/org/lflang/tests/runtime/CTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index 55aee329c2..29cf30bf9c 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -106,6 +106,12 @@ public void runWithFourThreads() { super.runWithFourThreads(); } + @Test + @Override + public void runWithNonDefaultSchedulers() { + super.runWithNonDefaultSchedulers(); + } + @Test @Override public void runSerializationTests() { From bdc69834e21972e60b8fbe6cefd691f6995f61ac Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 20 Dec 2021 14:33:33 -0600 Subject: [PATCH 052/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index b14edfcf12..5e58f01492 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit b14edfcf12e9e5960dd38d8e544c44ae826b9b7d +Subproject commit 5e58f014923f0228479866acc34845b1766c1945 From eaf393a29e652dda9d03e53fdb3546bfe6faacc1 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 20 Dec 2021 14:37:01 -0600 Subject: [PATCH 053/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 5e58f01492..b3da423906 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 5e58f014923f0228479866acc34845b1766c1945 +Subproject commit b3da4239060499c1690fbfe3c6aad2e3706647ec From a38fb65ac08e29e7fd9c322e30d84053ee4c0d8f Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 20 Dec 2021 14:55:28 -0600 Subject: [PATCH 054/121] Addressed apparent merge artifact --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 1 + 1 file changed, 1 insertion(+) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index eceb8674d8..069e58cf52 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -953,6 +953,7 @@ class CGenerator extends GeneratorBase { */ def addSchedulerFiles(ArrayList coreFiles) { coreFiles.add("threaded/scheduler.h") + coreFiles.add("threaded/scheduler_sync_tag_advance.c") coreFiles.add("threaded/scheduler_" + targetConfig.schedulerType.toString() + ".c"); targetConfig.compileAdditionalSources.add( "core" + File.separator + "threaded" + File.separator + From 977e3feb795057e4eee83801a4a7fc89dcbbfa7d Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 20 Dec 2021 14:57:34 -0600 Subject: [PATCH 055/121] Removed unnecessary import --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 069e58cf52..21851d6942 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -47,10 +47,9 @@ import org.lflang.ASTUtils import org.lflang.ErrorReporter import org.lflang.FileConfig import org.lflang.InferredType -import org.lflang.TargetConfig -import org.lflang.TargetConfig.Mode import org.lflang.Target import org.lflang.TargetConfig +import org.lflang.TargetConfig.Mode import org.lflang.TargetProperty import org.lflang.TargetProperty.ClockSyncMode import org.lflang.TargetProperty.CoordinationType From a46c9af0ef9f03bf4bc89fce57c655632b58a65a Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 20 Dec 2021 23:32:46 -0600 Subject: [PATCH 056/121] Switched to using NP as the default scheduler. GEDF_NP will be selected if there is a deadline. --- org.lflang/src/org/lflang/TargetProperty.java | 4 +--- .../src/org/lflang/generator/c/CGenerator.xtend | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 6138d98b7d..fdd6ccded5 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -28,14 +28,12 @@ import java.io.IOException; import java.nio.file.Path; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.function.Predicate; import java.util.stream.Collectors; import org.eclipse.xtext.util.RuntimeIOException; - import org.lflang.TargetConfig.DockerOptions; import org.lflang.TargetConfig.TracingOptions; import org.lflang.generator.InvalidLfSourceException; @@ -1288,7 +1286,7 @@ public enum SchedulerOptions { PEDF_NP; // Partitioned EDF non-preemptive public static SchedulerOptions getDefault() { - return GEDF_NP; + return NP; } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 21851d6942..fa77fd8985 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -953,11 +953,26 @@ class CGenerator extends GeneratorBase { def addSchedulerFiles(ArrayList coreFiles) { coreFiles.add("threaded/scheduler.h") coreFiles.add("threaded/scheduler_sync_tag_advance.c") + // Don't use the default non-priority scheduler if the program contains a deadline (handler). + // Use the GEDF_NP scheduler instead. + if (targetConfig.schedulerType == TargetProperty.SchedulerOptions.NP) { + // Check if a deadline is assigned to any reaction + if (reactors.filter[reactor | + // Filter reactors that contain at least one reaction + // that has a deadline handler. + return reactor.allReactions.filter[ reaction | + return reaction.deadline !== null + ].size > 0; + ].size > 0) { + targetConfig.schedulerType = TargetProperty.SchedulerOptions.GEDF_NP; + } + } coreFiles.add("threaded/scheduler_" + targetConfig.schedulerType.toString() + ".c"); targetConfig.compileAdditionalSources.add( "core" + File.separator + "threaded" + File.separator + "scheduler_" + targetConfig.schedulerType.toString() + ".c" ); + System.out.println("******** Using the "+targetConfig.schedulerType.toString()+" runtime scheduler."); } /** From 5f81b1890e2b10383573ae6b7a2d23755ee2208f Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 20 Dec 2021 23:32:59 -0600 Subject: [PATCH 057/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index b3da423906..a08b5e765b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit b3da4239060499c1690fbfe3c6aad2e3706647ec +Subproject commit a08b5e765b3e2ec91ad46de3e47a08cfefe8cb47 From 3401e227de9247b9b23a3676fb642fbf36ee39b3 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 20 Dec 2021 23:34:37 -0600 Subject: [PATCH 058/121] Turned testing for runtime scheduler swapping back on, minus the PEDF_NP scheduler --- org.lflang.tests/src/org/lflang/tests/runtime/CTest.java | 2 +- org.lflang/src/org/lflang/TargetProperty.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index 29cf30bf9c..81eeddde81 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -66,7 +66,7 @@ protected boolean supportsDockerOption() { @Override protected boolean supportsSchedulerSwapping() { - return false; + return true; } @Test diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index fdd6ccded5..d91af56a13 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -1282,8 +1282,8 @@ public String toString() { public enum SchedulerOptions { NP, // Non-preemptive GEDF_NP, // Global EDF non-preemptive - GEDF_NP_CI, // Global EDF non-preemptive with chain ID - PEDF_NP; // Partitioned EDF non-preemptive + GEDF_NP_CI; // Global EDF non-preemptive with chain ID +// PEDF_NP; // Partitioned EDF non-preemptive (FIXME) public static SchedulerOptions getDefault() { return NP; From 2969e6e5088e9e034da165ac2a5b22edd0c65de0 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 21 Dec 2021 00:02:56 -0600 Subject: [PATCH 059/121] Typo --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index fa77fd8985..feafd71e12 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -953,7 +953,7 @@ class CGenerator extends GeneratorBase { def addSchedulerFiles(ArrayList coreFiles) { coreFiles.add("threaded/scheduler.h") coreFiles.add("threaded/scheduler_sync_tag_advance.c") - // Don't use the default non-priority scheduler if the program contains a deadline (handler). + // Don't use the default non-preemptive scheduler if the program contains a deadline (handler). // Use the GEDF_NP scheduler instead. if (targetConfig.schedulerType == TargetProperty.SchedulerOptions.NP) { // Check if a deadline is assigned to any reaction From 3c2a672f4eeebc61dbff14bca3f039136f39ecd1 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 21 Dec 2021 00:31:41 -0600 Subject: [PATCH 060/121] Minor printing updates --- benchmark/C/Savina/src/concurrency/Philosophers.lf | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmark/C/Savina/src/concurrency/Philosophers.lf b/benchmark/C/Savina/src/concurrency/Philosophers.lf index 5f52f63afb..d1376e34d4 100644 --- a/benchmark/C/Savina/src/concurrency/Philosophers.lf +++ b/benchmark/C/Savina/src/concurrency/Philosophers.lf @@ -171,7 +171,7 @@ reactor Arbitrator(num_philosophers:int(20)) { } if (self->finished_philosophers == self->num_philosophers) { - printf("Arbitrator: All philosophers are sated. Number of denials to philosophers: %d", self->retries); + printf("Arbitrator: All philosophers are sated. Number of denials to philosophers: %d\n", self->retries); request_stop(); } =} diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index feafd71e12..4e0dd48db5 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -599,7 +599,7 @@ class CGenerator extends GeneratorBase { ) ) val compileThreadPool = Executors.newFixedThreadPool(numOfCompileThreads); - System.out.println("******** Using "+numOfCompileThreads+" threads."); + System.out.println("******** Using "+numOfCompileThreads+" threads to compile the program."); for (federate : federates) { startTimeStepIsPresentCount = 0 startTimeStepTokens = 0 From e76957c34b3c86d18b0453786c11c448383e49c7 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 21 Dec 2021 01:01:32 -0600 Subject: [PATCH 061/121] Exclude the examples category --- .../src/org/lflang/tests/AbstractTest.java | 2 +- .../src/org/lflang/tests/Configurators.java | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java index dba6489b1d..6594f22cfc 100644 --- a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java +++ b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java @@ -209,7 +209,7 @@ public void runWithNonDefaultSchedulers() { this.runTestsForTargets( Message.DESC_SCHED_SWAPPING + scheduler.toString() +".", - Configurators::noneExcluded, + Configurators::examplesExcluded, test -> { test.getContext() .getArgs() diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index b1847cfe82..0189fbba71 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -97,9 +97,14 @@ public static boolean isExcluded(TestCategory category) { } /** - * Report all test categories as included. + * Report all test categories as included except examples. */ - public static boolean noneExcluded(TestCategory category) { - return true; + public static boolean examplesExcluded(TestCategory category) { + boolean excluded = false; + + // EXAMPLE is excluded + excluded |= (category == TestCategory.EXAMPLE); + + return !excluded; } } From 473b18fb6207082e11220feada747a008b2ab7f5 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 9 Jan 2022 13:02:26 -0600 Subject: [PATCH 062/121] Fixed issues with docker support --- .../src/org/lflang/federated/PythonGeneratorExtension.java | 1 - org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/federated/PythonGeneratorExtension.java b/org.lflang/src/org/lflang/federated/PythonGeneratorExtension.java index 01a0461d44..c5455fc4de 100644 --- a/org.lflang/src/org/lflang/federated/PythonGeneratorExtension.java +++ b/org.lflang/src/org/lflang/federated/PythonGeneratorExtension.java @@ -132,7 +132,6 @@ public static String generateNetworkSenderBody( pickler.generateNetworkSerializerCode(variableToSerialize, null) ); result.append("size_t message_length = "+lengthExpression+";\n"); - result.append("info_print(\"Message length is %d\", message_length);\n"); result.append(sendingFunction+"("+commonArgs+", "+pointerExpression+");\n"); break; } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index e273ad990a..e2a74b9673 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -931,7 +931,7 @@ class CGenerator extends GeneratorBase { if (targetConfig.dockerOptions !== null) { if (isFederated) { - appendRtiToDockerComposeServices(dockerComposeServices, rtiName, "rti:rti", federates.size); + appendRtiToDockerComposeServices(dockerComposeServices, rtiName, "lflang/rti:rti", federates.size); } writeFederatesDockerComposeFile(fileConfig.getSrcGenPath().toFile(), dockerComposeServices, dockerComposeNetworkName); } From 062009bee0dc488fc0af90bb43db3d69fac80ec1 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 9 Jan 2022 20:13:42 -0600 Subject: [PATCH 063/121] Updated compile definitions --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/lib/py/reactor-c-py | 2 +- org.lflang/src/org/lflang/TargetConfig.java | 4 +++- .../lflang/generator/c/CCmakeGenerator.java | 6 +++--- .../src/org/lflang/generator/c/CCompiler.java | 6 +++--- .../org/lflang/generator/c/CGenerator.xtend | 10 +++++----- .../generator/python/PythonGenerator.xtend | 19 ++++++++++++++----- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 6f9bdd3f15..fd1e51150b 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 6f9bdd3f157915e4f53e3bdcd545635b6f36a18e +Subproject commit fd1e51150b89045dc4537a7432a7db2f6a15720a diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 609ebc7322..f43e5b5bd7 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 609ebc7322e338e439c5d5d394ff3aa11fd26c8f +Subproject commit f43e5b5bd7c25d323ec1faeeb4e04f6a6d4bff3a diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 5d2f657536..4f3d6c46bd 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -25,8 +25,10 @@ package org.lflang; import java.util.ArrayList; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import org.lflang.TargetProperty.BuildType; @@ -105,7 +107,7 @@ public class TargetConfig { /** * Additional (preprocessor) definitions to add to the compile command if appropriate. */ - public List compileDefinitions = new ArrayList<>(); + public Map compileDefinitions = new HashMap<>(); /** * Additional libraries to add to the compile command using the "-l" command-line option. diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 73fd41641d..fed587c1ac 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -100,9 +100,9 @@ StringBuilder generateCMakeCode( cMakeCode.append("\n"); cMakeCode.append("# Compile definitions\n"); - for (String definition: targetConfig.compileDefinitions) { - cMakeCode.append("add_compile_definitions("+definition+")\n"); - } + targetConfig.compileDefinitions.forEach( (key, value) -> { + cMakeCode.append("add_compile_definitions("+key+"="+value+")\n"); + }); cMakeCode.append("\n"); // Set the build type diff --git a/org.lflang/src/org/lflang/generator/c/CCompiler.java b/org.lflang/src/org/lflang/generator/c/CCompiler.java index 60ed886aeb..c48031152a 100644 --- a/org.lflang/src/org/lflang/generator/c/CCompiler.java +++ b/org.lflang/src/org/lflang/generator/c/CCompiler.java @@ -188,9 +188,9 @@ public LFCommand compileCCommand( compileArgs.addAll(targetConfig.compileLibraries); // Add compile definitions - for (String definition: targetConfig.compileDefinitions) { - compileArgs.add("-D"+definition); - } + targetConfig.compileDefinitions.forEach( (key,value) -> { + compileArgs.add("-D"+key+"="+value); + }); // If threaded computation is requested, add a -pthread option. if (targetConfig.threads != 0 || targetConfig.tracing != null) { diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index e2a74b9673..c44bb95256 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -507,7 +507,7 @@ class CGenerator extends GeneratorBase { this.unorderedReactions) this.main.assignLevels(); // Add the maximum reaction level as a compile-time definition - targetConfig.compileDefinitions.add("MAX_REACTION_LEVEL="+this.main.maxReactionLevel); + targetConfig.compileDefinitions.put("MAX_REACTION_LEVEL", this.main.maxReactionLevel.toString); // Avoid compile errors by removing disconnected network ports. // This must be done after assigning levels. removeRemoteFederateConnectionPorts(main); @@ -3640,7 +3640,7 @@ class CGenerator extends GeneratorBase { * Return a string that defines the log level. */ static def String defineLogLevel(GeneratorBase generator) { - generator.targetConfig.compileDefinitions.add("LOG_LEVEL="+generator.targetConfig.logLevel.ordinal); + generator.targetConfig.compileDefinitions.put("LOG_LEVEL" , generator.targetConfig.logLevel.ordinal.toString); ''' #define LOG_LEVEL «generator.targetConfig.logLevel.ordinal» ''' @@ -5088,13 +5088,13 @@ class CGenerator extends GeneratorBase { pr(this.defineLogLevel) if (isFederated) { - targetConfig.compileDefinitions.add("FEDERATED"); + targetConfig.compileDefinitions.put("FEDERATED", ""); if (targetConfig.coordination === CoordinationType.CENTRALIZED) { // The coordination is centralized. - targetConfig.compileDefinitions.add("FEDERATED_CENTRALIZED"); + targetConfig.compileDefinitions.put("FEDERATED_CENTRALIZED", ""); } else if (targetConfig.coordination === CoordinationType.DECENTRALIZED) { // The coordination is decentralized - targetConfig.compileDefinitions.add("FEDERATED_DECENTRALIZED"); + targetConfig.compileDefinitions.put("FEDERATED_DECENTRALIZED", ""); } } diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index c2b18f12a4..a148f8ba84 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -27,7 +27,6 @@ THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package org.lflang.generator.python import java.io.File -import java.nio.file.Paths import java.util.ArrayList import java.util.LinkedHashSet import java.util.List @@ -50,11 +49,11 @@ import org.lflang.federated.serialization.SupportedSerializers import org.lflang.generator.GeneratorResult import org.lflang.generator.IntegratedBuilder import org.lflang.generator.JavaGeneratorUtils -import org.lflang.generator.ParameterInstance import org.lflang.generator.LFGeneratorContext -import org.lflang.generator.SubContext +import org.lflang.generator.ParameterInstance import org.lflang.generator.ReactionInstance import org.lflang.generator.ReactorInstance +import org.lflang.generator.SubContext import org.lflang.generator.c.CCompiler import org.lflang.generator.c.CGenerator import org.lflang.lf.Action @@ -72,7 +71,6 @@ import org.lflang.lf.StateVar import org.lflang.lf.TriggerRef import org.lflang.lf.Value import org.lflang.lf.VarRef -import org.lflang.util.LFCommand import static extension org.lflang.ASTUtils.* import static extension org.lflang.JavaAstUtils.* @@ -788,7 +786,7 @@ class PythonGenerator extends CGenerator { linguafranca«topLevelName»module = Extension("LinguaFranca«topLevelName»", sources = ["«topLevelName».c", «FOR src : targetConfig.compileAdditionalSources SEPARATOR ", "» "«FileConfig.toUnixString(src)»"«ENDFOR»], define_macros=[('MODULE_NAME', 'LinguaFranca«topLevelName»')«IF (targetConfig.threads !== 0 || (targetConfig.tracing !== null))», - ('NUMBER_OF_WORKERS', '«targetConfig.threads»')«ENDIF»]) + ('NUMBER_OF_WORKERS', '«targetConfig.threads»')«ENDIF»,«FOR definition: targetConfig.compileDefinitions.entrySet»('«definition.key»', '«definition.value»'),«ENDFOR»]) setup(name="LinguaFranca«topLevelName»", version="1.0", ext_modules = [linguafranca«topLevelName»module], @@ -864,6 +862,17 @@ class PythonGenerator extends CGenerator { */ override generatePreamble() { + if (isFederated) { + targetConfig.compileDefinitions.put("FEDERATED", ""); + if (targetConfig.coordination === CoordinationType.CENTRALIZED) { + // The coordination is centralized. + targetConfig.compileDefinitions.put("FEDERATED_CENTRALIZED", ""); + } else if (targetConfig.coordination === CoordinationType.DECENTRALIZED) { + // The coordination is decentralized + targetConfig.compileDefinitions.put("FEDERATED_DECENTRALIZED", ""); + } + } + val models = new LinkedHashSet for (r : this.reactors ?: emptyList) { From 78862c0fd71d436781f5cf6905bcba8d5d625e24 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 9 Jan 2022 20:20:30 -0600 Subject: [PATCH 064/121] Updated comments --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/TargetConfig.java | 3 +++ org.lflang/src/org/lflang/TargetProperty.java | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index fd1e51150b..e7d944f313 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit fd1e51150b89045dc4537a7432a7db2f6a15720a +Subproject commit e7d944f31378224dd6ec394ddd5e66f335717037 diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 4f3d6c46bd..4b6a3a936d 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -106,6 +106,9 @@ public class TargetConfig { /** * Additional (preprocessor) definitions to add to the compile command if appropriate. + * + * The first string is the definition itself, and the second string is the value to attribute to that definition, if any. + * The second value could be left empty. */ public Map compileDefinitions = new HashMap<>(); diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 38b4df1e40..e2f4e21ccc 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -1293,7 +1293,7 @@ public enum SchedulerOptions { NP, // Non-preemptive GEDF_NP, // Global EDF non-preemptive GEDF_NP_CI; // Global EDF non-preemptive with chain ID -// PEDF_NP; // Partitioned EDF non-preemptive (FIXME) + // PEDF_NP; // Partitioned EDF non-preemptive (FIXME: To be re-added in a future PR) public static SchedulerOptions getDefault() { return NP; From a1f061fc4cbf6d3111a508e0e89f0201d5e49856 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 9 Jan 2022 20:46:03 -0600 Subject: [PATCH 065/121] Updated the way scheduler tests are performed --- .../src/org/lflang/tests/AbstractTest.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java index 6594f22cfc..fad1ba6468 100644 --- a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java +++ b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java @@ -201,15 +201,31 @@ public void runWithFourThreads() { ); } + /** + * Swap the default runtime scheduler with other supported versions and run all the supported tests. + */ @Test public void runWithNonDefaultSchedulers() { Assumptions.assumeTrue(supportsSchedulerSwapping(), Message.NO_SCHED_SWAPPING_SUPPORT); for (SchedulerOptions scheduler: SchedulerOptions.values()) { if (scheduler == SchedulerOptions.getDefault()) continue; + EnumSet categories = EnumSet.allOf(TestCategory.class); + categories.remove(TestCategory.EXAMPLE); + + if (isWindows() || !supportsFederatedExecution()) { + categories.removeAll(EnumSet.of(TestCategory.FEDERATED, + TestCategory.DOCKER_FEDERATED)); + } + + if (!isLinux() || !supportsDockerOption()) { + categories.removeAll(EnumSet.of(TestCategory.DOCKER, + TestCategory.DOCKER_FEDERATED)); + } + this.runTestsForTargets( Message.DESC_SCHED_SWAPPING + scheduler.toString() +".", - Configurators::examplesExcluded, + categories::contains, test -> { test.getContext() .getArgs() From d7865816bdc73831156998c46d79f9272a0a8f6d Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 9 Jan 2022 21:56:39 -0600 Subject: [PATCH 066/121] Missed renames --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index c44bb95256..c2abf135d5 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -833,7 +833,7 @@ class CGenerator extends GeneratorBase { bool _lf_trigger_shutdown_reactions() { for (int i = 0; i < _lf_shutdown_reactions_size; i++) { if (_lf_shutdown_reactions[i] != NULL) { - _lf_enqueue_reaction(_lf_shutdown_reactions[i], -1); + _lf_trigger_reaction(_lf_shutdown_reactions[i], -1); } } // Return true if there are shutdown reactions. @@ -1008,7 +1008,7 @@ class CGenerator extends GeneratorBase { pr(''' for (int i = 0; i < _lf_startup_reactions_size; i++) { if (_lf_startup_reactions[i] != NULL) { - _lf_enqueue_reaction(_lf_startup_reactions[i], -1); + _lf_trigger_reaction(_lf_startup_reactions[i], -1); } } ''') From af3cd77c465d4bbb316b10a45e97894912f28618 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 9 Jan 2022 22:07:05 -0600 Subject: [PATCH 067/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index e7d944f313..d93e589b28 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit e7d944f31378224dd6ec394ddd5e66f335717037 +Subproject commit d93e589b28f7ce92cfe9f19ebcccdec29104ba58 From 08f8062505520dfab43076c87b662dab2a6ba8e7 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 9 Jan 2022 23:45:49 -0600 Subject: [PATCH 068/121] Added exclusions for serialization tests --- org.lflang.tests/src/org/lflang/tests/AbstractTest.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java index fad1ba6468..3429f5b7aa 100644 --- a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java +++ b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java @@ -213,11 +213,18 @@ public void runWithNonDefaultSchedulers() { EnumSet categories = EnumSet.allOf(TestCategory.class); categories.remove(TestCategory.EXAMPLE); + // Exclude federated tests if not supported if (isWindows() || !supportsFederatedExecution()) { categories.removeAll(EnumSet.of(TestCategory.FEDERATED, TestCategory.DOCKER_FEDERATED)); } + // Exclude serialization tests on Windows + if (isWindows()) { + categories.remove(TestCategory.SERIALIZATION); + } + + // Exclude docker tests if not supported if (!isLinux() || !supportsDockerOption()) { categories.removeAll(EnumSet.of(TestCategory.DOCKER, TestCategory.DOCKER_FEDERATED)); From 206f286379c9c37fe899e8d8a6b4ddebb0f074db Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 01:50:02 -0600 Subject: [PATCH 069/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index d93e589b28..388c5dcb57 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit d93e589b28f7ce92cfe9f19ebcccdec29104ba58 +Subproject commit 388c5dcb579d55611b02dd80c1a012c0f337aa69 From b4613809c147066cd5888871e9ea4b1c425268bb Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 01:54:16 -0600 Subject: [PATCH 070/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 388c5dcb57..113c0f6cb4 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 388c5dcb579d55611b02dd80c1a012c0f337aa69 +Subproject commit 113c0f6cb44d90e0fe4c68d822f3bce6aa0ed890 From 1f5b0d03c666ffbf7ed8a03c93ce939e3477fc6c Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 13:52:00 -0600 Subject: [PATCH 071/121] Minor tweaks to scheduler testings --- .../src/org/lflang/tests/AbstractTest.java | 44 ++++++++++--------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java index 3429f5b7aa..f69f2da2c2 100644 --- a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java +++ b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java @@ -207,29 +207,31 @@ public void runWithFourThreads() { @Test public void runWithNonDefaultSchedulers() { Assumptions.assumeTrue(supportsSchedulerSwapping(), Message.NO_SCHED_SWAPPING_SUPPORT); - for (SchedulerOptions scheduler: SchedulerOptions.values()) { + + EnumSet categories = EnumSet.allOf(TestCategory.class); + categories.remove(TestCategory.EXAMPLE); + + // Exclude federated tests if not supported + if (isWindows() || !supportsFederatedExecution()) { + categories.removeAll(EnumSet.of(TestCategory.FEDERATED, + TestCategory.DOCKER_FEDERATED)); + } + + // Exclude serialization and target-specific tests on Windows + if (isWindows()) { + categories.removeAll(EnumSet.of(TestCategory.SERIALIZATION, + TestCategory.TARGET)); + } + + // Exclude docker tests if not supported + if (!isLinux() || !supportsDockerOption()) { + categories.removeAll(EnumSet.of(TestCategory.DOCKER, + TestCategory.DOCKER_FEDERATED)); + } + + for (SchedulerOptions scheduler: EnumSet.allOf(SchedulerOptions.class)) { if (scheduler == SchedulerOptions.getDefault()) continue; - EnumSet categories = EnumSet.allOf(TestCategory.class); - categories.remove(TestCategory.EXAMPLE); - - // Exclude federated tests if not supported - if (isWindows() || !supportsFederatedExecution()) { - categories.removeAll(EnumSet.of(TestCategory.FEDERATED, - TestCategory.DOCKER_FEDERATED)); - } - - // Exclude serialization tests on Windows - if (isWindows()) { - categories.remove(TestCategory.SERIALIZATION); - } - - // Exclude docker tests if not supported - if (!isLinux() || !supportsDockerOption()) { - categories.removeAll(EnumSet.of(TestCategory.DOCKER, - TestCategory.DOCKER_FEDERATED)); - } - this.runTestsForTargets( Message.DESC_SCHED_SWAPPING + scheduler.toString() +".", categories::contains, From 44f1e1db66e4bd597d11e7969f2b4b7330069001 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 13:52:19 -0600 Subject: [PATCH 072/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 113c0f6cb4..a2c9a8641c 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 113c0f6cb44d90e0fe4c68d822f3bce6aa0ed890 +Subproject commit a2c9a8641cb840eb38cf60bf958e07ad9ffdc63a From ed4319fa829b844ab137533308663add3b084d92 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 18:21:25 -0600 Subject: [PATCH 073/121] Removed unnecessary function --- .../src/org/lflang/tests/Configurators.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index 0189fbba71..872a4341b7 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -95,16 +95,4 @@ public static boolean isExcluded(TestCategory category) { excluded |= (TestBase.isWindows() && (category == TestCategory.SERIALIZATION || category == TestCategory.TARGET)); return !excluded; } - - /** - * Report all test categories as included except examples. - */ - public static boolean examplesExcluded(TestCategory category) { - boolean excluded = false; - - // EXAMPLE is excluded - excluded |= (category == TestCategory.EXAMPLE); - - return !excluded; - } } From 611607c81a39192d2406465cc84aed02e95d799e Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 18:21:44 -0600 Subject: [PATCH 074/121] Updated reactor c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index a2c9a8641c..094c6aeae8 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit a2c9a8641cb840eb38cf60bf958e07ad9ffdc63a +Subproject commit 094c6aeae8e9e539a31822f403e5f9b8bc50166c From 43fc7f4aad0b59cd7c12f5fe985bad92b0e0d264 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 18:33:17 -0600 Subject: [PATCH 075/121] Added explicit return status to Python code --- .../org/lflang/generator/python/PythonMainGenerator.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonMainGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonMainGenerator.java index e0184bf4f9..6a7caf9c5a 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonMainGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonMainGenerator.java @@ -47,7 +47,12 @@ public static String generateCode() { + "# As is customary in Python programs, the main() function\n" + "# should only be executed if the main module is active.\n" + "if __name__==\"__main__\":\n" - + " main(sys.argv)\n" + + " try:\n" + + " main(sys.argv)\n" + + " sys.exit(0)\n" + + " except Exception as ex:\n" + + " print(\"Error: \"+ex)\n" + + " sys.exit(1)\n" ); return code.toString(); } From 68216ebece3ec709c5da271e046f440582ed1a86 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 21:01:24 -0600 Subject: [PATCH 076/121] Revert "Added explicit return status to Python code" This reverts commit 43fc7f4aad0b59cd7c12f5fe985bad92b0e0d264. --- .../org/lflang/generator/python/PythonMainGenerator.java | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonMainGenerator.java b/org.lflang/src/org/lflang/generator/python/PythonMainGenerator.java index 6a7caf9c5a..e0184bf4f9 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonMainGenerator.java +++ b/org.lflang/src/org/lflang/generator/python/PythonMainGenerator.java @@ -47,12 +47,7 @@ public static String generateCode() { + "# As is customary in Python programs, the main() function\n" + "# should only be executed if the main module is active.\n" + "if __name__==\"__main__\":\n" - + " try:\n" - + " main(sys.argv)\n" - + " sys.exit(0)\n" - + " except Exception as ex:\n" - + " print(\"Error: \"+ex)\n" - + " sys.exit(1)\n" + + " main(sys.argv)\n" ); return code.toString(); } From 702ebdb2e152595267f1107b53ba0b4d5f52b484 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 21:13:54 -0600 Subject: [PATCH 077/121] Added wheel as a requirement --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index a148f8ba84..f0b7ed981b 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -74,6 +74,7 @@ import org.lflang.lf.VarRef import static extension org.lflang.ASTUtils.* import static extension org.lflang.JavaAstUtils.* +import java.util.HashSet /** * Generator for Python target. This class generates Python code defining each reactor @@ -93,7 +94,7 @@ class PythonGenerator extends CGenerator { var pythonPreamble = new StringBuilder() // Used to add module requirements to setup.py (delimited with ,) - var pythonRequiredModules = new StringBuilder() + var pythonRequiredModules = new HashSet; new(FileConfig fileConfig, ErrorReporter errorReporter) { super(fileConfig, errorReporter) @@ -790,7 +791,7 @@ class PythonGenerator extends CGenerator { setup(name="LinguaFranca«topLevelName»", version="1.0", ext_modules = [linguafranca«topLevelName»module], - install_requires=['LinguaFrancaBase' «pythonRequiredModules»],) + install_requires=['LinguaFrancaBase', 'wheel', «pythonRequiredModules.join(", ")»],) ''' /** @@ -1001,7 +1002,7 @@ class PythonGenerator extends CGenerator { } val returnCode = protoc.run(cancelIndicator) if (returnCode == 0) { - pythonRequiredModules.append(''', 'google-api-python-client' ''') + pythonRequiredModules.add("google-api-python-client") } else { errorReporter.reportError("protoc returns error code " + returnCode) } From 7c23be14dfeeba45c18a317fe3e170a22e015f26 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 21:16:13 -0600 Subject: [PATCH 078/121] Fixed an issue with protobuff --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index f0b7ed981b..144fa396e3 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -1002,7 +1002,7 @@ class PythonGenerator extends CGenerator { } val returnCode = protoc.run(cancelIndicator) if (returnCode == 0) { - pythonRequiredModules.add("google-api-python-client") + pythonRequiredModules.add(''' 'google-api-python-client' ''') } else { errorReporter.reportError("protoc returns error code " + returnCode) } From 56bc05a34704ac519a29141d99d5180875552493 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 10 Jan 2022 21:54:25 -0600 Subject: [PATCH 079/121] Removed wheel as a requirement --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index 144fa396e3..74ef985096 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -791,7 +791,7 @@ class PythonGenerator extends CGenerator { setup(name="LinguaFranca«topLevelName»", version="1.0", ext_modules = [linguafranca«topLevelName»module], - install_requires=['LinguaFrancaBase', 'wheel', «pythonRequiredModules.join(", ")»],) + install_requires=['LinguaFrancaBase', «pythonRequiredModules.join(", ")»],) ''' /** From dfe1f19f6068ed2a952d39d4a97672a2795ef70f Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 11 Jan 2022 00:38:56 -0600 Subject: [PATCH 080/121] Added exit code and stack trace printouts for failed tests --- org.lflang.tests/src/org/lflang/tests/LFTest.java | 6 +++++- org.lflang.tests/src/org/lflang/tests/TestBase.java | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/LFTest.java b/org.lflang.tests/src/org/lflang/tests/LFTest.java index 0f875036b1..64a6691fca 100644 --- a/org.lflang.tests/src/org/lflang/tests/LFTest.java +++ b/org.lflang.tests/src/org/lflang/tests/LFTest.java @@ -28,6 +28,9 @@ public class LFTest implements Comparable { /** The result of the test. */ public Result result = Result.UNKNOWN; + + /** The exit code of the test. **/ + public String exitValue = "?"; /** Object used to determine where the code generator puts files. */ public FileConfig fileConfig; @@ -128,7 +131,7 @@ public String reportErrors() { sb.append("+---------------------------------------------------------------------------+").append(System.lineSeparator()); sb.append("Failed: ").append(this.name).append(System.lineSeparator()); sb.append("-----------------------------------------------------------------------------").append(System.lineSeparator()); - sb.append("Reason: ").append(this.result.message).append(System.lineSeparator()); + sb.append("Reason: ").append(this.result.message).append(" Exit code: ").append(this.exitValue).append(System.lineSeparator()); appendIfNotEmpty("Reported issues", this.issues.toString(), sb); appendIfNotEmpty("Compilation output", this.compilationLog.toString(), sb); appendIfNotEmpty("Execution output", this.execLog.toString(), sb); @@ -164,6 +167,7 @@ public enum Result { CODE_GEN_FAIL("Error while generating code for test."), NO_EXEC_FAIL("Did not execute test."), TEST_FAIL("Test did not pass."), + TEST_EXCEPTION("Test exited with an exception."), TEST_TIMEOUT("Test timed out."), TEST_PASS("Test passed."); diff --git a/org.lflang.tests/src/org/lflang/tests/TestBase.java b/org.lflang.tests/src/org/lflang/tests/TestBase.java index 99dff11b15..61d211e02d 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestBase.java +++ b/org.lflang.tests/src/org/lflang/tests/TestBase.java @@ -5,6 +5,8 @@ import java.io.IOException; import java.io.PrintStream; +import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.nio.file.Files; @@ -468,12 +470,18 @@ private void execute(LFTest test) { } else { if (p.exitValue() != 0) { test.result = Result.TEST_FAIL; + test.exitValue = Integer.toString(p.exitValue()); return; } } } } catch (Exception e) { - test.result = Result.TEST_FAIL; + test.result = Result.TEST_EXCEPTION; + // Add the stack trace to the test output + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + test.execLog.buffer.append(sw.toString()); return; } test.result = Result.TEST_PASS; From b9439329b8e4ba71cd0689ffcd36ca05a0ece09d Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 11 Jan 2022 01:17:26 -0600 Subject: [PATCH 081/121] Fixed message format --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index 74ef985096..7a9915c7aa 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -1957,7 +1957,7 @@ class PythonGenerator extends CGenerator { ENTRYPOINT ["python3", "src-gen/«topLevelName».py"] ''') JavaGeneratorUtils.writeSourceCodeToFile(contents, dockerFile) - println("Dockerfile for «topLevelName» written to " + dockerFile) + println('''Dockerfile for «topLevelName» written to «dockerFile»''') println(''' ##################################### To build the docker image, use: From 70e0149b70f1a00c15d1bc2530d69658879d013c Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 11 Jan 2022 01:29:34 -0600 Subject: [PATCH 082/121] Revert reactor-c-py to an earlier commit to try to pinpoint the cause of heap corruption --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index f43e5b5bd7..5c7f236a9e 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit f43e5b5bd7c25d323ec1faeeb4e04f6a6d4bff3a +Subproject commit 5c7f236a9e7921ea04d5e09295b53c1f541dd0a3 From 422619d9f3fbb6ef72de35af9fede740dbd7e573 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 11 Jan 2022 01:55:59 -0600 Subject: [PATCH 083/121] Revert reactor-c-py even further --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 5c7f236a9e..609ebc7322 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 5c7f236a9e7921ea04d5e09295b53c1f541dd0a3 +Subproject commit 609ebc7322e338e439c5d5d394ff3aa11fd26c8f From 2dd89ce37946d99cda7808d8df54d9d69665148d Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 11 Jan 2022 02:24:14 -0600 Subject: [PATCH 084/121] Pointing back to the head of reactor-c-py --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 609ebc7322..c69861957b 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 609ebc7322e338e439c5d5d394ff3aa11fd26c8f +Subproject commit c69861957b3f9b3d92dc8970cf22ba7301cd169e From 60e87fe0a7636d331b3c4c2a6c51fb2163583d83 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Tue, 11 Jan 2022 03:29:54 -0600 Subject: [PATCH 085/121] Slightly streamlined test categories --- .../src/org/lflang/tests/AbstractTest.java | 26 ++++++------------- 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java index f69f2da2c2..459973df91 100644 --- a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java +++ b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java @@ -208,25 +208,15 @@ public void runWithFourThreads() { public void runWithNonDefaultSchedulers() { Assumptions.assumeTrue(supportsSchedulerSwapping(), Message.NO_SCHED_SWAPPING_SUPPORT); - EnumSet categories = EnumSet.allOf(TestCategory.class); - categories.remove(TestCategory.EXAMPLE); - - // Exclude federated tests if not supported - if (isWindows() || !supportsFederatedExecution()) { - categories.removeAll(EnumSet.of(TestCategory.FEDERATED, - TestCategory.DOCKER_FEDERATED)); - } - - // Exclude serialization and target-specific tests on Windows - if (isWindows()) { - categories.removeAll(EnumSet.of(TestCategory.SERIALIZATION, - TestCategory.TARGET)); - } + EnumSet categories = EnumSet.of(TestCategory.CONCURRENT, + TestCategory.MULTIPORT); - // Exclude docker tests if not supported - if (!isLinux() || !supportsDockerOption()) { - categories.removeAll(EnumSet.of(TestCategory.DOCKER, - TestCategory.DOCKER_FEDERATED)); + // Add federated and docker tests if supported + if (!isWindows() && supportsFederatedExecution()) { + categories.add(TestCategory.FEDERATED); + if (isLinux() && supportsDockerOption()) { + categories.add(TestCategory.DOCKER_FEDERATED); + } } for (SchedulerOptions scheduler: EnumSet.allOf(SchedulerOptions.class)) { From 90c69c8a590081e02df9da39edf02d810895ce11 Mon Sep 17 00:00:00 2001 From: Peter Donovan Date: Wed, 26 Jan 2022 01:22:06 +0000 Subject: [PATCH 086/121] Benchmarks: Add scheduler parameter. --- benchmark/runner/conf/default.yaml | 4 ++-- benchmark/runner/conf/target/lf-c.yaml | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/benchmark/runner/conf/default.yaml b/benchmark/runner/conf/default.yaml index 371e413975..dbb58a43c6 100644 --- a/benchmark/runner/conf/default.yaml +++ b/benchmark/runner/conf/default.yaml @@ -1,9 +1,9 @@ iterations: 12 threads: null -scheduler: GEDF_NP +timeout: 1200 savina_path: "${oc.env:SAVINA_PATH}" lf_path: "${oc.env:LF_PATH}" -continue_on_error: False +continue_on_error: True test_mode: False defaults: - benchmark: ??? diff --git a/benchmark/runner/conf/target/lf-c.yaml b/benchmark/runner/conf/target/lf-c.yaml index b023edd9d0..6f9dd21e33 100644 --- a/benchmark/runner/conf/target/lf-c.yaml +++ b/benchmark/runner/conf/target/lf-c.yaml @@ -3,10 +3,12 @@ prepare: ["mkdir", "src"] copy: ["cp", "-r", "${benchmark.targets.lf-c.copy_sources}", "src"] gen: ["cog", "-r", "${args:benchmark.targets.lf-c.gen_args}", "-D", "threads=${threads}", - "-D", "scheduler=${scheduler}", + "-D", "scheduler=${target.params.scheduler}", "-D", "threaded_runtime=True", "src/${benchmark.targets.lf-c.lf_file}"] compile: ["${lf_path}/bin/lfc", "src/${benchmark.targets.lf-c.lf_file}"] run: ["bash", "-c", "seq ${iterations} | xargs -I{} bin/${benchmark.targets.lf-c.binary}"] parser: _target_: "parser.parse_lfc_output" +params: + scheduler: "GEDF_NP" From 0e6ea24ea84389618f031a8beeefb45b660ccacb Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 29 Jan 2022 17:30:37 -0600 Subject: [PATCH 087/121] Fixed merge conflict --- .../src/org/lflang/generator/ReactorInstance.java | 7 ------- .../src/org/lflang/generator/c/CCmakeGenerator.java | 2 +- .../src/org/lflang/generator/c/CGenerator.xtend | 11 ++--------- .../org/lflang/generator/python/PythonGenerator.xtend | 1 - 4 files changed, 3 insertions(+), 18 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactorInstance.java b/org.lflang/src/org/lflang/generator/ReactorInstance.java index 8346f6152c..81a1d1c508 100644 --- a/org.lflang/src/org/lflang/generator/ReactorInstance.java +++ b/org.lflang/src/org/lflang/generator/ReactorInstance.java @@ -274,13 +274,6 @@ public PortInstance getInput(String name) { return null; } - /** - * Return the maximum reaction level in this reactor instance. - */ - public long getMaxReactionLevel() { - return maxReactionLevel; - } - /** * Override the base class to append [i_d], where d is the depth, * if this reactor is in a bank of reactors. diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 6bb2261952..05e2f31560 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -84,7 +84,7 @@ CodeBuilder generateCMakeCode( fileConfig.getSrcGenPath().resolve(Paths.get(file))); additionalSources.add(FileConfig.toUnixString(relativePath)); } - cMakeCode.append("\n"); + cMakeCode.pr("\n"); cMakeCode.pr("cmake_minimum_required(VERSION 3.13)"); cMakeCode.pr("project("+executableName+" LANGUAGES C)"); diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 59b1c3093f..965668f886 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -43,10 +43,7 @@ import org.lflang.ASTUtils import org.lflang.ErrorReporter import org.lflang.FileConfig import org.lflang.InferredType -<<<<<<< HEAD -======= import org.lflang.JavaAstUtils ->>>>>>> origin/master import org.lflang.Target import org.lflang.TargetConfig import org.lflang.TargetConfig.Mode @@ -470,16 +467,12 @@ class CGenerator extends GeneratorBase { // it is the same for all federates. this.main = new ReactorInstance(mainDef.reactorClass.toDefinition, errorReporter, this.unorderedReactions) -<<<<<<< HEAD - this.main.assignLevels(); - // Add the maximum reaction level as a compile-time definition - targetConfig.compileDefinitions.put("MAX_REACTION_LEVEL", this.main.maxReactionLevel.toString); -======= if (this.main.assignLevels().nodeCount > 0) { errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); return; } ->>>>>>> origin/master + // Add the maximum reaction level as a compile-time definition + targetConfig.compileDefinitions.put("MAX_REACTION_LEVEL", "0"); // FIXME // Avoid compile errors by removing disconnected network ports. // This must be done after assigning levels. removeRemoteFederateConnectionPorts(main); diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index 1e3beb36f1..4963b2a28d 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -82,7 +82,6 @@ import org.lflang.lf.VarRef import static extension org.lflang.ASTUtils.* import static extension org.lflang.JavaAstUtils.* -import java.util.HashSet /** * Generator for Python target. This class generates Python code defining each reactor From f3fd387c0bf0e4652d6c450c6d79bed4895ac593 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 29 Jan 2022 17:38:45 -0600 Subject: [PATCH 088/121] Added back the scheduler option --- org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java b/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java index 67c67e82bb..25bc3735a7 100644 --- a/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java @@ -94,6 +94,11 @@ public static void setTargetConfig( if (context.getArgs().containsKey("target-compiler")) { targetConfig.compiler = context.getArgs().getProperty("target-compiler"); } + if (context.getArgs().containsKey("scheduler")) { + targetConfig.schedulerType = TargetProperty.SchedulerOptions.valueOf( + context.getArgs().getProperty("scheduler") + ); + } if (context.getArgs().containsKey("target-flags")) { targetConfig.compilerFlags.clear(); if (!context.getArgs().getProperty("target-flags").isEmpty()) { From 824b24a092c25d7b143d2dfa6e41bc352cb97a00 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 29 Jan 2022 18:17:46 -0600 Subject: [PATCH 089/121] Added back MAX_REACTION_LEVEL --- .../org/lflang/generator/GeneratorBase.xtend | 6 +- .../generator/ReactionInstanceGraph.java | 67 ++++++++++++++++++- .../org/lflang/generator/c/CGenerator.xtend | 7 +- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/GeneratorBase.xtend b/org.lflang/src/org/lflang/generator/GeneratorBase.xtend index 883dbb9449..0d410b267d 100644 --- a/org.lflang/src/org/lflang/generator/GeneratorBase.xtend +++ b/org.lflang/src/org/lflang/generator/GeneratorBase.xtend @@ -889,11 +889,13 @@ abstract class GeneratorBase extends AbstractLFValidator { // // Private functions /** - * Remove triggers in each federates' network reactions that are defined in remote federates. + * Remove triggers in each federates' network reactions that are defined + * in remote federates. * * This must be done in code generators after the dependency graphs * are built and levels are assigned. Otherwise, these disconnected ports - * might reference data structures in remote federates and cause compile errors. + * might reference data structures in remote federates and cause + * compile/runtime errors. * * @param instance The reactor instance to remove these ports from if any. * Can be null. diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index fbcfee645e..af076b91c2 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -94,6 +94,14 @@ public void rebuild() { } } + /* + * Get an array of non-zero integers representing the maximum number of reactions + * per each level, where levels are indices of the array. + */ + public Integer[] getMaxNumOfReactionPerLevel() { + return maxNumOfReactionPerLevel.toArray(new Integer[0]); + } + /////////////////////////////////////////////////////////// //// Protected methods @@ -206,6 +214,16 @@ protected void addNodesAndEdges(ReactorInstance reactor) { } } + /////////////////////////////////////////////////////////// + //// Private fields + + /** + * Maximum number of reactions per level, represented as list of + * integers where the indices are the levels. + */ + private List maxNumOfReactionPerLevel = new ArrayList<>( + List.of(Integer.valueOf(0))); + /////////////////////////////////////////////////////////// //// Private methods @@ -224,7 +242,7 @@ private void assignLevels() { // All root nodes start with level 0. for (Runtime origin : start) { - origin.level = 0; + assignLevel(origin, 0); } // No need to do any of this if there are no root nodes; @@ -232,13 +250,18 @@ private void assignLevels() { while (!start.isEmpty()) { Runtime origin = start.remove(0); Set toRemove = new LinkedHashSet(); + Set downstreamAdjacentNodes = getDownstreamAdjacentNodes(origin); + // All downstream adjacent nodes start with a level 0. Adjust the + // maxNumOfReactionPerLevel field accordingly (to be + // updated in the for loop below). + adjustMaxNumOfReactionPerLevel(0, downstreamAdjacentNodes.size()); // Visit effect nodes. - for (Runtime effect : getDownstreamAdjacentNodes(origin)) { + for (Runtime effect : downstreamAdjacentNodes) { // Stage edge between origin and effect for removal. toRemove.add(effect); // Update level of downstream node. - effect.level = Math.max(effect.level, origin.level+1); + updateLevel(effect, origin.level+1); } // Remove visited edges. for (Runtime effect : toRemove) { @@ -254,4 +277,42 @@ private void assignLevels() { removeNode(origin); } } + + /** + * Assign a level to a reaction runtime instance. + * + * @param runtime The reaction runtime instance. + * @param level The level to assign. + */ + private void assignLevel(Runtime runtime, Integer level) { + runtime.level = level; + } + + /** + * Update the level of the reaction runtime instance + * to level if level is larger than the + * level already assigned to runtime. + */ + private void updateLevel(Runtime runtime, Integer level) { + if (runtime.level < level) { + runtime.level = level; + // Adjust the maxNumOfReactionPerLevel field + // accordingly. + adjustMaxNumOfReactionPerLevel(runtime.level, -1); + adjustMaxNumOfReactionPerLevel(level, 1); + } + } + + /** + * Adjust {@link #maxNumOfReactionPerLevel} at index level by + * valueToAdd. + */ + private void adjustMaxNumOfReactionPerLevel(int level, int valueToAdd) { + if (maxNumOfReactionPerLevel.size() > level) { + maxNumOfReactionPerLevel.set(level, maxNumOfReactionPerLevel.get(0) + valueToAdd); + } else { + maxNumOfReactionPerLevel.add(level, valueToAdd); + } + + } } diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 965668f886..a5ecee9bfb 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -472,7 +472,12 @@ class CGenerator extends GeneratorBase { return; } // Add the maximum reaction level as a compile-time definition - targetConfig.compileDefinitions.put("MAX_REACTION_LEVEL", "0"); // FIXME + targetConfig.compileDefinitions.put( + "MAX_REACTION_LEVEL", + String.valueOf( + this.main.assignLevels().maxNumOfReactionPerLevel.size + ) + ); // Avoid compile errors by removing disconnected network ports. // This must be done after assigning levels. removeRemoteFederateConnectionPorts(main); From ed3a2d2a434c903150fc4cd4e0a3fbe64a66b880 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 29 Jan 2022 20:16:15 -0600 Subject: [PATCH 090/121] Made generated CMakeLists.txt a bit prettier --- org.lflang/src/lib/c/reactor-c | 2 +- .../src/org/lflang/generator/CodeBuilder.java | 7 +++ .../generator/ReactionInstanceGraph.java | 2 +- .../lflang/generator/c/CCmakeGenerator.java | 59 +++++++++++-------- 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 04e51f60ce..4ccf218727 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 04e51f60cec94e5f7d3186c2a0a31ba35dd4e6fd +Subproject commit 4ccf218727ae39730a9c5ab1f1772b4038b379cc diff --git a/org.lflang/src/org/lflang/generator/CodeBuilder.java b/org.lflang/src/org/lflang/generator/CodeBuilder.java index f0116b14d5..cbfd710a0e 100644 --- a/org.lflang/src/org/lflang/generator/CodeBuilder.java +++ b/org.lflang/src/org/lflang/generator/CodeBuilder.java @@ -69,6 +69,13 @@ public void insert(int position, String text) { public int length() { return code.length(); } + + /** + * Add a new line. + */ + public void newLine() { + this.pr(""); + } /** * Append the specified text plus a final newline. diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index af076b91c2..b33891257d 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -218,7 +218,7 @@ protected void addNodesAndEdges(ReactorInstance reactor) { //// Private fields /** - * Maximum number of reactions per level, represented as list of + * Maximum number of reactions per level, represented as a list of * integers where the indices are the levels. */ private List maxNumOfReactionPerLevel = new ArrayList<>( diff --git a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java index 05e2f31560..a9effdf5d1 100644 --- a/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java +++ b/org.lflang/src/org/lflang/generator/c/CCmakeGenerator.java @@ -84,77 +84,83 @@ CodeBuilder generateCMakeCode( fileConfig.getSrcGenPath().resolve(Paths.get(file))); additionalSources.add(FileConfig.toUnixString(relativePath)); } - cMakeCode.pr("\n"); + cMakeCode.newLine(); cMakeCode.pr("cmake_minimum_required(VERSION 3.13)"); cMakeCode.pr("project("+executableName+" LANGUAGES C)"); - cMakeCode.pr(""); + cMakeCode.newLine(); cMakeCode.pr("# Require C11"); cMakeCode.pr("set(CMAKE_C_STANDARD 11)"); cMakeCode.pr("set(CMAKE_C_STANDARD_REQUIRED ON)"); - cMakeCode.pr(""); + cMakeCode.newLine(); cMakeCode.pr("# Require C++17"); cMakeCode.pr("set(CMAKE_CXX_STANDARD 17)"); cMakeCode.pr("set(CMAKE_CXX_STANDARD_REQUIRED ON)"); - cMakeCode.pr(""); + cMakeCode.newLine(); cMakeCode.pr("# Compile definitions\n"); targetConfig.compileDefinitions.forEach( (key, value) -> { cMakeCode.pr("add_compile_definitions("+key+"="+value+")\n"); }); - cMakeCode.pr("\n"); + cMakeCode.newLine(); // Set the build type cMakeCode.pr("set(DEFAULT_BUILD_TYPE " + targetConfig.cmakeBuildType + ")\n"); cMakeCode.pr("if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)\n"); cMakeCode.pr(" set(CMAKE_BUILD_TYPE ${DEFAULT_BUILD_TYPE} CACHE STRING \"Choose the type of build.\" FORCE)\n"); cMakeCode.pr("endif()\n"); - cMakeCode.pr("\n"); + cMakeCode.newLine(); cMakeCode.pr("set(CoreLib core)"); cMakeCode.pr("set(PlatformLib platform)"); - cMakeCode.pr(""); + cMakeCode.newLine(); if (CppMode) { // Suppress warnings about const char*. cMakeCode.pr("set(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wno-write-strings\")"); + cMakeCode.newLine(); } cMakeCode.pr("include(${CoreLib}/platform/Platform.cmake)"); + cMakeCode.newLine(); cMakeCode.pr("include_directories(${CoreLib})"); cMakeCode.pr("include_directories(${CoreLib}/platform)"); cMakeCode.pr("include_directories(${CoreLib}/federated)"); + cMakeCode.newLine(); cMakeCode.pr("set(LF_MAIN_TARGET "+executableName+")"); + cMakeCode.newLine(); + if (hasMain) { cMakeCode.pr("# Declare a new executable target and list all its sources"); - cMakeCode.pr( - "add_executable(${LF_MAIN_TARGET} " + String.join("\n", sources) - + " ${CoreLib}/platform/${LF_PLATFORM_FILE} " + String.join("\n", additionalSources) + ")\n" - ); + cMakeCode.pr("add_executable("); } else { cMakeCode.pr("# Declare a new library target and list all its sources"); - cMakeCode.pr( - "add_library(${LF_MAIN_TARGET} " + String.join("\n", sources) - + " ${CoreLib}/platform/${LF_PLATFORM_FILE} " + String.join("\n", additionalSources) + ")\n" - ); + cMakeCode.pr("add_library("); } - cMakeCode.pr(""); + cMakeCode.indent(); + cMakeCode.pr("${LF_MAIN_TARGET}"); + sources.forEach(source -> {cMakeCode.pr(source);}); + cMakeCode.pr("${CoreLib}/platform/${LF_PLATFORM_FILE}"); + additionalSources.forEach(source -> {cMakeCode.pr(source);}); + cMakeCode.unindent(); + cMakeCode.pr(")"); + cMakeCode.newLine(); if (targetConfig.threads != 0 || targetConfig.tracing != null) { // If threaded computation is requested, add a the threads option. cMakeCode.pr("# Find threads and link to it"); cMakeCode.pr("find_package(Threads REQUIRED)"); cMakeCode.pr("target_link_libraries( ${LF_MAIN_TARGET} Threads::Threads)"); - cMakeCode.pr(""); + cMakeCode.newLine(); // If the LF program itself is threaded or if tracing is enabled, we need to define // NUMBER_OF_WORKERS so that platform-specific C files will contain the appropriate functions cMakeCode.pr("# Set the number of workers to enable threading"); cMakeCode.pr("target_compile_definitions( ${LF_MAIN_TARGET} PUBLIC NUMBER_OF_WORKERS="+targetConfig.threads+")"); - cMakeCode.pr(""); + cMakeCode.newLine(); } // Check if CppMode is enabled @@ -171,6 +177,7 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("set_source_files_properties( "+source+" PROPERTIES LANGUAGE CXX)"); } cMakeCode.pr("set_source_files_properties(${CoreLib}/platform/${LF_PLATFORM_FILE} PROPERTIES LANGUAGE CXX)"); + cMakeCode.newLine(); } if (targetConfig.compiler != null && !targetConfig.compiler.isBlank()) { @@ -180,6 +187,7 @@ CodeBuilder generateCMakeCode( } else { cMakeCode.pr("set(CMAKE_C_COMPILER "+targetConfig.compiler+")"); } + cMakeCode.newLine(); } // Set the compiler flags @@ -214,17 +222,22 @@ CodeBuilder generateCMakeCode( cMakeCode.pr("add_link_options( "+compilerFlag+")"); } } - cMakeCode.pr(""); + cMakeCode.newLine(); // Add the install option - cMakeCode.pr("install(TARGETS ${LF_MAIN_TARGET}"); - cMakeCode.pr(" RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})"); - cMakeCode.pr(""); + cMakeCode.pr("install("); + cMakeCode.indent(); + cMakeCode.pr("TARGETS ${LF_MAIN_TARGET}"); + cMakeCode.pr("RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}"); + cMakeCode.unindent(); + cMakeCode.pr(")"); + cMakeCode.newLine(); // Add the include file for (String includeFile : targetConfig.cmakeIncludesWithoutPath) { cMakeCode.pr("include(\""+includeFile+"\")"); - } + } + cMakeCode.newLine(); return cMakeCode; } From 433643b300ef111300cc9f42355a5b3bafa4947c Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 29 Jan 2022 20:58:21 -0600 Subject: [PATCH 091/121] Updated reactor-c-py --- org.lflang/src/lib/py/reactor-c-py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/py/reactor-c-py b/org.lflang/src/lib/py/reactor-c-py index 4e19241ef2..9e78ad3596 160000 --- a/org.lflang/src/lib/py/reactor-c-py +++ b/org.lflang/src/lib/py/reactor-c-py @@ -1 +1 @@ -Subproject commit 4e19241ef26662a006c72e4dcc7543c0d3840179 +Subproject commit 9e78ad35961e559d88abfaf950f76a5f2d4323e7 From 8f375ef26cbdc44828726ca29f18556c288c6b18 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 29 Jan 2022 21:02:03 -0600 Subject: [PATCH 092/121] Fixed merge artifact --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index 4963b2a28d..82fc0fe61c 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -858,13 +858,13 @@ class PythonGenerator extends CGenerator { from setuptools import setup, Extension linguafranca«topLevelName»module = Extension("LinguaFranca«topLevelName»", - sources = ["«topLevelName».c", «FOR src : targetConfig.compileAdditionalSources SEPARATOR ", "» "«src»"«ENDFOR»], - define_macros=[('MODULE_NAME', 'LinguaFranca«topLevelName»')«IF (targetConfig.threads !== 0 || (targetConfig.tracing !== null))», - ('NUMBER_OF_WORKERS', '«targetConfig.threads»')«ENDIF»]) + sources = ["«topLevelName».c", «FOR src : targetConfig.compileAdditionalSources SEPARATOR ", "» "«FileConfig.toUnixString(src)»"«ENDFOR»], + define_macros=[('MODULE_NAME', 'LinguaFranca«topLevelName»')«IF (targetConfig.threads !== 0 || (targetConfig.tracing !== null))», + ('NUMBER_OF_WORKERS', '«targetConfig.threads»')«ENDIF»,«FOR definition: targetConfig.compileDefinitions.entrySet»('«definition.key»', '«definition.value»'),«ENDFOR»]) setup(name="LinguaFranca«topLevelName»", version="1.0", ext_modules = [linguafranca«topLevelName»module], - install_requires=['LinguaFrancaBase' «pythonRequiredModules»],) + install_requires=['LinguaFrancaBase' «pythonRequiredModules.join(", ")»],) ''' /** From d57deadbbd3c8e5351dbd6d976c8f9de279312a2 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 29 Jan 2022 21:48:36 -0600 Subject: [PATCH 093/121] Another merge artifact --- .../src/org/lflang/generator/python/PythonGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend index 82fc0fe61c..60bacf4bb5 100644 --- a/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/python/PythonGenerator.xtend @@ -864,7 +864,7 @@ class PythonGenerator extends CGenerator { setup(name="LinguaFranca«topLevelName»", version="1.0", ext_modules = [linguafranca«topLevelName»module], - install_requires=['LinguaFrancaBase' «pythonRequiredModules.join(", ")»],) + install_requires=['LinguaFrancaBase', «pythonRequiredModules.join(", ")»],) ''' /** From 6d6463db7cb52b429938d8516d73eb44315a9152 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sun, 30 Jan 2022 13:33:48 -0600 Subject: [PATCH 094/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 4ccf218727..dea6e2d692 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 4ccf218727ae39730a9c5ab1f1772b4038b379cc +Subproject commit dea6e2d69252574f1e6d898027734a6b0a1ed64a diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index b33891257d..17e2f8d041 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -95,7 +95,7 @@ public void rebuild() { } /* - * Get an array of non-zero integers representing the maximum number of reactions + * Get an array of non-negative integers representing the maximum number of reactions * per each level, where levels are indices of the array. */ public Integer[] getMaxNumOfReactionPerLevel() { From 43553284b4752d235e0354769ab6f40832ed67c7 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 00:45:32 -0600 Subject: [PATCH 095/121] Added scheduler options and params during code generation --- org.lflang/src/lib/c/reactor-c | 2 +- .../org/lflang/generator/c/CGenerator.xtend | 33 +++++++++++++++---- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index dea6e2d692..93fccc30bd 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit dea6e2d69252574f1e6d898027734a6b0a1ed64a +Subproject commit 93fccc30bd7d4eed47af2c248c222312e2949a59 diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index a5ecee9bfb..988044d38c 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -471,13 +471,6 @@ class CGenerator extends GeneratorBase { errorReporter.reportError("Main reactor has causality cycles. Skipping code generation."); return; } - // Add the maximum reaction level as a compile-time definition - targetConfig.compileDefinitions.put( - "MAX_REACTION_LEVEL", - String.valueOf( - this.main.assignLevels().maxNumOfReactionPerLevel.size - ) - ); // Avoid compile errors by removing disconnected network ports. // This must be done after assigning levels. removeRemoteFederateConnectionPorts(main); @@ -948,6 +941,7 @@ class CGenerator extends GeneratorBase { */ def addSchedulerFiles(ArrayList coreFiles) { coreFiles.add("threaded/scheduler.h") + coreFiles.add("threaded/scheduler_params.h") coreFiles.add("threaded/scheduler_sync_tag_advance.c") // Don't use the default non-preemptive scheduler if the program contains a deadline (handler). // Use the GEDF_NP scheduler instead. @@ -969,6 +963,9 @@ class CGenerator extends GeneratorBase { "scheduler_" + targetConfig.schedulerType.toString() + ".c" ); System.out.println("******** Using the "+targetConfig.schedulerType.toString()+" runtime scheduler."); + targetConfig.compileAdditionalSources.add( + "core" + File.separator + "utils" + File.separator + "semaphore.c" + ); } /** @@ -1079,6 +1076,9 @@ class CGenerator extends GeneratorBase { setReactionPriorities(main, code) initializeFederate(federate) + + initializeScheduler(); + code.unindent() code.pr("}\n") } @@ -1578,6 +1578,24 @@ class CGenerator extends GeneratorBase { } } + /** + * Generate code to initialize the scheduler foer the threaded C runtime. + */ + protected def initializeScheduler() { + if (targetConfig.threads > 0) { + code.pr(''' + // Initialize the scheduler + lf_sched_init( + «targetConfig.threads», + &(sched_options_t) { + .max_reactions_per_level = (size_t []) {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}, + .max_reaction_level = (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size» + } + ); + ''') + } + } + /** * Copy target-specific header file to the src-gen directory. */ @@ -4630,6 +4648,7 @@ class CGenerator extends GeneratorBase { protected def includeTargetLanguageSourceFiles() { if (targetConfig.threads > 0) { code.pr("#include \"core/threaded/reactor_threaded.c\"") + code.pr("#include \"core/threaded/scheduler.h\"") } else { code.pr("#include \"core/reactor.c\"") } From f1804d461dbd62758fab39e72aed8bf4c139a364 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 00:52:34 -0600 Subject: [PATCH 096/121] Fixed taking address of temporary array error --- org.lflang/src/lib/c/reactor-c | 2 +- .../src/org/lflang/generator/c/CGenerator.xtend | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 93fccc30bd..c721596c7e 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 93fccc30bd7d4eed47af2c248c222312e2949a59 +Subproject commit c721596c7e8dd431a4955fadd3fa1c8fcc2ccefe diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 988044d38c..2e64648b3b 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -1585,12 +1585,15 @@ class CGenerator extends GeneratorBase { if (targetConfig.threads > 0) { code.pr(''' // Initialize the scheduler + sched_options_t sched_options = (sched_options_t) { + .max_reactions_per_level = + (size_t []) {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}, + .max_reaction_level = + (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size» + }; lf_sched_init( «targetConfig.threads», - &(sched_options_t) { - .max_reactions_per_level = (size_t []) {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}, - .max_reaction_level = (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size» - } + &sched_options ); ''') } From 1ae914af1e3b198c7e59ae9772bfc3d7afccc6ba Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 00:58:40 -0600 Subject: [PATCH 097/121] Format fixes and Cpp-related fixes --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index c721596c7e..2cb60b1575 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit c721596c7e8dd431a4955fadd3fa1c8fcc2ccefe +Subproject commit 2cb60b157597e6692a353674700c1b8af0f2fc3b diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 2e64648b3b..bb02db93e2 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -1584,13 +1584,13 @@ class CGenerator extends GeneratorBase { protected def initializeScheduler() { if (targetConfig.threads > 0) { code.pr(''' + // Initialize the scheduler sched_options_t sched_options = (sched_options_t) { .max_reactions_per_level = (size_t []) {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}, .max_reaction_level = - (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size» - }; + (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size»}; lf_sched_init( «targetConfig.threads», &sched_options From 6aaafab6d25952e2631145b9a9d02955b4a47ef6 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 01:10:06 -0600 Subject: [PATCH 098/121] More Cpp-related fixes --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index bb02db93e2..bac2b04bcf 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -1586,11 +1586,11 @@ class CGenerator extends GeneratorBase { code.pr(''' // Initialize the scheduler + size_t max_reactions_per_level[«this.main.assignLevels().maxNumOfReactionPerLevel.size»] = + {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}; sched_options_t sched_options = (sched_options_t) { - .max_reactions_per_level = - (size_t []) {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}, - .max_reaction_level = - (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size»}; + .max_reactions_per_level = &max_reactions_per_level[0], + .max_reaction_level = (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size»}; lf_sched_init( «targetConfig.threads», &sched_options From 97ba3a436efe4f9e77de058d850977ddaff17c26 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 10:03:58 -0600 Subject: [PATCH 099/121] Renamed options to params --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index bac2b04bcf..9ec1c8c4fc 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -941,7 +941,7 @@ class CGenerator extends GeneratorBase { */ def addSchedulerFiles(ArrayList coreFiles) { coreFiles.add("threaded/scheduler.h") - coreFiles.add("threaded/scheduler_params.h") + coreFiles.add("threaded/scheduler_instance.h") coreFiles.add("threaded/scheduler_sync_tag_advance.c") // Don't use the default non-preemptive scheduler if the program contains a deadline (handler). // Use the GEDF_NP scheduler instead. @@ -1588,12 +1588,12 @@ class CGenerator extends GeneratorBase { // Initialize the scheduler size_t max_reactions_per_level[«this.main.assignLevels().maxNumOfReactionPerLevel.size»] = {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}; - sched_options_t sched_options = (sched_options_t) { + sched_params_t sched_params = (sched_params_t) { .max_reactions_per_level = &max_reactions_per_level[0], .max_reaction_level = (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size»}; lf_sched_init( «targetConfig.threads», - &sched_options + &sched_params ); ''') } From 9a9d640aa3e0ddcb3c9e67562b15e217c314f474 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 10:15:08 -0600 Subject: [PATCH 100/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 2cb60b1575..9c04b16777 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 2cb60b157597e6692a353674700c1b8af0f2fc3b +Subproject commit 9c04b167774db5c488f94afd2580b69a5d865be5 From 4b77cd6aa348bb80ee5e9b8436dd8e3e158b4088 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 16:54:10 -0600 Subject: [PATCH 101/121] Updated reactor-c --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 9ec1c8c4fc..ff63f638ed 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -1590,7 +1590,7 @@ class CGenerator extends GeneratorBase { {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}; sched_params_t sched_params = (sched_params_t) { .max_reactions_per_level = &max_reactions_per_level[0], - .max_reaction_level = (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size»}; + .max_reactions_per_level_size = (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size»}; lf_sched_init( «targetConfig.threads», &sched_params From 9fc26da4864ac10d8a4db21e5731e841e3365bb4 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 16:56:03 -0600 Subject: [PATCH 102/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 9c04b16777..fe8268bd33 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 9c04b167774db5c488f94afd2580b69a5d865be5 +Subproject commit fe8268bd337003cb901159c811038b5b6d2e4be0 From 8672a6b10785fd440caac4459517de26ef7d305e Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 17:22:27 -0600 Subject: [PATCH 103/121] Logic fix --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index fe8268bd33..a38de775d9 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit fe8268bd337003cb901159c811038b5b6d2e4be0 +Subproject commit a38de775d9d0de2973299583f063c97038f800af diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index 17e2f8d041..d9779a6fbd 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -286,6 +286,7 @@ private void assignLevels() { */ private void assignLevel(Runtime runtime, Integer level) { runtime.level = level; + adjustMaxNumOfReactionPerLevel(level, 1); } /** From 09414ee7c17632ede1a68daf1b920ca2d66c340f Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Mon, 31 Jan 2022 19:26:02 -0600 Subject: [PATCH 104/121] Updated reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index a38de775d9..a9bd0b5fe6 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit a38de775d9d0de2973299583f063c97038f800af +Subproject commit a9bd0b5fe6236eed7ff9cabd324f7edd176abd82 From 8142f4bbac9486b0382654ee8923b872941cfd54 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 2 Feb 2022 12:37:40 -0600 Subject: [PATCH 105/121] Fixed merge conflict --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index a9bd0b5fe6..53d0d4f892 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit a9bd0b5fe6236eed7ff9cabd324f7edd176abd82 +Subproject commit 53d0d4f892a5ab855b08761e125793e0129fbec7 From 82adb16ba4de94064e1e0ad23a84362f9d01751d Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Wed, 2 Feb 2022 14:45:06 -0600 Subject: [PATCH 106/121] Added a warning for the scheduler type. Updated tests slightly to test for priority --- org.lflang/src/lib/c/reactor-c | 2 +- org.lflang/src/org/lflang/TargetProperty.java | 25 +++++++++++++++---- .../lflang/generator/JavaGeneratorUtils.java | 1 + .../org/lflang/generator/c/CGenerator.xtend | 19 +++++++++++--- .../org/lflang/validation/LFValidator.xtend | 2 +- test/C/src/Deadline.lf | 11 ++++++++ test/Python/src/Deadline.lf | 15 ++++++++++- 7 files changed, 63 insertions(+), 12 deletions(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 53d0d4f892..232768f0a4 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 53d0d4f892a5ab855b08761e125793e0129fbec7 +Subproject commit 232768f0a42179c3212d554cae028db1b278fefd diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index e2f4e21ccc..60284eec5d 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -1290,15 +1290,30 @@ public String toString() { * @author{Soroush Bateni } */ public enum SchedulerOptions { - NP, // Non-preemptive - GEDF_NP, // Global EDF non-preemptive - GEDF_NP_CI; // Global EDF non-preemptive with chain ID - // PEDF_NP; // Partitioned EDF non-preemptive (FIXME: To be re-added in a future PR) + NP(false), // Non-preemptive + GEDF_NP(true), // Global EDF non-preemptive + GEDF_NP_CI(true); // Global EDF non-preemptive with chain ID + // PEDF_NP(true); // Partitioned EDF non-preemptive (FIXME: To be re-added in a future PR) + + /** + * Indicate whether or not the scheduler prioritizes reactions by deadline. + */ + private final Boolean prioritizesDeadline; + + /** + * Return true if the scheduler prioritizes reactions by deadline. + */ + public Boolean prioritizesDeadline() { + return this.prioritizesDeadline; + } + + private SchedulerOptions(Boolean prioritizesDeadline) { + this.prioritizesDeadline = prioritizesDeadline; + } public static SchedulerOptions getDefault() { return NP; } - } /** diff --git a/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java b/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java index 1677ac5ad0..56f8d013b2 100644 --- a/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java @@ -100,6 +100,7 @@ public static void setTargetConfig( targetConfig.schedulerType = TargetProperty.SchedulerOptions.valueOf( context.getArgs().getProperty("scheduler") ); + targetConfig.setByUser.add(TargetProperty.SCHEDULER); } if (context.getArgs().containsKey("target-flags")) { targetConfig.compilerFlags.clear(); diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 56f31b3870..6a5d80c04e 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -933,9 +933,9 @@ class CGenerator extends GeneratorBase { coreFiles.add("threaded/scheduler.h") coreFiles.add("threaded/scheduler_instance.h") coreFiles.add("threaded/scheduler_sync_tag_advance.c") - // Don't use the default non-preemptive scheduler if the program contains a deadline (handler). - // Use the GEDF_NP scheduler instead. - if (targetConfig.schedulerType == TargetProperty.SchedulerOptions.NP) { + // Don't use a scheduler that does not prioritize reactions based on deadlines + // if the program contains a deadline (handler). Use the GEDF_NP scheduler instead. + if (!targetConfig.schedulerType.prioritizesDeadline) { // Check if a deadline is assigned to any reaction if (reactors.filter[reactor | // Filter reactors that contain at least one reaction @@ -944,7 +944,18 @@ class CGenerator extends GeneratorBase { return reaction.deadline !== null ].size > 0; ].size > 0) { - targetConfig.schedulerType = TargetProperty.SchedulerOptions.GEDF_NP; + + if (targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { + // FIXME: This potentially belongs in the validator + // TODO: Move after LFValidator is ported + errorReporter.reportWarning("This program contains deadlines, but the chosen " + +targetConfig.schedulerType.name + +" scheduler does not prioritize reaction execution " + +"based on deadlines. This might result in a sub-optimal " + +"scheduling."); + } else { + targetConfig.schedulerType = TargetProperty.SchedulerOptions.GEDF_NP; + } } } coreFiles.add("threaded/scheduler_" + targetConfig.schedulerType.toString() + ".c"); diff --git a/org.lflang/src/org/lflang/validation/LFValidator.xtend b/org.lflang/src/org/lflang/validation/LFValidator.xtend index e2ed4b47ba..97ab4ffa2f 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.xtend +++ b/org.lflang/src/org/lflang/validation/LFValidator.xtend @@ -1238,7 +1238,7 @@ class LFValidator extends BaseLFValidator { Literals.KEY_VALUE_PAIR__NAME ) } - } + } } @Check(FAST) diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index 49b3d5fb64..6a1c6d101a 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -27,6 +27,7 @@ reactor Source(period:time(1500 msec)) { reactor Destination(timeout:time(1 sec)) { input x:int; state count:int(0); + state expected:int(1); reaction(x) {= printf("Destination receives: %d\n", x->value); if (2 * (self->count / 2) != self->count) { @@ -44,6 +45,16 @@ reactor Destination(timeout:time(1 sec)) { } (self->count)++; =} + + reaction(x) {= + info_print("Lower priority reaction invoked."); + if (self->count != self->expected++) { + error_print_and_exit( + "The reaction with the larger deadline was " + "invoked before the reaction with the smaller deadline." + ); + } + =} } main reactor Deadline { s = new Source(); diff --git a/test/Python/src/Deadline.lf b/test/Python/src/Deadline.lf index 186cd0c5e4..7c77eee07f 100644 --- a/test/Python/src/Deadline.lf +++ b/test/Python/src/Deadline.lf @@ -2,7 +2,8 @@ // Even numbers are sent by the Source immediately, whereas odd numbers // are sent after a big enough delay to violate the deadline. target Python { - timeout: 4 sec + timeout: 4 sec, + scheduler: GEDF_NP }; reactor Source(period(2 sec)) { output y; @@ -26,6 +27,7 @@ reactor Source(period(2 sec)) { reactor Destination(timeout(1 sec)) { input x; state count(0); + state expected(1); reaction(x) {= print("Destination receives: ", x.value) if self.count % 2 != 0: @@ -42,6 +44,17 @@ reactor Destination(timeout(1 sec)) { exit(2) self.count += 1 =} + + reaction(x) {= + print("Lower priority reaction invoked.") + if self.count != self.expected: + sys.stderr.write("ERROR: " + "The reaction with the larger deadline was " + "invoked before the reaction with the smaller deadline." + ) + exit(3) + self.expected+=1 + =} } main reactor Deadline { s = new Source(); From 906b6fbf22cb4db8f42b99bcbd7d561a58889fd4 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sat, 12 Feb 2022 23:46:59 -0800 Subject: [PATCH 107/121] Created separate test for non-standard schedulers that listens to system properties to select a specific scheduler --- org.lflang.tests/build.gradle | 2 + .../src/org/lflang/tests/AbstractTest.java | 48 ------------ .../src/org/lflang/tests/TestBase.java | 1 - .../lflang/tests/runtime/CSchedulerTest.java | 74 +++++++++++++++++++ .../src/org/lflang/tests/runtime/CTest.java | 15 +--- org.lflang/src/org/lflang/TargetConfig.java | 4 +- org.lflang/src/org/lflang/TargetProperty.java | 10 +-- .../lflang/generator/JavaGeneratorUtils.java | 4 +- 8 files changed, 86 insertions(+), 72 deletions(-) create mode 100644 org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java diff --git a/org.lflang.tests/build.gradle b/org.lflang.tests/build.gradle index 4261fbc338..df44eaa000 100644 --- a/org.lflang.tests/build.gradle +++ b/org.lflang.tests/build.gradle @@ -46,6 +46,8 @@ test { events "passed", "skipped", "failed" showStandardStreams = true } + // Pass the scheduler property on to the Java VM + systemProperty 'scheduler', System.getProperty('scheduler') // Suggested by Gradle documentation: https://guides.gradle.org/performance/#parallel_test_execution maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 useJUnitPlatform() diff --git a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java index 91b18f84a7..5299475590 100644 --- a/org.lflang.tests/src/org/lflang/tests/AbstractTest.java +++ b/org.lflang.tests/src/org/lflang/tests/AbstractTest.java @@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test; import org.lflang.ASTUtils; import org.lflang.Target; -import org.lflang.TargetProperty.SchedulerOptions; import org.lflang.tests.TestRegistry.TestCategory; /** @@ -64,14 +63,6 @@ protected boolean supportsDockerOption() { return false; } - - /** - * Whether to test different {@link org.lflang.TargetProperty#SchedulerOptions}. - */ - protected boolean supportsSchedulerSwapping() { - return false; - } - @Test public void runExampleTests() { runTestsForTargets(Message.DESC_EXAMPLE_TESTS, @@ -200,43 +191,4 @@ public void runWithFourThreads() { true ); } - - /** - * Swap the default runtime scheduler with other supported versions and run all the supported tests. - */ - @Test - public void runWithNonDefaultSchedulers() { - Assumptions.assumeTrue(supportsSchedulerSwapping(), Message.NO_SCHED_SWAPPING_SUPPORT); - - EnumSet categories = EnumSet.of(TestCategory.CONCURRENT, - TestCategory.MULTIPORT); - - // Add federated and docker tests if supported - if (!isWindows() && supportsFederatedExecution()) { - categories.add(TestCategory.FEDERATED); - if (isLinux() && supportsDockerOption()) { - categories.add(TestCategory.DOCKER_FEDERATED); - } - } - - for (SchedulerOptions scheduler: EnumSet.allOf(SchedulerOptions.class)) { - if (scheduler == SchedulerOptions.getDefault()) continue; - - this.runTestsForTargets( - Message.DESC_SCHED_SWAPPING + scheduler.toString() +".", - categories::contains, - test -> { - test.getContext() - .getArgs() - .setProperty( - "scheduler", - scheduler.toString() - ); - return true; - }, - TestLevel.EXECUTION, - true - ); - } - } } diff --git a/org.lflang.tests/src/org/lflang/tests/TestBase.java b/org.lflang.tests/src/org/lflang/tests/TestBase.java index 4d444a1e76..46374aaaf4 100644 --- a/org.lflang.tests/src/org/lflang/tests/TestBase.java +++ b/org.lflang.tests/src/org/lflang/tests/TestBase.java @@ -123,7 +123,6 @@ public static class Message { public static final String NO_DOCKER_SUPPORT = "Target does not support the 'docker' property."; public static final String NO_DOCKER_TEST_SUPPORT = "Docker tests are only supported on Linux."; public static final String NO_GENERICS_SUPPORT = "Target does not support generic types."; - public static final String NO_SCHED_SWAPPING_SUPPORT = "Target does not support runtime scheduler swapping."; /* Descriptions of collections of tests. */ public static final String DESC_SERIALIZATION = "Run serialization tests (threads = 0)."; diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java new file mode 100644 index 0000000000..7aa3251ec4 --- /dev/null +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java @@ -0,0 +1,74 @@ +package org.lflang.tests.runtime; + +import java.util.EnumSet; + +import org.junit.jupiter.api.Test; + +import org.lflang.Target; +import org.lflang.TargetProperty.SchedulerOption; +import org.lflang.tests.TestBase; +import org.lflang.tests.TestRegistry.TestCategory; + +/** + */ +public class CSchedulerTest extends TestBase { + + + public CSchedulerTest() { + super(Target.C); + } + + /** + * Swap the default runtime scheduler with other supported versions and + * run all the supported tests. Only run tests for a specific non-default + * scheduler if specified using a system property (e.g., -Dscheduler=GEDF_NP). + */ + @Test + public void runWithNonDefaultSchedulers() { + EnumSet categories = EnumSet.of(TestCategory.CONCURRENT, + TestCategory.MULTIPORT); + + // Add federated and docker tests if supported + if (!isWindows()) { + categories.add(TestCategory.FEDERATED); + if (isLinux()) { + categories.add(TestCategory.DOCKER_FEDERATED); + } + } + var name = System.getProperty("scheduler"); + + if (name != null) { + var option = EnumSet.allOf(SchedulerOption.class).stream() + .filter(it -> it.name().equals(name)).findFirst(); + if (option.isPresent()) { + this.runTest(option.get(), categories); + } else { + throw new RuntimeException("Cannot find runtime scheduler called " + name); + } + } else { + for (SchedulerOption scheduler: EnumSet.allOf(SchedulerOption.class)) { + if (scheduler == SchedulerOption.getDefault()) continue; + this.runTest(scheduler, categories); + } + } + } + + private void runTest(SchedulerOption scheduler, EnumSet categories) { + this.runTestsForTargets( + Message.DESC_SCHED_SWAPPING + scheduler.toString() +".", + categories::contains, + test -> { + test.getContext() + .getArgs() + .setProperty( + "scheduler", + scheduler.toString() + ); + return true; + }, + TestLevel.EXECUTION, + true + ); + } +} + diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java index 81eeddde81..4873ff1266 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CTest.java @@ -1,5 +1,3 @@ -/* Scoping unit tests. */ - /************* Copyright (c) 2019, The University of California at Berkeley. @@ -63,11 +61,6 @@ protected boolean supportsFederatedExecution() { protected boolean supportsDockerOption() { return true; } - - @Override - protected boolean supportsSchedulerSwapping() { - return true; - } @Test @Override @@ -105,13 +98,7 @@ public void runMultiportTests() { public void runWithFourThreads() { super.runWithFourThreads(); } - - @Test - @Override - public void runWithNonDefaultSchedulers() { - super.runWithNonDefaultSchedulers(); - } - + @Test @Override public void runSerializationTests() { diff --git a/org.lflang/src/org/lflang/TargetConfig.java b/org.lflang/src/org/lflang/TargetConfig.java index 4b6a3a936d..ab277e2ae2 100644 --- a/org.lflang/src/org/lflang/TargetConfig.java +++ b/org.lflang/src/org/lflang/TargetConfig.java @@ -35,7 +35,7 @@ import org.lflang.TargetProperty.ClockSyncMode; import org.lflang.TargetProperty.CoordinationType; import org.lflang.TargetProperty.LogLevel; -import org.lflang.TargetProperty.SchedulerOptions; +import org.lflang.TargetProperty.SchedulerOption; import org.lflang.generator.rust.RustTargetConfig; /** @@ -202,7 +202,7 @@ public class TargetConfig { public boolean singleFileProject = false; /** What runtime scheduler to use. */ - public SchedulerOptions schedulerType = SchedulerOptions.getDefault(); + public SchedulerOption schedulerType = SchedulerOption.getDefault(); /** * The number of worker threads to deploy. The default is zero (i.e., diff --git a/org.lflang/src/org/lflang/TargetProperty.java b/org.lflang/src/org/lflang/TargetProperty.java index 60284eec5d..af80f02cce 100644 --- a/org.lflang/src/org/lflang/TargetProperty.java +++ b/org.lflang/src/org/lflang/TargetProperty.java @@ -318,7 +318,7 @@ public enum TargetProperty { */ SCHEDULER("scheduler", UnionType.SCHEDULER_UNION, Arrays.asList(Target.C, Target.CCPP, Target.Python), (config, value, err) -> { - config.schedulerType = (SchedulerOptions) UnionType.SCHEDULER_UNION + config.schedulerType = (SchedulerOption) UnionType.SCHEDULER_UNION .forName(ASTUtils.toText(value)); }), @@ -768,7 +768,7 @@ public enum UnionType implements TargetPropertyType { BUILD_TYPE_UNION(Arrays.asList(BuildType.values()), null), COORDINATION_UNION(Arrays.asList(CoordinationType.values()), CoordinationType.CENTRALIZED), - SCHEDULER_UNION(Arrays.asList(SchedulerOptions.values()), SchedulerOptions.getDefault()), + SCHEDULER_UNION(Arrays.asList(SchedulerOption.values()), SchedulerOption.getDefault()), LOGGING_UNION(Arrays.asList(LogLevel.values()), LogLevel.INFO), CLOCK_SYNC_UNION(Arrays.asList(ClockSyncMode.values()), ClockSyncMode.INITIAL), @@ -1289,7 +1289,7 @@ public String toString() { * Supported schedulers. * @author{Soroush Bateni } */ - public enum SchedulerOptions { + public enum SchedulerOption { NP(false), // Non-preemptive GEDF_NP(true), // Global EDF non-preemptive GEDF_NP_CI(true); // Global EDF non-preemptive with chain ID @@ -1307,11 +1307,11 @@ public Boolean prioritizesDeadline() { return this.prioritizesDeadline; } - private SchedulerOptions(Boolean prioritizesDeadline) { + private SchedulerOption(Boolean prioritizesDeadline) { this.prioritizesDeadline = prioritizesDeadline; } - public static SchedulerOptions getDefault() { + public static SchedulerOption getDefault() { return NP; } } diff --git a/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java b/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java index 6cefe62e88..840bad278d 100644 --- a/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java +++ b/org.lflang/src/org/lflang/generator/JavaGeneratorUtils.java @@ -6,7 +6,6 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -30,6 +29,7 @@ import org.lflang.TargetConfig; import org.lflang.TargetConfig.Mode; import org.lflang.TargetProperty; +import org.lflang.TargetProperty.SchedulerOption; import org.lflang.graph.InstantiationGraph; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; @@ -99,7 +99,7 @@ public static void setTargetConfig( targetConfig.compiler = context.getArgs().getProperty("target-compiler"); } if (context.getArgs().containsKey("scheduler")) { - targetConfig.schedulerType = TargetProperty.SchedulerOptions.valueOf( + targetConfig.schedulerType = SchedulerOption.valueOf( context.getArgs().getProperty("scheduler") ); targetConfig.setByUser.add(TargetProperty.SCHEDULER); From dbb9017ea0e1049d4bae6adacd2fb51e82df2063 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 13 Feb 2022 09:28:12 -0800 Subject: [PATCH 108/121] Use 4 threads for scheduler tests --- .../src/org/lflang/tests/runtime/CSchedulerTest.java | 2 +- org.lflang/src/lib/c/reactor-c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java index 7aa3251ec4..4124501340 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java @@ -64,7 +64,7 @@ private void runTest(SchedulerOption scheduler, EnumSet categories "scheduler", scheduler.toString() ); - return true; + return Configurators.useFourThreads(test); }, TestLevel.EXECUTION, true diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index cf47a41389..232768f0a4 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit cf47a413890f23d59b7d9093eba46be99c04d339 +Subproject commit 232768f0a42179c3212d554cae028db1b278fefd From bc08e6440f2ee445477aa6e7ed6643306212b5f5 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 13 Feb 2022 11:04:31 -0800 Subject: [PATCH 109/121] Parameterized C tests workflow with scheduler option --- .github/workflows/c-tests.yml | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 071341fdb6..5a80eed39a 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -13,6 +13,9 @@ on: required: false type: boolean default: false + scheduler: + required: false + type: string jobs: run: @@ -53,14 +56,18 @@ jobs: - name: Build RTI docker image uses: ./.github/actions/build-rti-docker if: ${{ runner.os == 'Linux' }} - - name: Perform tests for C target + - name: Perform tests for C target with default scheduler run: | ./gradlew test --tests org.lflang.tests.runtime.CTest.* --tests org.lflang.tests.lsp.LspTests.lspWithDependenciesTestC - if: ${{ !inputs.use-cpp }} - - name: Perform tests for CCpp target + if: ${{ !inputs.use-cpp && !inputs.scheduler }} + - name: Perform tests for C target with specified scheduler (no LSP tests) + run: | + ./gradlew test --tests org.lflang.tests.runtime.CSchedulerTest.* -Dscheduler=${{ inputs.scheduler }} + if: ${{ !inputs.use-cpp && inputs.scheduler }} + - name: Perform tests for CCpp target with default scheduler run: | ./gradlew test --tests org.lflang.tests.runtime.CCppTest.* - if: ${{ inputs.use-cpp }} + if: ${{ inputs.use-cpp && !inputs.scheduler }} - name: Report to CodeCov uses: codecov/codecov-action@v2.1.0 with: From 79b9bed96c52a38d8959d90dbe388882faa238ac Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 13 Feb 2022 11:20:24 -0800 Subject: [PATCH 110/121] IntelliJ refactoring ignores Xtend files; provided manual fix --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 872060a0e9..32a93d0b24 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -951,7 +951,7 @@ class CGenerator extends GeneratorBase { +"based on deadlines. This might result in a sub-optimal " +"scheduling."); } else { - targetConfig.schedulerType = TargetProperty.SchedulerOptions.GEDF_NP; + targetConfig.schedulerType = TargetProperty..GEDF_NP; } } } From 6a9e4d9791e76ed7a9428a792c87670b35b99d78 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 13 Feb 2022 11:30:19 -0800 Subject: [PATCH 111/121] Fix typo --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 32a93d0b24..52d4b1f153 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -951,7 +951,7 @@ class CGenerator extends GeneratorBase { +"based on deadlines. This might result in a sub-optimal " +"scheduling."); } else { - targetConfig.schedulerType = TargetProperty..GEDF_NP; + targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; } } } From 108b026f3329f77d9a9402c0122e7787b0a2e58b Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 13 Feb 2022 11:59:04 -0800 Subject: [PATCH 112/121] Fix compile error --- org.lflang.tests/src/org/lflang/tests/Configurators.java | 6 +++--- .../src/org/lflang/tests/runtime/CSchedulerTest.java | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/org.lflang.tests/src/org/lflang/tests/Configurators.java b/org.lflang.tests/src/org/lflang/tests/Configurators.java index 872a4341b7..1e64dc5f5e 100644 --- a/org.lflang.tests/src/org/lflang/tests/Configurators.java +++ b/org.lflang.tests/src/org/lflang/tests/Configurators.java @@ -51,7 +51,7 @@ public interface Configurator { * @param test The test to configure. * @return True if successful, false otherwise. */ - static boolean useSingleThread(LFTest test) { + public static boolean useSingleThread(LFTest test) { test.getContext().getArgs().setProperty("threads", "0"); return true; } @@ -62,7 +62,7 @@ static boolean useSingleThread(LFTest test) { * @param test The test to configure * @return True if successful, false otherwise. */ - static boolean useFourThreads(LFTest test) { + public static boolean useFourThreads(LFTest test) { test.getContext().getArgs().setProperty("threads", "4"); return true; } @@ -73,7 +73,7 @@ static boolean useFourThreads(LFTest test) { * @param test The test to configure. * @return True */ - static boolean noChanges(LFTest test) { + public static boolean noChanges(LFTest test) { return true; } diff --git a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java b/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java index 4124501340..c4fa0a2b2b 100644 --- a/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java +++ b/org.lflang.tests/src/org/lflang/tests/runtime/CSchedulerTest.java @@ -6,6 +6,7 @@ import org.lflang.Target; import org.lflang.TargetProperty.SchedulerOption; +import org.lflang.tests.Configurators; import org.lflang.tests.TestBase; import org.lflang.tests.TestRegistry.TestCategory; From 3e9d836015f2e8c9221cb9da075743f865018d4d Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 13 Feb 2022 12:13:30 -0800 Subject: [PATCH 113/121] Echo specified scheduler --- .github/workflows/c-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/c-tests.yml b/.github/workflows/c-tests.yml index 5a80eed39a..70a3a83990 100644 --- a/.github/workflows/c-tests.yml +++ b/.github/workflows/c-tests.yml @@ -62,6 +62,7 @@ jobs: if: ${{ !inputs.use-cpp && !inputs.scheduler }} - name: Perform tests for C target with specified scheduler (no LSP tests) run: | + echo "Specified scheduler: ${{ inputs.scheduler }}" ./gradlew test --tests org.lflang.tests.runtime.CSchedulerTest.* -Dscheduler=${{ inputs.scheduler }} if: ${{ !inputs.use-cpp && inputs.scheduler }} - name: Perform tests for CCpp target with default scheduler From b65274a7955a11f91f1d4c0e90dd0e74c3890887 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Fri, 25 Feb 2022 23:30:52 -0600 Subject: [PATCH 114/121] Attempt to fix merge artifact --- .../src/org/lflang/generator/c/CGenerator.xtend | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 1c30aa654f..52ad27d8f3 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -333,7 +333,7 @@ class CGenerator extends GeneratorBase { } /** - * Set C-specific default target properties if needed. + * Set C-specific default target configurations if needed. */ def setCSpecificDefaults(LFGeneratorContext context) { if (!targetConfig.useCmake && targetConfig.compiler.isNullOrEmpty) { @@ -345,6 +345,17 @@ class CGenerator extends GeneratorBase { targetConfig.compilerFlags.addAll("-O2") // "-Wall -Wconversion" } } + if (isFederated) { + // Add compile definitions for federated execution + targetConfig.compileDefinitions.put("FEDERATED", ""); + if (targetConfig.coordination === CoordinationType.CENTRALIZED) { + // The coordination is centralized. + targetConfig.compileDefinitions.put("FEDERATED_CENTRALIZED", ""); + } else if (targetConfig.coordination === CoordinationType.DECENTRALIZED) { + // The coordination is decentralized + targetConfig.compileDefinitions.put("FEDERATED_DECENTRALIZED", ""); + } + } } /** From 980097a771e2eb8cb4a239aa769ebdbfa50a06ba Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 26 Feb 2022 00:13:17 -0600 Subject: [PATCH 115/121] Moved check --- .../org/lflang/generator/c/CGenerator.xtend | 11 +------ .../org/lflang/validation/LFValidator.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index 52ad27d8f3..b5f6c887d4 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -930,16 +930,7 @@ class CGenerator extends GeneratorBase { return reaction.deadline !== null ].size > 0; ].size > 0) { - - if (targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { - // FIXME: This potentially belongs in the validator - // TODO: Move after LFValidator is ported - errorReporter.reportWarning("This program contains deadlines, but the chosen " - +targetConfig.schedulerType.name - +" scheduler does not prioritize reaction execution " - +"based on deadlines. This might result in a sub-optimal " - +"scheduling."); - } else { + if (!targetConfig.setByUser.contains(TargetProperty.SCHEDULER)) { targetConfig.schedulerType = TargetProperty.SchedulerOption.GEDF_NP; } } diff --git a/org.lflang/src/org/lflang/validation/LFValidator.java b/org.lflang/src/org/lflang/validation/LFValidator.java index 8a95bf8f72..1b72a035f8 100644 --- a/org.lflang/src/org/lflang/validation/LFValidator.java +++ b/org.lflang/src/org/lflang/validation/LFValidator.java @@ -1109,6 +1109,36 @@ public void checkTargetProperties(KeyValuePairs targetProperties) { ); } } + + + EList schedulerTargetProperties = + new BasicEList<>(targetProperties.getPairs()); + schedulerTargetProperties.removeIf(pair -> TargetProperty + .forName(pair.getName()) != TargetProperty.SCHEDULER); + KeyValuePair schedulerTargetProperty = schedulerTargetProperties + .size() > 0 ? schedulerTargetProperties.get(0) : null; + if (schedulerTargetProperty != null) { + String schedulerName = schedulerTargetProperty.getValue().getId(); + if (!TargetProperty.SchedulerOption.valueOf(schedulerName) + .prioritizesDeadline()) { + // Check if a deadline is assigned to any reaction + if (info.model.getReactors().stream().filter(reactor -> { + // Filter reactors that contain at least one reaction that + // has a deadline handler. + return ASTUtils.allReactions(reactor).stream() + .filter(reaction -> { + return reaction.getDeadline() != null; + }).count() > 0; + }).count() > 0) { + warning("This program contains deadlines, but the chosen " + + schedulerName + + " scheduler does not prioritize reaction execution " + + "based on deadlines. This might result in a sub-optimal " + + "scheduling.", schedulerTargetProperty, + Literals.KEY_VALUE_PAIR__VALUE); + } + } + } } @Check(CheckType.FAST) From 27e74f51f91686aeef09a857a54a40aa50b6f5a4 Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 26 Feb 2022 00:23:06 -0600 Subject: [PATCH 116/121] Revert incorrect tests --- test/C/src/Deadline.lf | 11 ----------- test/Python/src/Deadline.lf | 15 +-------------- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/test/C/src/Deadline.lf b/test/C/src/Deadline.lf index 6a1c6d101a..49b3d5fb64 100644 --- a/test/C/src/Deadline.lf +++ b/test/C/src/Deadline.lf @@ -27,7 +27,6 @@ reactor Source(period:time(1500 msec)) { reactor Destination(timeout:time(1 sec)) { input x:int; state count:int(0); - state expected:int(1); reaction(x) {= printf("Destination receives: %d\n", x->value); if (2 * (self->count / 2) != self->count) { @@ -45,16 +44,6 @@ reactor Destination(timeout:time(1 sec)) { } (self->count)++; =} - - reaction(x) {= - info_print("Lower priority reaction invoked."); - if (self->count != self->expected++) { - error_print_and_exit( - "The reaction with the larger deadline was " - "invoked before the reaction with the smaller deadline." - ); - } - =} } main reactor Deadline { s = new Source(); diff --git a/test/Python/src/Deadline.lf b/test/Python/src/Deadline.lf index 7c77eee07f..186cd0c5e4 100644 --- a/test/Python/src/Deadline.lf +++ b/test/Python/src/Deadline.lf @@ -2,8 +2,7 @@ // Even numbers are sent by the Source immediately, whereas odd numbers // are sent after a big enough delay to violate the deadline. target Python { - timeout: 4 sec, - scheduler: GEDF_NP + timeout: 4 sec }; reactor Source(period(2 sec)) { output y; @@ -27,7 +26,6 @@ reactor Source(period(2 sec)) { reactor Destination(timeout(1 sec)) { input x; state count(0); - state expected(1); reaction(x) {= print("Destination receives: ", x.value) if self.count % 2 != 0: @@ -44,17 +42,6 @@ reactor Destination(timeout(1 sec)) { exit(2) self.count += 1 =} - - reaction(x) {= - print("Lower priority reaction invoked.") - if self.count != self.expected: - sys.stderr.write("ERROR: " - "The reaction with the larger deadline was " - "invoked before the reaction with the smaller deadline." - ) - exit(3) - self.expected+=1 - =} } main reactor Deadline { s = new Source(); From 2778331c454444178f0af8198bcecf94b3c929ed Mon Sep 17 00:00:00 2001 From: Soroush Bateni Date: Sat, 26 Feb 2022 00:25:36 -0600 Subject: [PATCH 117/121] Reverted continue_on_error --- benchmark/runner/conf/default.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benchmark/runner/conf/default.yaml b/benchmark/runner/conf/default.yaml index dbb58a43c6..b109df8058 100644 --- a/benchmark/runner/conf/default.yaml +++ b/benchmark/runner/conf/default.yaml @@ -3,7 +3,7 @@ threads: null timeout: 1200 savina_path: "${oc.env:SAVINA_PATH}" lf_path: "${oc.env:LF_PATH}" -continue_on_error: True +continue_on_error: False test_mode: False defaults: - benchmark: ??? From 61a5ed52906ef640c6e09b5b08a0add4351f924f Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 26 Feb 2022 08:39:05 -0800 Subject: [PATCH 118/121] set to point to c-new-scheduler branch of reactor-c --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index b630601f79..0cd4202eac 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit b630601f7945d450d33b58bb996984fdaa3a3199 +Subproject commit 0cd4202eac64a21f7b7f6294352d7161478b4e9b From 9af2f830c0403ea25aff9d935a73406d492f4d08 Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 26 Feb 2022 08:48:21 -0800 Subject: [PATCH 119/121] Renamed max levels to num levels --- org.lflang/src/org/lflang/generator/c/CGenerator.xtend | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend index b5f6c887d4..fda61f5d08 100644 --- a/org.lflang/src/org/lflang/generator/c/CGenerator.xtend +++ b/org.lflang/src/org/lflang/generator/c/CGenerator.xtend @@ -1554,14 +1554,15 @@ class CGenerator extends GeneratorBase { */ protected def initializeScheduler() { if (targetConfig.threads > 0) { + val numReactionsPerLevel = this.main.assignLevels.getNumReactionsPerLevel(); code.pr(''' // Initialize the scheduler - size_t max_reactions_per_level[«this.main.assignLevels().maxNumOfReactionPerLevel.size»] = - {«this.main.assignLevels().maxNumOfReactionPerLevel.join(", \\\n")»}; + size_t num_reactions_per_level[«numReactionsPerLevel.size»] = + {«numReactionsPerLevel.join(", \\\n")»}; sched_params_t sched_params = (sched_params_t) { - .max_reactions_per_level = &max_reactions_per_level[0], - .max_reactions_per_level_size = (size_t) «this.main.assignLevels().maxNumOfReactionPerLevel.size»}; + .num_reactions_per_level = &num_reactions_per_level[0], + .num_reactions_per_level_size = (size_t) «numReactionsPerLevel.size»}; lf_sched_init( «targetConfig.threads», &sched_params From 34bb15a1001e20d3517129ebc96131774982f8d8 Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 26 Feb 2022 08:48:49 -0800 Subject: [PATCH 120/121] Fixed suspicious methods for adjusting number of levels count. --- .../generator/ReactionInstanceGraph.java | 40 ++++++++++--------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java index d9779a6fbd..bc77c60939 100644 --- a/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java +++ b/org.lflang/src/org/lflang/generator/ReactionInstanceGraph.java @@ -95,11 +95,11 @@ public void rebuild() { } /* - * Get an array of non-negative integers representing the maximum number of reactions + * Get an array of non-negative integers representing the number of reactions * per each level, where levels are indices of the array. */ - public Integer[] getMaxNumOfReactionPerLevel() { - return maxNumOfReactionPerLevel.toArray(new Integer[0]); + public Integer[] getNumReactionsPerLevel() { + return numReactionsPerLevel.toArray(new Integer[0]); } /////////////////////////////////////////////////////////// @@ -218,10 +218,10 @@ protected void addNodesAndEdges(ReactorInstance reactor) { //// Private fields /** - * Maximum number of reactions per level, represented as a list of + * Number of reactions per level, represented as a list of * integers where the indices are the levels. */ - private List maxNumOfReactionPerLevel = new ArrayList<>( + private List numReactionsPerLevel = new ArrayList<>( List.of(Integer.valueOf(0))); /////////////////////////////////////////////////////////// @@ -254,7 +254,7 @@ private void assignLevels() { // All downstream adjacent nodes start with a level 0. Adjust the // maxNumOfReactionPerLevel field accordingly (to be // updated in the for loop below). - adjustMaxNumOfReactionPerLevel(0, downstreamAdjacentNodes.size()); + adjustNumReactionsPerLevel(0, downstreamAdjacentNodes.size()); // Visit effect nodes. for (Runtime effect : downstreamAdjacentNodes) { // Stage edge between origin and effect for removal. @@ -286,7 +286,7 @@ private void assignLevels() { */ private void assignLevel(Runtime runtime, Integer level) { runtime.level = level; - adjustMaxNumOfReactionPerLevel(level, 1); + adjustNumReactionsPerLevel(level, 1); } /** @@ -296,24 +296,28 @@ private void assignLevel(Runtime runtime, Integer level) { */ private void updateLevel(Runtime runtime, Integer level) { if (runtime.level < level) { + adjustNumReactionsPerLevel(runtime.level, -1); runtime.level = level; - // Adjust the maxNumOfReactionPerLevel field - // accordingly. - adjustMaxNumOfReactionPerLevel(runtime.level, -1); - adjustMaxNumOfReactionPerLevel(level, 1); + adjustNumReactionsPerLevel(level, 1); } } /** - * Adjust {@link #maxNumOfReactionPerLevel} at index level by - * valueToAdd. + * Adjust {@link #numReactionsPerLevel} at index level by + * adding to the previously recorded number valueToAdd. + * If there is no previously recorded number for this level, then + * create one with index level and value valueToAdd. + * @param level The level. + * @param valueToAdd The value to add to the number of levels. */ - private void adjustMaxNumOfReactionPerLevel(int level, int valueToAdd) { - if (maxNumOfReactionPerLevel.size() > level) { - maxNumOfReactionPerLevel.set(level, maxNumOfReactionPerLevel.get(0) + valueToAdd); + private void adjustNumReactionsPerLevel(int level, int valueToAdd) { + if (numReactionsPerLevel.size() > level) { + numReactionsPerLevel.set(level, numReactionsPerLevel.get(level) + valueToAdd); } else { - maxNumOfReactionPerLevel.add(level, valueToAdd); + while (numReactionsPerLevel.size() < level) { + numReactionsPerLevel.add(0); + } + numReactionsPerLevel.add(valueToAdd); } - } } From 900c4493cfe5bdd14dccf6dd5091390750621dc2 Mon Sep 17 00:00:00 2001 From: eal Date: Sat, 26 Feb 2022 10:56:15 -0800 Subject: [PATCH 121/121] Point to reactor-c main branch, which now has c-new-scheduler merged in --- org.lflang/src/lib/c/reactor-c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.lflang/src/lib/c/reactor-c b/org.lflang/src/lib/c/reactor-c index 0cd4202eac..e7306edb43 160000 --- a/org.lflang/src/lib/c/reactor-c +++ b/org.lflang/src/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 0cd4202eac64a21f7b7f6294352d7161478b4e9b +Subproject commit e7306edb430560aca043dc47345e24bf5f1f87d3