Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seg Fault when attempting broadcast. #158

Closed
hughack opened this issue Apr 27, 2022 · 1 comment
Closed

Seg Fault when attempting broadcast. #158

hughack opened this issue Apr 27, 2022 · 1 comment

Comments

@hughack
Copy link

hughack commented Apr 27, 2022

I am trying to add a vector to a matrix, and broadcast the addition across all vectors. I'd like something like this:

Tensor<double,3> vec = {1,2,3};      // a vector
Tensor<double,2,2,3> A(0);           // 3D tensor of all zeros 

A = A + vec

and get

[0,:,:]
[1, 2, 3]
[1, 2, 3]
[1,:,:]
[1, 2, 3]
[1, 2, 3]

I read #108 and saw you mention the only way to do it is with for loops, so i tried this as a naive implementation:

for(int i = 0; i < 2; i++)
    for(int j = 0; j < 2; j++)
        A(i, j, Fastor::all) = vec;

It works in this case. I wanted to see how it performed on a larger matrix, the task i'm trying to work on uses 1000x1000x3. When i run this:

#include <Fastor/Fastor.h>

int main() {
  Fastor::Tensor<double,3> vec = {1,2,3};
  Fastor::Tensor<double,1000,1000,3> A(0);

  for(int i = 0; i < 1000; i++)
    for(int j = 0; j < 1000; j++)
        A(i, j, Fastor::all) = vec;

  return 0;
}

I get a segmentation fault - am i doing it completely wrong or is there some issue going on? Do you have a recommended way of achieving this?

@romeric
Copy link
Owner

romeric commented Apr 28, 2022

This issue has been covered multiple times in the past. Fastor tensors are stack-allocated (not on heap) and your machine does not have that much stack memory. Fastor is not designed for that big of a tensors.

I would close this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants