Mercurial > hg > GearsTemplate
changeset 383:300c18700ca5
Add split to bitonicSort
author | Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 25 Jul 2017 04:52:18 +0900 |
parents | f1d111e293c4 |
children | ee5d2b1685d7 |
files | src/parallel_execution/context.h src/parallel_execution/examples/bitonicSort/bitonicSort.cbc src/parallel_execution/examples/bitonicSort/swap.cbc src/parallel_execution/generate_stub.pl |
diffstat | 4 files changed, 35 insertions(+), 104 deletions(-) [+] |
line wrap: on
line diff
--- a/src/parallel_execution/context.h Mon Jul 24 20:05:08 2017 +0900 +++ b/src/parallel_execution/context.h Tue Jul 25 04:52:18 2017 +0900 @@ -299,6 +299,7 @@ int loopCounter2; int loopCounter3; int sort_finish; + int prefix; enum Code make_array; enum Code print; enum Code bitonic_sort;
--- a/src/parallel_execution/examples/bitonicSort/bitonicSort.cbc Mon Jul 24 20:05:08 2017 +0900 +++ b/src/parallel_execution/examples/bitonicSort/bitonicSort.cbc Tue Jul 25 04:52:18 2017 +0900 @@ -7,7 +7,8 @@ #include "../../../context.h" int cpu_num = 1; -int length = 100; +int length = 1024; +int split = 8; int gpu_num = 0; int CPU_ANY = -1; int CPU_CUDA = -1; @@ -59,6 +60,7 @@ printf("cpus:\t\t%d\n", cpu_num); printf("gpus:\t\t%d\n", gpu_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"); */ @@ -102,9 +104,9 @@ struct Integer* integer2 = &ALLOCATE_DATA_GEAR(context, Integer)->Integer; integer1->value = j; integer2->value = first; - + inputSortArray->prefix = length/2/split; task->next = C_bitonicSwap; - task->iterator = createOneDimIterator(context, length/2); + task->iterator = createOneDimIterator(context, split); task->idgCount = 1; task->idg = task->dataNum; task->data[task->idg] = (union Data*)inputSortArray; @@ -143,7 +145,7 @@ } __code code2(struct LoopCounter* loopCounter, struct TaskManager* taskManager, struct Time* time) { - sleep(30); + sleep(40); taskManager->next = C_exit_code; goto meta(context, taskManager->taskManager->TaskManager.shutdown); } @@ -154,6 +156,8 @@ 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]); else if (strcmp(argv[i], "-cuda") == 0) { gpu_num = 1; CPU_CUDA = 0; @@ -221,12 +225,16 @@ } __code printArray1(struct SortArray* inputArray, __code next(...)){ + //printf("%d\n", inputArray->array[inputArray->loopCounter]->value); + inputArray->loopCounter++; if (inputArray->loopCounter == GET_SIZE(inputArray->array)){ inputArray->loopCounter = 0; goto meta(context, next); } - //printf("%d\n", inputArray->array[inputArray->loopCounter]->value); - inputArray->loopCounter++; + if (inputArray->array[inputArray->loopCounter-1]->value > inputArray->array[inputArray->loopCounter]->value) { + printf("wrong result\n"); + goto meta(context, next); + } goto meta(context, C_printArray1); }
--- a/src/parallel_execution/examples/bitonicSort/swap.cbc Mon Jul 24 20:05:08 2017 +0900 +++ b/src/parallel_execution/examples/bitonicSort/swap.cbc Tue Jul 25 04:52:18 2017 +0900 @@ -1,18 +1,24 @@ #include "../../../context.h" #include <stdio.h> -__code bitonicSwap(struct SortArray* inputArray, 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, struct LoopCounter* loopCounter, __code next(struct SortArray* output, ...)) { struct SortArray* output = *O_output; - int position = i->value/block->value; - int index1 = i->value+block->value*position; - int index2 = (first->value == 1)? ((block->value<<1)*(position+1))-(index1%block->value)-1 : index1+block->value; - struct Integer** array = inputArray->array; - if (array[index2]->value < array[index1]->value) { - struct Integer *tmp = array[index1]; - array[index1] = array[index2]; - array[index2] = tmp; + if (loopCounter->i < inputArray->prefix) { + int index = loopCounter->i + i->value * inputArray->prefix; + int position = index/block->value; + int index1 = index+block->value*position; + int index2 = (first->value == 1)? ((block->value<<1)*(position+1))-(index1%block->value)-1 : index1+block->value; + struct Integer** array = inputArray->array; + if (array[index2]->value < array[index1]->value) { + struct Integer *tmp = array[index1]; + array[index1] = array[index2]; + array[index2] = tmp; + } + loopCounter->i++; + goto meta(context, C_bitonicSwap); } - output->array = array; + loopCounter->i = 0; + output->array = inputArray->array; *O_output = output; goto meta(context, next); } @@ -24,6 +30,7 @@ &context->data[context->idg+1]->Integer, &context->data[context->idg+2]->Integer, &context->data[context->idg+3]->Integer, + Gearef(context, LoopCounter), context->next, O_output); }
--- a/src/parallel_execution/generate_stub.pl Mon Jul 24 20:05:08 2017 +0900 +++ b/src/parallel_execution/generate_stub.pl Tue Jul 25 04:52:18 2017 +0900 @@ -38,59 +38,21 @@ my %outputArgs; # continuation's output variables my %dataGear; my %dataGearName; -my %generic; -my %dataGearVarType; my $implementation; my $interface; -# interface definision -# -# typedef struct Stack<Type, Impl>{ -# Type* stack; -# Type* data; -# Type* data1; -# __code whenEmpty(...); -# __code clear(Impl* stack,__code next(...)); -# __code push(Impl* stack,Type* data, __code next(...)); -# __code pop(Impl* stack, __code next(Type*, ...)); -# __code pop2(Impl* stack, Type** data, Type** data1, __code next(Type**, Type**, ...)); -# __code isEmpty(Impl* stack, __code next(...), __code whenEmpty(...)); -# __code get(Impl* stack, Type** data, __code next(...)); -# __code get2(Impl* stack,..., __code next(...)); -# __code next(...); -# } Stack; -# -# calling example -# -# goto nodeStack->push((union Data*)node, stackTest3); -# -# generated meta level code -# -# Gearef(context, Stack)->stack = nodeStack->stack; -# Gearef(context, Stack)->data = (union Data*)node; -# Gearef(context, Stack)->next = C_stackTest3; -# goto meta(context, nodeStack->push); - sub getDataGear { my ($filename) = @_; my ($codeGearName, $name, $inTypedef); open my $fd,"<",$filename or die("can't open $filename $!"); while (<$fd>) { if (! $inTypedef) { - if (/^typedef struct (\w+)\s*<(.*)>/) { + if (/^typedef struct (\w+)/) { $inTypedef = 1; $name = $1; $dataGear{$name} = $_; $var{$name} = {}; $code{$name} = {}; - $generic{$name} = \split(/,/,$2); - } elsif (/^typedef struct (\w+)/) { - $inTypedef = 1; - $name = $1; - $dataGear{$name} = $_; - $var{$name} = {}; - $code{$name} = {}; - $generic{$name} = []; } elsif (/^(\w+)(\*)+ create(\w+)\(/) { if (defined $interface) { die "duplicate interface $interface\n"; @@ -112,29 +74,8 @@ $ttype = $2; } $var{$name}->{$tname} = $ttype; - } elsif (/^\_\_code (\w+)\((.*)\)(.*)/) { - my $args = $2; - my $method = $1; - $code{$name}->{$method} = []; - while($args) { - if ($args =~ s/(^\s*,\s*)//) { - } - # continuation case - if ($args =~ s/^(\s)*\_\_code\s+(\w+)\(([^)]*)\)//) { - my $next = $2; - my @args = split(/,/,$3); - push(@{$code{$name}->{$method}},$next); - } elsif ($args =~ s/^(struct|union) (\w+)(\*)+\s(\w+)//) { - my $structType = $1; - my $typeName = $2; - my $varName = $4; - my $typeField = lcfirst($typeName); - push(@{$code{$name}->{$method}},$varName); - } elsif ($args =~ s/(.*,)//) { - } else { - last; - } - } + } elsif (/\_\_code (\w+)\(/) { + $code{$name}->{$1} = 1; } if (/^}/) { $inTypedef = 0; @@ -158,7 +99,6 @@ return 0 if ( $n eq $varname1); } push @{$dataGearVar{$codeGearName}}, $varname1; - push @{$dataGearVarType{$codeGearName}}, $typeName; if ($typeName eq $implementation) { # get implementation $dataGearName{$codeGearName} .= "\t$typeName* $varName = ($typeName*)GearImpl(context, $interface, $varName);\n"; @@ -313,31 +253,6 @@ print $fd $outputVar{$codeGearName}; } next; - } elsif (/^(.*)goto (\w+)\-\>(\w+)\((.*)\);/) { - # handling goto statement - # convert it to the meta call form with two arugments, that is context and enum Code - my $prev = $1; - my $next = $2; - my $method = $3; - my @args = split(/,/,$4); - my @types = @{$dataGearVarType{$codeGearName}}; - my $ntype; - for my $v (@{$dataGearVar{$codeGearName}}) { - my $t = shift @types; - if ($v eq $next) { - $ntype = $t; - } - } - print $fd "\tGearef(context, $ntype)->$next = $next->$next;\n"; - # Put interface argument - my $prot = $code{$ntype}->{$method}; - for my $arg (@args) { - my $p = shift @$prot; - next if ($p eq $arg); - print $fd "\tGearef(context, $ntype)->$p = $arg;\n"; - } - print $fd "${prev}goto meta(context, $next->$next->$ntype.$method);\n"; - next; } elsif (/^(.*)goto (\w+)\((.*)\);/) { # handling goto statement # convert it to the meta call form with two arugments, that is context and enum Code