Mercurial > hg > Members > Moririn
view src/parallel_execution/examples/calc/calc.cbc @ 462:8d7e5d48cad3
Running CPU examples
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 20 Dec 2017 22:05:08 +0900 |
parents | d3d7a7d6a117 |
children | 831b7f6fd687 |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #include <assert.h> #include "../../../context.h" #include "TaskManager.h" int cpu_num = 1; int length = 100; int gpu_num = 0; int CPU_ANY = -1; int CPU_CUDA = -1; void *start_taskManager(struct Context *context) { goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager)); return 0; } __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { // loopCounter->tree = createRedBlackTree(context); loopCounter->i = 0; taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, gpu_num, 0); goto meta(context, C_code1); } __code initDataGears_stub(struct Context* context) { struct TaskManager* taskManager = Gearef(context, TaskManager); taskManager->taskManager = 0; struct LoopCounter* loopCounter = Gearef(context, LoopCounter); goto initDataGears(context, loopCounter, taskManager); } __code code1(struct Time* time) { printf("cpus:\t\t%d\n", cpu_num); printf("gpus:\t\t%d\n", gpu_num); printf("length:\t\t%d\n", length); /* puts("queue"); */ /* print_queue(context->data[ActiveQueue]->queue.first); */ /* puts("tree"); */ /* print_tree(context->data[Tree]->tree.root); */ /* puts("result"); */ //time->next = C_code2; goto meta(context, C_createTask1); //goto meta(context, C_start_time); } __code code1_stub(struct Context* context) { goto code1(context, Gearef(context, Time)); } __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { int i = loopCounter->i; if (i < length) { loopCounter->i++; goto meta(context, C_createTask2); } loopCounter->i = 0; taskManager->next = C_exit_code; goto taskManager->shutdown(exit_code); } __code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { Integer* integer1 = new Integer(); Integer* integer2 = new Integer(); Integer* integer3 = new Integer(); par goto mult(integer1, integer2, integer3, __exit); Integer* integer4 = new Integer(); Integer* integer5 = new Integer(); par goto add(integer4, integer5, integer1, __exit); par goto initIntegerDataGears(integer2, integer4, integer5, __exit); goto createTask1(); } 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], "-l") == 0) length = (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); struct Context* main_context = NEW(struct Context); initContext(main_context); main_context->next = C_initDataGears; goto start_code(main_context); }