Mercurial > hg > Members > Moririn
changeset 379:2744cb933ebc
Fix compile error for bitonicSort but not work
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 23 Jul 2017 07:01:14 +0900 |
parents | 9049c19036fd |
children | 783017f6dfbe |
files | src/parallel_execution/CMakeLists.txt src/parallel_execution/context.h src/parallel_execution/examples/bitonicSort.cbc src/parallel_execution/examples/swap.cbc src/parallel_execution/test/oneDimIterator_test.cbc |
diffstat | 5 files changed, 136 insertions(+), 86 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/CMakeLists.txt Wed Jul 19 23:02:25 2017 +0900 +++ b/src/parallel_execution/CMakeLists.txt Sun Jul 23 07:01:14 2017 +0900 @@ -6,7 +6,6 @@ set(CMAKE_C_COMPILER $ENV{CBC_COMPILER}) add_definitions("-Wall -g") -set(CMAKE_C_FLAGS "-lpthread") if (${USE_CUDA}) @@ -52,6 +51,7 @@ COMMAND "perl" "generate_context.pl" "-o" ${_Gears_TARGET} ${_Gears_CSOURCES} ) add_executable(${_Gears_TARGET} ${_Gears_CSOURCES} c/${_Gears_TARGET}-context.c) + target_link_libraries(${_Gears_TARGET} m pthread) endmacro() @@ -71,9 +71,9 @@ GearsCommand( TARGET - bitonic_sort + bitonicSort SOURCES - examples/bitonicSort.cbc examples/swap.cbc examples/InitIntegerDataGears.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc OneDimIterator.cbc TimeImpl.cbc + examples/bitonicSort.cbc examples/swap.cbc CPUWorker.cbc TaskManagerImpl.cbc SingleLinkedQueue.cbc SynchronizedQueue.cbc OneDimIterator.cbc TimeImpl.cbc ) if (${USE_CUDA})
--- a/src/parallel_execution/context.h Wed Jul 19 23:02:25 2017 +0900 +++ b/src/parallel_execution/context.h Sun Jul 23 07:01:14 2017 +0900 @@ -234,10 +234,10 @@ struct Element* next; } Element; struct Array { - int size; - int index; - int prefix; - int* array; + union Data* Array; + union Data* data; + enum Code get; + enum Code set; } Array; struct Tree { union Data* tree; @@ -295,9 +295,9 @@ struct SortArray {//そもそもこれは必要なのか? struct SortArray *sortArray; struct Integer **array;//Array arrayじゃできない? - int loop_counter; - int loop_counter2; - int loop_counter3; + int loopCounter; + int loopCounter2; + int loopCounter3; int sort_finish; enum Code make_array; enum Code print;
--- a/src/parallel_execution/examples/bitonicSort.cbc Wed Jul 19 23:02:25 2017 +0900 +++ b/src/parallel_execution/examples/bitonicSort.cbc Sun Jul 23 07:01:14 2017 +0900 @@ -2,6 +2,7 @@ #include <string.h> #include <stdlib.h> #include <unistd.h> +#include <math.h> #include "../../context.h" @@ -69,77 +70,79 @@ goto meta(context, time->time->Time.start); } -//__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { -// int waitFlag = 0; -// struct SortArray* inputSortArray = &ALLOCATE_DATA_GEAR(context, sortArray)->sortArray; -// inputSortArray->array = array; -// for (int i=2; i <= length; i=2*i) { -// int first = 1; -// lastOne = (length <= i*2) ? true : false; -// for (int j=i>>1; 0 < j; j=j>>1) { -// struct SortArray* outputSortArray = &ALLOCATE_DATA_GEAR(context, sortArray)->sortArray; -// outputSortArray->array = array; -// for(int k=0; 0 < length/2; k++) { -// struct Context* task = NEW(struct Context); -// struct Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; -// struct Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; -// struct Integer* integer3 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; -// integer1->value = j; -// integer2->value = first; -// integer3->value = k; -// -// task->next = C_swap; -// if (waitFlag) { -// task->idgCount = length/2; -// } else { -// task->idgCount = 0; -// } -// task->idg = task->dataNum; -// task->data[task->idg] = (union Data*)inputSortArray; -// task->data[task->idg+1] = (union Data*)integer1; -// task->data[task->idg+2] = (union Data*)integer2; -// task->data[task->idg+3] = (union Data*)integer3; -// task->maxIdg = task->idg + 4; -// task->odg = task->maxIdg; -// task->data[task->odg] = outputSortArray; -// task->maxOdg = task->odg + 1; -// first = 0; -// } -// inputSortArray = outputSortArray; -// } -// waitFlag = 1; -// } -// goto meta(context, taskManager->taskManager->TaskManager.shutdown); -//} +__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { + int logN = (int)log2((float)length); + struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, logN*(1+logN)/2 + 2); + int taskCount = 0; -__code createTask1(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Time* time) { - int i = loopCounter->i; - - if (i < length) { - loopCounter->i++; - goto meta(context, C_createTask2); - } + struct SortArray* outputSortArray = &ALLOCATE_DATA_GEAR(context, SortArray)->SortArray; + struct SortArray* inputSortArray = outputSortArray; - loopCounter->i = 0; - taskManager->next = C_exit_code; - goto meta(context, taskManager->taskManager->TaskManager.shutdown); -} - -__code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { - struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, 1); + // par goto makeArray(outputSortArray, _exit); struct Context* task = NEW(struct Context); initContext(task); - task->iterator = createOneDimIterator(context, 10); - task->next = C_printIterator; + task->next = C_makeArray; task->idgCount = 0; task->idg = task->dataNum; task->maxIdg = task->idg; task->odg = task->maxIdg; + task->data[task->odg] = (union Data*)outputSortArray; + task->maxOdg = task->odg + 1; + tasks[taskCount] = task; + + taskCount++; + for (int i=2; i <= length; i=2*i) { + int first = 1; + for (int j=i>>1; j > 0; j=j>>1) { + outputSortArray = &ALLOCATE_DATA_GEAR(context, SortArray)->SortArray; + struct Context* task = NEW(struct Context); + initContext(task); + struct Integer* integer1 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; + struct Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; + integer1->value = j; + integer2->value = first; + + task->next = C_bitonicSwap; + task->iterator = createOneDimIterator(context, length/2); + task->idgCount = 1; + task->idg = task->dataNum; + task->data[task->idg] = (union Data*)inputSortArray; + task->data[task->idg+1] = (union Data*)integer1; + task->data[task->idg+2] = (union Data*)integer2; + task->maxIdg = task->idg + 3; + task->odg = task->maxIdg; + task->data[task->odg] = (union Data*)outputSortArray; + task->maxOdg = task->odg + 1; + tasks[taskCount] = task; + taskCount++; + first = 0; + inputSortArray = outputSortArray; + } + } + + // par goto printArray(inputSortArray, __exit) + task = NEW(struct Context); + initContext(task); + task->next = C_printArray; + task->idgCount = 1; + task->idg = task->dataNum; + task->data[task->idg] = (union Data*)inputSortArray; + task->maxIdg = task->idg + 1; + task->odg = task->maxIdg; task->maxOdg = task->odg; - tasks[0] = task; + tasks[taskCount] = task; + taskManager->contexts = tasks; - taskManager->next1 = C_createTask1; + // goto code2(); + taskManager->next1 = C_code2; goto meta(context, taskManager->taskManager->TaskManager.spawnTasks); + //goto meta(context, taskManager->taskManager->TaskManager.shutdown); +} + +__code code2(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Time* time) { + sleep(2); + taskManager->next = C_exit_code; + goto meta(context, taskManager->taskManager->TaskManager.shutdown); } void init(int argc, char** argv) { @@ -163,3 +166,45 @@ goto start_code(main_context); } + +__code makeArray(__code next(struct SortArray* output, ...)){ + struct SortArray* output = *O_output; + if (output->loopCounter == 0){ + output->array = (Integer**)ALLOC_ARRAY(context, Integer, length); + srand((unsigned) time(NULL)); + } + if (output->loopCounter == GET_SIZE(output->array)){ + output->loopCounter = 0; + goto meta(context, next); + } + struct Integer* integer = new Integer(); + integer->value = rand() % 1000; + output->array[output->loopCounter] = integer; + printf("%d\n", output->array[output->loopCounter]->value); + output->loopCounter++; + *O_output = output; + goto meta(context, C_makeArray); +} + +__code makeArray_stub(struct Context* context) { + SortArray** O_output = (struct SortArray **)&context->data[context->odg]; + goto makeArray(context, + context->next, + O_output); +} + +__code printArray(struct SortArray* inputArray, __code next(...)){ + if (inputArray->loopCounter == GET_SIZE(inputArray->array)){ + inputArray->loopCounter = 0; + goto meta(context, next); + } + printf("%d\n", inputArray->array[inputArray->loopCounter]->value); + inputArray->loopCounter++; + goto meta(context, C_printArray); +} + +__code printArray_stub(struct Context* context) { + goto printArray(context, + &context->data[context->idg]->SortArray, + context->next); +}
--- a/src/parallel_execution/examples/swap.cbc Wed Jul 19 23:02:25 2017 +0900 +++ b/src/parallel_execution/examples/swap.cbc Sun Jul 23 07:01:14 2017 +0900 @@ -1,29 +1,31 @@ #include "../../context.h" #include <stdio.h> -__code swap(struct SortArray sortArray, struct Integer* block, struct Integer* first, struct Integer* i, __code next(struct SortArray* output, ...)) { +__code bitonicSwap(struct SortArray* inputArray, struct Integer* block, struct Integer* first, struct Integer* i, __code next(struct SortArray* output, ...)) { + struct SortArray* output = *O_output; int position = i->value/block->value; int index = i->value+block->value*position; - block->value = (first->value == 1)? ((block->value<<1)*(position+1))-(index%block->value)-1 : index+block->value; - - if (sortArray->array[block] < sortArray->array[index]) { - int Integer *tmp = sortArray->array[index]; - sortArray->array[index] = sortArray->array[block]; - sortArray->array[block] = tmp; + struct Integer** array = inputArray->array; + printf("block:%d\n", block->value); + printf("index:%d\n", index); + if (array[block->value] < array[index]) { + struct Integer *tmp = array[index]; + array[index] = array[block->value]; + array[block->value] = tmp; } - + output->array = array; *O_output = output; goto meta(context, next); } -__code swap_stub(struct Context* context) { +__code bitonicSwap_stub(struct Context* context) { SortArray** O_output = (struct SortArray **)&context->data[context->odg]; - goto swap(context, - &context->data[context->idg]->SortArray, - &context->data[context->idg+1]->Integer, - &context->data[context->idg+2]->Integer, - &context->data[context->idg+3]->Integer, - context->next, - O_output); + goto bitonicSwap(context, + &context->data[context->idg]->SortArray, + &context->data[context->idg+1]->Integer, + &context->data[context->idg+2]->Integer, + &context->data[context->idg+3]->Integer, + context->next, + O_output); }
--- a/src/parallel_execution/test/oneDimIterator_test.cbc Wed Jul 19 23:02:25 2017 +0900 +++ b/src/parallel_execution/test/oneDimIterator_test.cbc Sun Jul 23 07:01:14 2017 +0900 @@ -84,6 +84,8 @@ __code createTask2(struct LoopCounter* loopCounter, struct TaskManager* taskManager) { struct Context** tasks = (struct Context**)ALLOC_ARRAY(context, Context, 1); + + // par goto printIterator(iterate(10)) struct Context* task = NEW(struct Context); initContext(task); task->iterate = 0; @@ -94,6 +96,7 @@ task->maxIdg = task->idg; task->odg = task->maxIdg; task->maxOdg = task->odg; + tasks[0] = task; taskManager->contexts = tasks; taskManager->next1 = C_createTask1;