changeset 877:e2a0e5a65a3d

...
author anatofuz <anatofuz@cr.ie.u-ryukyu.ac.jp>
date Sat, 23 Jan 2021 21:02:49 +0900
parents 8c89ee7dd6b3
children 5125f75dd6f2
files src/parallel_execution/AtomicT.h src/parallel_execution/AtomicTImpl.cbc src/parallel_execution/examples/DPP/PhilsImpl.cbc src/parallel_execution/examples/DPP/main.cbc src/parallel_execution/examples/DPP2/PhilsImpl.cbc
diffstat 5 files changed, 49 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/src/parallel_execution/AtomicT.h	Sat Jan 23 18:41:22 2021 +0900
+++ b/src/parallel_execution/AtomicT.h	Sat Jan 23 21:02:49 2021 +0900
@@ -1,6 +1,6 @@
 typedef struct AtomicT <T>{
-    __code checkAndSet(Impl* atomic_t,T* ptr ,T init, T newData, __code next(...), __code fail(...));
-    __code set(Impl* atomic_t,T* ptr ,T newData, __code next(...));
+    __code checkAndSet(Impl* atomicT,T oldData, T newData, __code next(...), __code fail(...));
+    __code set(Impl* atomicT,T newData, __code next(...));
     __code next(...);
     __code fail(...);
 } AtomicT;
--- a/src/parallel_execution/AtomicTImpl.cbc	Sat Jan 23 18:41:22 2021 +0900
+++ b/src/parallel_execution/AtomicTImpl.cbc	Sat Jan 23 21:02:49 2021 +0900
@@ -2,28 +2,26 @@
 #impl "AtomicT.h" for "AtomicTImpl.h"
 #include <stdio.h>
 
