reduction

How to implement argmax with OpenMP?

余生长醉 提交于 2019-12-08 19:17:31
I am trying to implement a argmax with OpenMP. If short, I have a function that computes a floating point value: double toOptimize(int val); I can get the integer maximizing the value with: double best = 0; #pragma omp parallel for reduction(max: best) for(int i = 2 ; i < MAX ; ++i) { double v = toOptimize(i); if(v > best) best = v; } Now, how can I get the value i corresponding to the maximum? Edit: I am trying this, but would like to make sure it is valid: double best_value = 0; int best_arg = 0; #pragma omp parallel { double local_best = 0; int ba = 0; #pragma omp for reduction(max: best

Sequence reduction in R

最后都变了- 提交于 2019-12-07 07:30:53
问题 Assume you have a vector like so: v <- c(1,1,1,2,2,2,2,1,1,3,3,3,3) How can it be best reduced to a data.frame like this? v.df <- data.frame(value=c(1,2,1,3),repetitions=c(3,4,2,4)) In a procedural language I might just iterate through a loop and build the data.frame as I go, but with a large dataset in R such an approach is inefficient. Any advice? 回答1: or more simply data.frame(rle(v)[]) 回答2: with(rle(v), data.frame(values, lengths)) should get you what you need. values lengths 1 3 2 4 1 2

Finding max value in CUDA

不打扰是莪最后的温柔 提交于 2019-12-06 02:16:25
I am trying to write a code in CUDA for finding the max value for the given set of numbers. Assume you have 20 numbers, and the kernel is running on 2 blocks of 5 threads. Now assume the 10 threads compare the first 10 values at the same time, and thread 2 finds a max value, so thread 2 is updating the max value variable in global memory. While thread 2 is updating, what will happen to the remaining threads (1,3-10) that will be comparing using the old value? If I lock the global variable using atomicCAS(), will the threads (1,3-10) compare using the old max value? How can I overcome this

Sequence reduction in R

ⅰ亾dé卋堺 提交于 2019-12-05 15:12:05
Assume you have a vector like so: v <- c(1,1,1,2,2,2,2,1,1,3,3,3,3) How can it be best reduced to a data.frame like this? v.df <- data.frame(value=c(1,2,1,3),repetitions=c(3,4,2,4)) In a procedural language I might just iterate through a loop and build the data.frame as I go, but with a large dataset in R such an approach is inefficient. Any advice? or more simply data.frame(rle(v)[]) with(rle(v), data.frame(values, lengths)) should get you what you need. values lengths 1 3 2 4 1 2 3 4 来源: https://stackoverflow.com/questions/3010790/sequence-reduction-in-r

Call by value in the lambda calculus

ぐ巨炮叔叔 提交于 2019-12-05 13:05:44
问题 I'm working my way through Types and Programming Languages, and Pierce, for the call by value reduction strategy, gives the example of the term id (id (λz. id z)) . The inner redex id (λz. id z) is reduced to λz. id z first, giving id (λz. id z) as the result of the first reduction, before the outer redex is reduced to the normal form λz. id z . But call by value order is defined as 'only outermost redexes are reduced', and 'a redex is reduced only when its right-hand side has already been

Block reduction in CUDA

岁酱吖の 提交于 2019-12-05 01:18:33
I am trying to do reduction in CUDA and I am really a newbie. I am currently studying a sample code from NVIDIA. I guess I am really not sure how to set up the block size and grid size, especially when my input array is larger ( 512 X 512 ) than a single block size. Here is the code. template <unsigned int blockSize> __global__ void reduce6(int *g_idata, int *g_odata, unsigned int n) { extern __shared__ int sdata[]; unsigned int tid = threadIdx.x; unsigned int i = blockIdx.x*(blockSize*2) + tid; unsigned int gridSize = blockSize*2*gridDim.x; sdata[tid] = 0; while (i < n) { sdata[tid] += g

Java convert hash to random string

自作多情 提交于 2019-12-04 06:48:59
I'm trying to develop a reduction function for use within a rainbow table generator. The basic principle behind a reduction function is that it takes in a hash, performs some calculations, and returns a string of a certain length. At the moment I'm using SHA1 hashes, and I need to return a string with a length of three. I need the string to be made up on any three random characters from: abcdefghijklmnopqrstuvwxyz0123456789 The major problem I'm facing is that any reduction function I write, always returns strings that have already been generated. And a good reduction function will only return

Why is a built-in function applied to too few arguments considered to be in weak head normal form?

会有一股神秘感。 提交于 2019-12-04 02:50:27
问题 The Haskell definition says: An expression is in weak head normal form (WHNF), if it is either: a constructor (eventually applied to arguments) like True, Just (square 42) or (:) 1 a built-in function applied to too few arguments (perhaps none) like (+) 2 or sqrt. or a lambda abstraction \x -> expression. Why do built-in functions receive special treatment? According to lambda calculus, there is no difference between a partially applied function and any other function, because at the end we

CUDA - why is warp based parallel reduction slower?

情到浓时终转凉″ 提交于 2019-12-03 12:15:06
I had the idea about a warp based parallel reduction since all threads of a warp are in sync by definition. So the idea was that the input data can be reduced by factor 64 (each thread reduces two elements) without any synchronization need. Same as the original implementation by Mark Harris the reduction is applied on block-level and data is on shared memory. http://gpgpu.org/static/sc2007/SC07_CUDA_5_Optimization_Harris.pdf I created a kernel to test his version and my warp based version. The kernel itself is completely identically storing BLOCK_SIZE elements in shared memory and outputting

bison's reduction didn't work as expected

邮差的信 提交于 2019-12-02 16:50:28
问题 I'm trying to write a EPL parser,so I'm learning flex and bison.I try using it with following rules(SQL): SELECT { cout<<"SELECT detected"<<endl;return SELECT; } FROM { cout<<"FROM detected"<<endl;return FROM;} [a-zA-Z][0-9a-zA-Z]* { cout<<"IDENTIFIER detected"<<endl;yylval.c=yytext; return IDENTIFIER; } '$' { return DOL;} [ \t] { cout<<"space founded:"<<int(yytext[0])<<endl; } \n { return EOL;} . {} and bison rules are: sel_stmt : {cout<<"VOID"<<endl;} | SELECT identifier_expr FROM