2

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?

MvG
  • 57,380
  • 22
  • 148
  • 276
parallel
  • 303
  • 1
  • 3
  • 9
  • 2
    Line `6` of your example is `int id;` That wouldn't cause a type specifier error. Please post the exact code you're trying to compile. – japreiss Sep 13 '12 at 13:49

1 Answers1

2

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) {}
}
fork0
  • 3,401
  • 23
  • 23
  • 1
    @parallel - this is C++. class and struct data members can only be types, calling a constructor as part of a data declaration is illegal. – talonmies Sep 13 '12 at 15:17