Compact the nonzero elements of a float array, preserving order. Given input of length n, write the nonzeros into the front of output and write how many there were into count:
A sequential walk works on paper; this exercise is about the parallel pattern. Mark each element with a predicate, exclusive-scan those flags to get each survivor's destination index, then scatter. is a power of two and the whole array fits in one block (n <= 1024).
Complete:
__global__ kernel that flags, scans, and scatters.void solve(const float* input, float* output, int* count, int n) where every pointer is a host pointer. output has length n (only the first *count entries are defined). Allocate, copy in, launch, copy *count and the compacted prefix back, and free.Constraints: n is a power of two, 1 <= n <= 1024. Treat a value as zero only when it compares equal to 0.0f. Do not write a main() in your solution.