Search code examples
ccudasparse-matrixcusp-library

cusp sparse matrix to be used in struct in C


I am using the cusp library with CUDA to use sparse matrix. Can't I use it in a struct in C like:

  #include <cusp/coo_matrix.h>
  #include <cusp/multiply.h>
  #include <cusp/print.h>
  #include <cusp/transpose.h>
  struct Cat{
         int id;
         cusp::coo_matrix<int, double, cusp::host_memory> A(2,100,10);
  };
  int main(){
  }

I am getting the errors:

try.cu(7): error: expected a type specifier
try.cu(7): error: expected a type specifier
try.cu(7): error: expected a type specifier

What is the correct way to use it in a struct so that I can have array of such structures?


Solution

  • That piece of code coo_matrix looks suspiciously like a C++ template. If so, provide your Cat struct with constructor and initialize A there:

    struct Cat {
      int id;
      cusp::coo_matrix<int, double, cusp::host_memory> A;
      Cat(): id(0), A(2,100,10) {}
    }