On cusparseXcsrgemm2Nnz function of cusparse

In page 110 of cusparse document, the following piece of code is provided.

int nnzC;
int *nnzTotalDevHostPtr = &nnzC;
......
cusparseXcsrgemm2Nnz(..., nnzTotalDevHostPtr, ...);
if (NULL != nnzTotalDevHostPtr){
  nnzC = *nnzTotalDevHostPtr;
} else {
  ......
}

where the declaration of cusparseXcsrgemm2Nnz is as follows:

cusparseStatus_t
cusparseXcsrgemm2Nnz(..., int* nnzTotalDevHostPtr, ...)

If I understand correctly, nnzTotalDevHostPtr points to nnzC in the host. Then why the if in the first piece of code? Isn’t nnzC = *nnzTotalDevHostPtr redundant?

Hi. Yes, it is right. The code shows both alternatives just for making it more general. Anyway, you can always control the pointer mode with cusparseSetPointerMode(handle, CUSPARSE_POINTER_MODE_HOST);