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

Segmentation fault when using FOR loops on matrices #579

Closed
divjakm opened this issue Aug 2, 2023 · 7 comments
Closed

Segmentation fault when using FOR loops on matrices #579

divjakm opened this issue Aug 2, 2023 · 7 comments
Labels
bug A mistake in the code.

Comments

@divjakm
Copy link

divjakm commented Aug 2, 2023

Hello! I noticed I sometimes get a segmentation fault error when I use FOR loops for copying matrix data, but no error if I copy data using indexing.

The example code below works for N = 100 in both versions: with FOR loops (ver = 1) and indexing (ver = 2).
But for N = 1000 and ver = 1 I get a segmentation fault.
If I use ver = 2, then it works even for very large matrices.

// parameters:
ver = 1;	// concatenate version: 1-slow, 2-fast
N = 1000;	// matrix size

// create 2 matrices
Y1 = as.matrix<f64>(fill(100, N, 10));
Y2 = as.matrix<f64>(fill(200, N, 10));
nrowY1 = nrow (Y1);
ncolY1 = ncol (Y1);
nrowY2 = nrow (Y2);
ncolY2 = ncol (Y2);
print ("Y1 size: " + as.scalar(nrowY1) + " x " + as.scalar(ncolY1));
print ("Y2 size: " + as.scalar(nrowY2) + " x " + as.scalar(ncolY2));

// initialize matrix for concatenated signals
Y = as.matrix<f64> (fill (0, nrowY1+nrowY2, ncolY1));

// concatenate matrices Y1 and Y2
if (ver == 1)
{
  // concatenate 1: with FOR loops
  for (c in 0 : ncolY1 - 1)
  {
    for (r in 0 : nrowY1 - 1)
	Y[r,c] = Y1[r,c];
  }
  for (c in 0 : ncolY2 - 1)
  {
    for (r in 0 : nrowY2 - 1)
	Y[nrowY1+r,c] = Y2[r,c];
  }
}
else
{
  // concatenate 2: assign submatrix
  Y[0:nrowY1, 0:ncolY1] = Y1[,];
  Y[nrowY1:nrowY1+nrowY2, 0:ncolY2] = Y2[,];
}

nrowY = nrow (Y);
ncolY = ncol (Y);
print ("Y size: " + as.scalar(nrowY) + " x " + as.scalar(ncolY));
@aleszamuda
Copy link
Contributor

aleszamuda commented Aug 3, 2023 via email

@aleszamuda
Copy link
Contributor

aleszamuda commented Aug 3, 2023 via email

@corepointer
Copy link
Collaborator

Hi!

Off the top of my head, I'd say this could be related to (or be the same as) issue #77.

Regards, Mark

@corepointer corepointer added the bug A mistake in the code. label Aug 3, 2023
@divjakm
Copy link
Author

divjakm commented Aug 3, 2023

Hi! Thank you for a very quick answer. It does seem it could be related to issue #77. Unfortunately, I would like to loop for approx. 2.5 million times... :) I'll test a few other looping variants, hopefully I can find a workaround.

tomschw pushed a commit to tomschw/daphne that referenced this issue Aug 11, 2023
To sort the eigen vectors correctly according to the eigen values, a transpose was missing.
@philipportner
Copy link
Collaborator

Hi @divjakm , is this still an issue? I tried it on current main and it works on both versions. I suppose this was fixed with #820.

@divjakm
Copy link
Author

divjakm commented Sep 30, 2024

Hi! I tested this thoroughly and it works now. It seems it was fixed, so I'll close this issue. Thank you!

@divjakm
Copy link
Author

divjakm commented Sep 30, 2024

Closing...

@divjakm divjakm closed this as completed Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A mistake in the code.
Projects
None yet
Development

No branches or pull requests

4 participants