Mercurial > hg > GearsTemplate
view src/parallel_execution/main.cbc @ 289:3d70e21a3902
Delete createData
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 06 Feb 2017 11:09:53 +0900 |
parents | f1b0cc555b6e |
children | 8c2123bb577b |
line wrap: on
line source
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "../context.h" int cpu_num = 1; int length = 102400; int split = 8; int* array_ptr; void print_queue(struct Element* element) { while (element) { printf("%p\n", ((struct Task *)(element->data))); element = element->next; } } void print_tree(struct Node* node) { if (node != 0) { printf("%d\n", node->value->Array.index); print_tree(node->left); print_tree(node->right); } } __code initDataGears(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { loopCounter->tree = createRedBlackTree(context); loopCounter->i = 0; taskManager->taskManager = (union Data*)createTaskManagerImpl(context, cpu_num, 0, 0); goto meta(context, C_createTask1); } __code initDataGears_stub(struct Context* context) { goto initDataGears(context, Gearef(context, LoopCounter), Gearef(context, TaskManager)); } __code code1(struct Time* time) { printf("cpus:\t\t%d\n", cpu_num); printf("length:\t\t%d\n", length); printf("length/task:\t%d\n", length/split); /* 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_code2); //goto meta(context, C_exit_code); //goto meta(context, C_start_time); } __code code1_stub(struct Context* context) { goto code1(context, Gearef(context, Time)); } __code code2(struct LoopCounter* loopCounter) { int i = loopCounter->i; if (i < length) { //printf("%d\n", array_ptr[i]); if (array_ptr[i] == (i*2)) { loopCounter->i++; goto meta(context, C_code2); } else puts("wrong result"); } goto meta(context, C_exit_code); } __code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { int i = loopCounter->i; if ((length/split*i) < length) { taskManager->next = C_createTask2; goto meta(context, taskManager->taskManager->TaskManager.createTask); } loopCounter->i = 0; taskManager->next = C_code1; goto meta(context, taskManager->taskManager->TaskManager.shutdown); } __code createTask2(LoopCounter* loopCounter, TaskManager* taskManager,struct Context* task, LoopCounter* loopCounter2, Array* array) { int i = loopCounter->i; array->index = i; array->prefix = length/split; array->array = array_ptr; loopCounter2->i = 0; task->idgCount = 0; task->next = C_twice; task->data[task->dataNum] = (union Data*)loopCounter2; task->data[task->dataNum+1] = (union Data*)array; task->odg = task->dataNum + 2; task->maxOdg = task->odg; taskManager->next = C_createTask1; loopCounter->i++; goto meta(context, taskManager->taskManager->TaskManager.spawn); } __code createTask2_stub(struct Context* context) { LoopCounter* loopCounter = &ALLOCATE(context, LoopCounter)->LoopCounter; Array* array = &ALLOCATE(context, Array)->Array; goto createTask2(context, Gearef(context, LoopCounter), Gearef(context, TaskManager), Gearef(context, TaskManager)->context, loopCounter, array); } 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], "-s") == 0) split = (int)atoi(argv[i+1]); } } int main(int argc, char** argv) { init(argc, argv); array_ptr = NEWN(length, int); for(int i=0; i<length; i++) array_ptr[i]=i; struct Context* main_context = NEW(struct Context); initContext(main_context); main_context->next = C_initDataGears; goto start_code(main_context); }