When dividing a workload into fixed-size groups, ordinary integer division rounds down and can leave items uncovered. Ceiling division rounds up to the next whole group when there is a remainder. In CUDA C/C++, calculate the block count with (n + threadsPerBlock - 1) / threadsPerBlock. section 3.14 section 3.9
int numBlocks = (n + threadsPerBlock - 1) / threadsPerBlock; #A
Use this C/C++ expression to calculate the number of blocks. section 3.9
Covering an array
For 1,000 elements and 256 threads per block, the formula gives 4 blocks; plain division gives only 3, leaving 232 elements unprocessed. For 1,024 elements, it still gives 4 blocks. If n is 0, the formula gives 0 blocks, so skip the CUDA launch; CUDA rejects a zero-block launch. section 3.14 section 3.9

