I want to get Minimum of Large Array. I tried to change 'Scan of Large Arrays of Sample Program.

The error message went out while calculating and neither [dete] nor the wanted answer went out voluminously though it tried to change part instead of buildSum, to make buildMin, and to use it because I wanted to put out minimum value and the maximum value of the array by using Scan of Large Arrays of SAMPLE PROGRAM of NVIDIA CUDA SDK. Please teach the method of correcting the mistake.

device unsigned int buildMin(float *s_data)
{
unsigned int thid = threadIdx.x;
unsigned int stride = 1;

// build the sum in place up the tree
for (int d = blockDim.x; d > 0; d >>= 1)
{
    __syncthreads();

    if (thid < d)      
    {
        int i  = __mul24(__mul24(2, stride), thid);
        int ai = i + stride - 1;
        int bi = ai + stride;

        ai += CONFLICT_FREE_OFFSET(ai);
        bi += CONFLICT_FREE_OFFSET(bi);
        
        if (s_data[bi]>s_data[ai]) {
	s_data[bi] = s_data[ai];
    }

// s_data[bi] += s_data[ai]; //<-----buildSum
}

    stride *= 2;
}

return stride;

}

execute message —> unsigned int result_regtest = cutComparef( reference, h_data, num_elements);
[Error Message]
:
:
ERROR, i = 9991, 44955 / 12 (reference / data)
ERROR, i = 9992, 44956 / 0 (reference / data)
ERROR, i = 9993, 44958 / 2 (reference / data)
ERROR, i = 9994, 44961 / 2 (reference / data)
ERROR, i = 9995, 44965 / 6 (reference / data)
:

I don’t quite understand the question, but since you only want the minimum of the array, and not all the intermediate results, you should look at the “reduction” sample in the SDK, not scan.

I’m sorry because the explanation of the object to be requested was not correct, it explains again.

For me to have wanted to request be to want to compare each element of a big array and to know the minimum value and the maximum value.

Try min_element & max_element in the Thrust library.

Alternatively, this example demonstrates how to find both with a single reduction.

Algorithm to find minimum element of array

  • We will declare variable minElement and minElementPosition and initialize it with first element of inputArray and 0 respectively.
  • We will start traversing inputArray from index 0 to N -1 and compare each element with minElement. If minElement is more than current element, we will update minElement and minElementPosition with current element and current position respectively.
  • At any instant of time suppose we are at index i, then minElement will give the minimum element between array index 0 to i.

http://www.techcrashcourse.com/2015/03/c-program-find-minimum-element-in-array.html
http://www.techcrashcourse.com/2015/11/c-program-find-maximum-minimum-element-of-array.html

@AkbarKhan: If I understand your response correctly, your response is finding max. or min. sequentially, not parallelly. The OP asks for a parallel method.

@LongY: AkbarKhan is just spamming these forums trying to drum up publicity for the techchrashcourse.com site. It’s probably better if you just ignore the posting. (S)He dug up a 7 year old question to respond to which is almost certainly not relevant to the thread OP anymore.

Probably best just to leave it alone, not give it any more publicity.