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

[RFC]: add blas/base/zswap #2047

Closed
3 tasks done
performant23 opened this issue Mar 26, 2024 · 6 comments · Fixed by #2075
Closed
3 tasks done

[RFC]: add blas/base/zswap #2047

performant23 opened this issue Mar 26, 2024 · 6 comments · Fixed by #2075
Assignees
Labels
Accepted RFC feature request which has been accepted. BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). C Issue involves or relates to C. difficulty: 3 Likely to be challenging but manageable. Fortran Issue involves or relates to Fortran. Native Addons Issue involves or relates to Node.js native add-ons. priority: High High priority concern or feature request. RFC Request for comments. Feature requests and proposed changes.

Comments

@performant23
Copy link
Contributor

Description

This RFC proposes adding the package @stdlib/blas/base/zswap for interchanging two complex double-precision floating-point vectors.

void c_zswap( const int N, void *X, const int strideX, void *Y, const int strideY )

Related Issues

Related issues: #2039

Questions

No.

Other

No.

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.
@performant23
Copy link
Contributor Author

Hi, just had a quick question: For double-precision floating point vectors, in my implementation I represented them as treating complex numbers as pairs of double values (using 2 double variables to store imaginary and real parts of complex number during a swap) but I also found out that there is a double_Complex data type which is a built-in C99 complex data type. If we use that, we'd just need one variable to store the complex number during the swap and the compiler will handle real and imaginary parts (with the restraint that it would work with compilers supporting C99 and above).

So, how should we be representing double-precision complex numbers?

cc @kgryte

@kgryte kgryte added RFC Request for comments. Feature requests and proposed changes. difficulty: 3 Likely to be challenging but manageable. Native Addons Issue involves or relates to Node.js native add-ons. Accepted RFC feature request which has been accepted. BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). priority: High High priority concern or feature request. Fortran Issue involves or relates to Fortran. C Issue involves or relates to C. labels Mar 26, 2024
@kgryte
Copy link
Member

kgryte commented Mar 26, 2024

Treat as pairs of real-valued double-precision floating-point numbers. No reason in this case to include an additional header file.

On a more general note, we don't directly use the built-in C99 complex dtypes in stdlib, but use our own C complex dtypes.

@performant23
Copy link
Contributor Author

Got it, thanks @kgryte! Also, are there any workarounds/guide for memory management using doubles. For example in benchmark/c, using something like:

double x[ len*2 ];
double y[ len*2 ];

resulted in stack overflow on testing:

c::zswap:len=100000
make[1]: *** [Makefile:116: run] Error -1073741571

since we're using len to determine size of x and y and that can go until 10^6 (also double here is consuming twice as more memory compared to float).

A solution I thought can work is allocation using heaps instead of stacks i.e.

double *x = (double *) malloc(len*2 * sizeof(double));
double *y = (double *) malloc(len*2 * sizeof(double));
.
.
.
free(x);
free(y);

@kgryte
Copy link
Member

kgryte commented Mar 26, 2024

@performant23 See #369 for a quick workaround. Yes, in the longer term, we need to refactor memory allocation of arrays. In the short term, try adjusting ulimit.

@kgryte
Copy link
Member

kgryte commented Mar 26, 2024

If that doesn't work, feel free to do manual memory allocation and freeing.

@performant23
Copy link
Contributor Author

performant23 commented Mar 26, 2024

Got it! Will do!

kgryte added a commit that referenced this issue Apr 3, 2024
PR-URL: 	#2075
Closes: #2047
Ref: #2039
Ref: https://netlib.org/lapack/explore-html-3.6.1/d2/df9/group__complex16__blas__level1_ga13a187010a0cae1fef2820072404e857.html#ga13a187010a0cae1fef2820072404e857
Co-authored-by: Athan Reines <kgryte@gmail.com>
Reviewed-by: Athan Reines <kgryte@gmail.com> 
Signed-off-by: Athan Reines <kgryte@gmail.com>
Co-authored-by: stdlib-bot <82920195+stdlib-bot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted RFC feature request which has been accepted. BLAS Issue or pull request related to Basic Linear Algebra Subprograms (BLAS). C Issue involves or relates to C. difficulty: 3 Likely to be challenging but manageable. Fortran Issue involves or relates to Fortran. Native Addons Issue involves or relates to Node.js native add-ons. priority: High High priority concern or feature request. RFC Request for comments. Feature requests and proposed changes.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants