Mercurial > hg > Gears > Gears
view src/parallel_execution/examples/DPPMC/main.cbc @ 1030:c0cff89bb044
...
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 16 Oct 2023 18:19:31 +0900 |
parents | 635ccc391642 |
children | 793b21a8ea12 |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include "../../../context.h" #interface "TaskManager.h" #interface "Phils.h" #interface "Fork.h" #interface "AtomicT_int.h" #include "McDPP.h" //#include "../../ModelChecking/memory.h" extern void addMemoryPhilsImpl(MCTaskManagerImpl *mcti, struct PhilsImpl* phils); int cpu_num = 1; int gpu_num = 0; int CPU_ANY = -1; int CPU_CUDA = -1; __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { // loopCounter->tree = createRedBlackTree(context); loopCounter->i = 0; taskManager->taskManager = (union Data*)createMCTaskManagerImpl(context, cpu_num, gpu_num, 0); goto code1(); } __code code1() { printf("cpus:\t\t%d\n", cpu_num); printf("gpus:\t\t%d\n", gpu_num); goto createTask1(); } __code createTask1(struct TaskManager* taskManager) { // without taskManager, par goto won't work AtomicT_int* fork0 = createAtomicT_intImpl_int(context,-1); // fork0 AtomicT_int* fork1 = createAtomicT_intImpl_int(context,-1); // fork1 AtomicT_int* fork2 = createAtomicT_intImpl_int(context,-1); // fork2 AtomicT_int* fork3 = createAtomicT_intImpl_int(context,-1); // fork3 AtomicT_int* fork4 = createAtomicT_intImpl_int(context,-1); // fork4 struct MCTaskManagerImpl *mcti = (struct MCTaskManagerImpl *)context->taskManager->taskManager; add_memory_range(&((struct AtomicT_intImpl_int*)fork0->atomicT_int)->atomic, sizeof(int), &mcti->mem); add_memory_range(&((struct AtomicT_intImpl_int*)fork1->atomicT_int)->atomic, sizeof(int), &mcti->mem); add_memory_range(&((struct AtomicT_intImpl_int*)fork2->atomicT_int)->atomic, sizeof(int), &mcti->mem); add_memory_range(&((struct AtomicT_intImpl_int*)fork3->atomicT_int)->atomic, sizeof(int), &mcti->mem); add_memory_range(&((struct AtomicT_intImpl_int*)fork4->atomicT_int)->atomic, sizeof(int), &mcti->mem); mcti->statefunc = mcDPP; #if 1 Phils* phils0 = createPhilsImpl(context,0,fork0,fork1); // phils0 Phils* phils1 = createPhilsImpl(context,1,fork1,fork2); // phils1 Phils* phils2 = createPhilsImpl(context,2,fork2,fork3); // phils2 Phils* phils3 = createPhilsImpl(context,3,fork3,fork4); // phils3 Phils* phils4 = createPhilsImpl(context,4,fork4,fork0); // phils4 #else Phils* phils0 = createPhilsImpl(context,0,fork0,fork1); // phils0 Phils* phils1 = createPhilsImpl(context,1,fork1,fork2); // phils1 Phils* phils2 = createPhilsImpl(context,2,fork2,fork0); // phils2 #endif par goto phils0->thinking(exit_code); par goto phils1->thinking(exit_code); par goto phils2->thinking(exit_code); #if 1 par goto phils3->thinking(exit_code); par goto phils4->thinking(exit_code); #endif goto code2(); } __code code2(struct TaskManager* taskManager) { goto taskManager->shutdown(exit_code); } __code code2_stub(struct Context* contextt) { goto code2(contextt, &Gearef(contextt, TaskManager)->taskManager->TaskManager); } void init(int argc, char** argv) { for (int i = 1; argv[i]; ++i) { if (strcmp(argv[i], "-cpu") == 0) cpu_num = (int)atoi(argv[i+1]); else if (strcmp(argv[i], "-cuda") == 0) { gpu_num = 1; CPU_CUDA = 0; } } } int main(int argc, char** argv) { init(argc, argv); goto initDataGears(); }