4

I need to perform some tensor products and contractions on some large arrays in Fortran. Sometimes they are vectors or matrices and sometimes some of the objects involved are 3-arrays or 4-arrays.

Of course, it is very easy to write a subroutine achieving this with some nested loops, and that's just what I've done. But I have to call this subroutine with all its loops a lot of times for very large arrays, and I was just wondering whether there is some optimized function or subroutine implemented in Fortran which I could benefit from.

7
  • 2
    Show your code. Commented Oct 18, 2016 at 9:57
  • 2
    Fortran excels at iterating over large, dense, regular arrays. And Fortran compilers excel at optimising the execution of such codes on whatever resources the CPU (etc) provides. Sometimes manual tiling helps, sometimes its more trouble than its worth. For such a general question as yours, no more than vague generalities such as mine can be provided. Commented Oct 18, 2016 at 10:01
  • 2
    Ok, thanks Mark. I don't believe my question is general. It is pretty specific. Given two arrays A and B, the tensor product of them both is a well-defined object, and I was asking whether there is a specific function in fortran, say, tensor( , ), such that tensor(A,B) is what I'm looking for. And, furthermore, I specified that I was asking so because I would expect such a function to be more efficient than the nested loops I'm using. It is a concrete question and showing such a trivial code in it wouldn't be of any use at all -It would just make the post longer. Commented Oct 18, 2016 at 10:14
  • 1
    It wouldn't, it would illustrate the post and it should really be there. As a rule of thumb, every post here should contain code. Commented Oct 18, 2016 at 10:18
  • 1
    Yes I agree this doesn't seem appropriate for so. Maybe migrate to scicomp.stackexchange.com? Commented Oct 18, 2016 at 13:09

1 Answer 1

3

Last time I looked (about a year ago) I did not find a high performance general purpose tensor product library in Fortran. I think one of the reason for this might be Fortran's cumbersome way of resizing arrays, which is a constant requirement when dealing with tensors.

If you only need multiplication you might be able to get away with using your own code. However if you need high performance, or more general operations, I would highly recommend writing a C interface and using one of the excellent C++ libraries out there, which are probably already optimized for your type of application:

Physics: http://itensor.org/

Machine learning: https://github.com/tensorflow/tensorflow

These are only examples. For a more complete listing see: Tensor multiplication library

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.