-AtomicT<T>* createAtomicTImpl(struct Context* context,T init) {
-    struct AtomicT<T>* atomic_t  = new AtomicT();
-    struct AtomicTImpl<T>* atomic_t_impl = new AtomicTImpl();
-    atomic_t->atomic_t = (union Data*)atomic_t_impl;
-    atomic_t->checkAndSet = C_checkAndSetAtomicTImpl;
-    atomic_t->set = C_setAtomicTImpl;
-    atomic_t->fail = C_failAtomicTImpl;
-    atomic_t_impl->atomic = init;
-    atomic_t_impl->init = init;
-    return atomic_t;
-
+AtomicT<T> *createAtomicTImpl(struct Context* context, T init){
+    struct AtomicT<T>* atomicT = new AtomicT();
+    struct AtomicTImpl<T>* atomicT_impl = new AtomicTImpl();
+    atomicT->atomicT = (union Data *)atomic_t_impl;
+    atomicT->checkAndSet = C_checkAndSetAtomicTImpl;
+    atomicT->set = C_setAtomicTImpl;
+    atomicT->fail = C_failAtomicTImpl;
+    atomicT_impl->atomic = init;
+    atomict_impl->init = init;
+    return atomicT;
 }
 
-__code checkAndSet_AtomicTImpl(struct AtomicTImpl* atomic_t_impl, T* ptr,T init, T newData, __code next(...), __code fail(...)) {
-    if (__sync_bool_compare_and_swap(ptr, init, newData)) {
+__code checkAndSet_AtomicTImpl(struct AtomicTImpl* atomicT_impl, T oldData, T newData, __code next(...), __code fail(...)){
+    if (__sync_bool_compare_and_swap(&atomicT->atomic, init, newData)){
         goto next(...);
     }
     goto fail(...);
 }
 
-__code set_AtomicTImpl(struct AtomicTImpl* atomic_t_impl, T* ptr, T newData, __code next(...) ) {
-	*ptr = newData;
-   goto next(...);
+__code set_AtomicTImpl(struct AtomicTImpl* atomicT_impl, T newData, __code next(...)){
+    atomicT_impl->atomic = newData;
+    goto next(...);
 }
-
--- a/src/parallel_execution/examples/DPP/PhilsImpl.cbc	Sat Jan 23 18:41:22 2021 +0900
+++ b/src/parallel_execution/examples/DPP/PhilsImpl.cbc	Sat Jan 23 21:02:49 2021 +0900
@@ -6,7 +6,6 @@
 #interface "AtomicT.h"
 #interface "TaskManager.h"
 
-
 // ----
 // typedef struct PhilsImpl <Self, Isa> impl Phils {
 //   __code next(...);
@@ -16,10 +15,10 @@
 // } PhilsImpl;
 // ----
 
-Phils* createPhilsImpl(struct Context* context, int id, AtomicT<int> right, AtomicT<int> left) {
-    struct Phils* phils  = new Phils();
+Phils *createPhilsImpl(struct Context *context, int id, AtomicT<int> right, AtomicT<int> left){
+    struct Phils* phils = new Phils();
     struct PhilsImpl* phils_impl = new PhilsImpl();
-    phils->phils = (union Data*)phils_impl;
+    phils->phils = (union Data *)phils_impl;
     phils_impl->Leftfork = left;
     phils_impl->Rightfork = right;
     phils_impl->self = 0;
@@ -32,31 +31,32 @@
     return phils;
 }
 
-__code putdown_lfork_PhilsImpl(struct PhilsImpl* phils, __code next(...)) {
-    goto phils->Leftfork->set(-1, putdown_rfork_PhilsImpl);
-
+__code putdown_rfork(struct PhilsImpl* phils, __code next(...)){
+    struct AtomicT<int>* right_fork = phils->Rightfork;
+    goto right_fork->set(0, putdown_lfork);
 }
 
-__code putdown_rfork_PhilsImpl(struct PhilsImpl* phils, __code next(...)) {
-    goto phils->Rightfork->set(-1, putdown_lfork_PhilsImpl);
+__code putdown_lfork(struct PhilsImpl* phils, __code next(...)){
+    struct AtomicT<int>* left_fork = phils->Leftfork;
+    goto left_fork->set(0, thinking);
 }
 
-__code thinking_PhilsImpl(struct PhilsImpl* phils, struct Fork* fork, __code next(...)) {
-    printf("%d: thinking\n", phils->phils->id);
-    goto pickup_lfork(phils_impl->self);
+__code thinking(struct PhilsImpl* phils, struct Fork* fork, __code next(...)){
+    printf("%d: thinking\n", phils->self);
+    goto pickup_lfork();
 }
 
-__code pickup_rfork_PhilsImpl(struct PhilsImpl* phils, __code next(...)) {
-    goto phils->Rightfork->checkAndSet(id, -1, pickup_lfork_Phils, pickup_rfork_Phils);
+__code pickup_rfork(struct PhilsImpl* phils, __code next(...)){
+    struct AtomicT<int>* right_fork = phils->Rightfork;
+    goto right_fork->checkAndSet(-1, 0, pickup_lfork, pickup_rfork)
 }
 
-__code pickup_lfork_PhilsImpl(struct PhilsImpl* phils, __code next(...)) {
-    goto phils->Leftfork->checkAndSet(id, -1, pickup_rfork_Phils, eating_PhilsImpl);
-
+__code pickup_lfork(struct PhilsImpl* phils, __code next(...)){
+    struct AtomicT<int>* left_fork = phils->Leftfork;
+    goto left_fork->checkAndSet(-1, 0, pickup_rfork, eating);
 }
 
-__code eating_PhilsImpl(struct PhilsImpl* phils, __code next(...)) {
-    printf("%d: eating\n", phils_impl->self->id);
+__code eating(struct PhilsImpl* phils, __code next(...)){
+    printf("%d: eating\n", phils_impl->self);
     goto putdown_rfork();
 }
-
--- a/src/parallel_execution/examples/DPP/main.cbc	Sat Jan 23 18:41:22 2021 +0900
+++ b/src/parallel_execution/examples/DPP/main.cbc	Sat Jan 23 21:02:49 2021 +0900
@@ -10,7 +10,7 @@
 #interface "Fork.h"
 #interface "AtomicT.h"
 
-int cpu_num = 1;
+int cpu_num = 5;
 int length = 102400;
 int split = 8;
 int* array_ptr;
@@ -46,17 +46,17 @@
     AtomicT<int>* fork3 = createAtomicTImpl(contex,-1); // model checking : fork3
     AtomicT<int>* fork4 = createAtomicTImpl(contex,-1); // model checking : fork4
 
-    Phils* phils0 = createPhilsImpl(context,0,*fork0,*fork1); // model checking : phils0
-    Phils* phils1 = createPhilsImpl(context,1,*fork1,*fork2); // model checking : phils1
-    Phils* phils2 = createPhilsImpl(context,2,*fork2,*fork3); // model checking : phils2
-    Phils* phils3 = createPhilsImpl(context,3,*fork3,*fork4); // model checking : phils3
-    Phils* phils4 = createPhilsImpl(context,4,*fork4,*fork0); // model checking : phils4
+    Phils* phils0 = createPhilsImpl(context,0,fork0,fork1); // model checking : phils0
+    Phils* phils1 = createPhilsImpl(context,1,fork1,fork2); // model checking : phils1
+    Phils* phils2 = createPhilsImpl(context,2,fork2,fork3); // model checking : phils2
+    Phils* phils3 = createPhilsImpl(context,3,fork3,fork4); // model checking : phils3
+    Phils* phils4 = createPhilsImpl(context,4,fork4,fork0); // model checking : phils4
 
-    par goto phils0->thinking( __exit);
-    par goto phils1->thinking( __exit);
-    par goto phils2->thinking( __exit);
-    par goto phils3->thinking( __exit);
-    par goto phils4->thinking( __exit);
+    par goto phils0->thinking(exit_code);
+    par goto phils1->thinking(exit_code);
+    par goto phils2->thinking(exit_code);
+    par goto phils3->thinking(exit_code);
+    par goto phils4->thinking(exit_code);
 
     goto code2();
 }
@@ -88,4 +88,3 @@
     init(argc, argv);
     goto initDataGears();
 }
-OB
--- a/src/parallel_execution/examples/DPP2/PhilsImpl.cbc	Sat Jan 23 18:41:22 2021 +0900
+++ b/src/parallel_execution/examples/DPP2/PhilsImpl.cbc	Sat Jan 23 21:02:49 2021 +0900
@@ -46,7 +46,7 @@
 
 __code thinking(struct PhilsImpl* phils, struct Fork* fork, __code next(...)) {
     printf("%d: thinking\n", phils->self);
-    goto pickup_lfork(phils->self);
+    goto pickup_lfork();
 }
 
 __code pickup_rfork(struct PhilsImpl* phils, __code next(...)) {