Group Abstract Group Abstract

Message Boards Message Boards

2
|
10.3K Views
|
7 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Transposing an integer matrix with LibraryLink

Posted 11 years ago
POSTED BY: Arnoud Buzing
7 Replies

This is a great post for educational purposes, but it should be pointed out that it is (very likely, I haven't tried) going to be significantly slower than the builtin Transpose.

The reason is that naive implementations of simple operations like transposition, array addition, etc. will not be as fast as an explicitly vectorized version. Writing it to take advantage of SIMD operations (like SSE) and considering cache effects should speed it up considerably. The builtin Transpose is certainly written this way.

The point I want to come to is that it would be great if LibraryLink provided access to some of these operations, in particular transposition. Mathematica stores matrices in row-major order (for very good reasons). Most other libraries use column-major order. If we want to transfer data between the two, it becomes necessary to transpose while copying. In a future version I would love to see a transpose-copy function for this purpose.

POSTED BY: Szabolcs Horvát
POSTED BY: Szabolcs Horvát

I did some benchmarks for this recently:

In short:

  • for an empty function call LibraryLink passing is ~5 times faster than MathLink passing.
  • for cycling a large array it's 25 times faster

Keep in mind that: these numbers are specific to the precise passing method I used and my own computer. Check the full post to see what it is precisely that was benchmarked. There are many variations on how this can be done.

POSTED BY: Szabolcs Horvát

I think so, but it's not something I personally have a lot of experience with (yet).

POSTED BY: Arnoud Buzing

I thought I had to use MathLink to do callbacks to Mathematica through LibraryLink. Is that correct?

POSTED BY: Frank Kampas

Both are equivalent in their end results. I would expect a little bit more communication overhead when using MathLink (WSTP), but I don't have any data in hand to back this claim up.

POSTED BY: Arnoud Buzing

I've used MathLink to send data back and forth across LibraryLink. What are the pros and cons of doing that?

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard