I have noticed that multiple CPU's were not being used, each process is spawned 
and seems to wait till it's finished before the next one starts so that only on 
CPU is being used at once. Is there something I should check about my 
implementation to make sure that I'm not doing something obviously wrong? 
Matrix[F] is a ref object and is only read from so it should be fine. 
    
    
    proc subFor(j: int64, n: int64, K: AbstractKernel, data: Matrix[F], mat: 
Matrix[F]): void {.thread.} =
      for i in j..<n:
        var tmp: F = kernel(K, data.col(i), data.col(j));
        mat[i, j] = tmp;
        mat[j, i] = tmp;
      return;
    
    proc calculateKernelMatrix*(K: AbstractKernel, data: Matrix[F]): Matrix[F] =
      let n = int64(ncol(data));
      var mat = Matrix[F](data: newSeq[F](n*n), dim: @[n, n]);
      for j in 0..<n:
        spawn subFor(j, n, K, data, mat);
      sync();
      return mat;
    
    
    Run

Reply via email to