0

I routinely have to debug legacy Fortran code that is utilizing large arrays of complex data, and the best option available is TotalView. I have created my own visualizer to view data (as per TotalView's instructions here) that works well. It is more flexible than the default one and has the ability to ingest and display complex data, but TotalView will not send complex arrays through its visualization pipe.

Is there any way to make TotalView be able to display complex data without having to recompile the code with additional debugging arrays just to take the absolute value?

E.g. for code like the following short example, I could make another array in Fortran, but I'd really like to just stop and examine the variable my_arr:

program main

implicit none

integer N,  M, i, j
parameter (N=100, M=30)
complex my_arr(N, M)
real pi

pi = ACOS(-1.0)

do j = 1, M
    do i = 1, N
        my_arr(i,j) = cmplx(i*cos(j/pi), i*sin(j/pi))
    end do
end do

return

end

For small arrays I can get away with something like this as an expression:

my_arr%Real_Part**2 + my_arr%Imaginary_Part**2

but that won't work for anything very large, TotalView complains about the memory.

I'm using TotalView 8.13.

Ajean
  • 5,528
  • 14
  • 46
  • 69

1 Answers1

0

You can do this if your array is contiguous in memory and you can adjust your visualizer to input the complex data as a real array with an extra dimension containing the real and imaginary parts.

In your example above, if you 'dive' into the variable my_arr, it will show up as type

COMPLEX(4)(100,30)

This is actually the same as the TotalView built-in $complex_8. You can recast the type and dimensions by simply retyping the following into the "Type:" field:

$real_4(2,100,30)

Then the real and imaginary parts will reside in the first (fastest-iterating) dimension and TotalView will allow you to pass the 3D float array to the visualizer. Note: by default TotalView restricts itself to visualizing 2D arrays, so you'll need to change that to 3D (or however many your visualizer can handle) under "Preferences->Launch Strings" in the "Enable Visualizer Launch" box under "Maximum array rank."

Allocatable arrays:

Dynamically sized arrays can be handled in the same way, but require a couple extra steps.

  1. Usually the address of the reference to the array is not the address of the actual array in memory, so you will have to manually adjust the address of the dive window.

    In the dive window on the right side there is an option button just above the scroll bar to indicate what columns are shown in the window - turn on "Address" and write down the hex address of the first element in the array. After you recast by changing the type string, type that hex address into the "Address" field at the top, then your data will show up correctly.

    TotalView variable window with button circled

  2. The type string will contain something along the lines of COMPLEX(4),allocatable::(:,:), whereas the "Actual Type" string will show you the dimensions. When you do the recast, make sure to remove the ,allocatable:: and change the (:,:) to the actual dimensions (e.g. (100,30)).

Ajean
  • 5,528
  • 14
  • 46
  • 69
  • I'd really like more details on how you wrote your custom visualizer, if you ever read this... – philb Jun 10 '20 at 18:57
  • 1
    @philb Sadly, I don't have access to the actual code at the moment, but I give a brief outline. It was written using PyQt, and it works in 2 parts ... the first is a class that, when instantiated from a main section, is designed to accept data from stdin according the Totalview's spec and store it, while displaying an item in a list. I used a QSocketNotifier to make sure it's a greedy reader. The second is a GUI class using PyQt and matplotlib that enables some simple display manipulation. Any other detail is probably longer than can fit in a comment, sorry! – Ajean Jun 12 '20 at 21:32