How can I send complex data to my visualizer in TotalView? - fortran

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.

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.
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.
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)).

Related

Design the presentation of own class in the variable viewer

I'm using Visual Studio and writing in C++. I have written a table (named Vector) which columns can be of any data type (any size the user wishes). In this example I filled one row with three columns. First is of type Byte (1 Byte in size), seconds is also of type Byte and the third of type Int64 (8 Bytes). I saved the numbers 1, 2 and 3.
I also created a vector from the c++ standard (std::vector) and filled it with the same numbers.
As you can see, the seconds picture with the std::vector variable myStdVector shows the int-numbers sorted with [0], 1, 2. I like this class view.
And I would like my own class (Vector) to have the same design respectively presentation in the variable viewer.
Probably it is also possible to show the data type in the third column of the variable viewer which could be different in my Vector-class.
Does Visual Studio offer a possibility to structure the member variables or show some data in a special way?
own vector table class view
std vector class view

Pymol: How to use a list index as input for a pymol function (align)?

I want to get the RMSD for each pair of poses generated by an autodock docking via the align function:
align pose1, pose2, cycles=0, transform=0
Instead of using the names of the poses as input, I want to access a list that contains all poses.
This list is successfully obtained via:
allobjects = cmd.get_object_list('all')
and
print(allobjects[x])
successfully prints the pose at position x in this list.
However, the following method did not work:
align allobjects[1], allobjects[2], cycles=0, transform=0
yields error: Invalid selection name "allobjects[1]"
What would be the correct way to feed the align function with the list indices?
Thank you in advance!
As far as I know, you can not pass values from python variables to the built-in functions of PyMOL. But there is almost always an equivalent python function that does the same and can receive regular pythonic arguments. In the case of align it would be cmd.align().
The result of cmd.align() is not printed as nice as the align function, but instead a list of 7 elements is returned, being the first element the calculated RMSD. The meaning of the rest of the values can be found in the source code of the function.
I also assume that you intent to calculate the RMSD for every possible pair of docked structures. For that purpose you have to use all the unique combinations of all structures and manually do a python loop over them. Be aware that the calculation time will increase exponentially with the number of structures you have.
allobjects = cmd.get_object_list('all')
from itertools import combinations
for pair in combinations(allobjects, 2): print(pair[0], pair[1], cmd.align(pair[0], pair[1], cycles=0, transform=0)[0])

Format array content into a series of strings and output to .csv in C++?

I have been trying to figure out what the best way to do this would be, but haven't quite found an answer yet. I have a float array full of data collected from an inertial sensor and I would like to put it into the right format and output it to a CSV file. I'm using an mbed microcontroller with a local file system to store the file. It's the part about getting the format right that is confusing me at the minute.
I'd like my gyroscope/accelerometer values to be displayed in rows such as:
gx1, gy1, gz1, ax1, ay1, az1
gx2, gy2, gz2, ax2, ay2, az2
gx3, gy3, gz3, ax3, ay3, az3
I think these values first need to be converted to char before being written to the file, so I will need to do that and store them in a new array of type char. That's where I get confused, because I don't just want to copy the data into this new array all at once (thinking of using a for loop and spritf()) but I also want it to be formatted as displayed above, with the right breaks between rows.
The function that writes the content of the array to the file takes the array, its types size, the array size and the file object.
fwrite(converted_array, sizeof(char), sizeof(converted_array), FileObject);
What would be the best way to make sure that the array content is formatted like I want it to be?

Use the function "mod" in the instructions "if" and "select case"

I wrote a little code in Fortran. But the code doesn't behave as I thought, and I can figure out where is the problem.
I will not put the code here because it has 1200 lines but here its philosophy:
I create a 3D grid represented by a four dimensional table (I stock a vector of 2 elements on each point of the grid, corresponding at the nature of the site and who is occupying the site). This grid represents what we call a crystal (where atoms can be found periodically)
When this grid is constructed, the code scans each point of this grid and it looks to the neighboring sites to count the different type of atoms or the vacancies.
For this last point, I use a triple imbricated loop which permit to explore the different sites and I check the different neighboring site using either the if or the select case instructions. As I want my grid to be periodic, I have the function mod in the argument of the if or the select case.
The problem is sometimes, It found a different element in a neighboring site that the actual element in this specific neighboring site. As an example:
In the two ouput files where all the coordinates are written with the
element type I have grid(0,0,1)=-1 (which correspond to a empty site).
But while the code is looking to the neighboring sites of grdi(0,0,1) It tells that there is actually an element indexed 2 in grid(0,0,1).
I look carefully to the block in the triple implemented loop, but it seems fine.
I would like to know if anyone has already meet this kind of problem, or know if there is some problems using mod in a if or select case argument ?
If some of you want to look closer, I can send you the code, with some explanations.
Arrays are usually dimensioned as:
REAL(KIND=8),DIMENSION(0:N) ::A
or
REAL(KIND=8),DIMENSION(N) :: A
In the later example, they are assumed to start at 1.
You could also go (-N:N) or (10:191)
If you use the compiler switch '-check bounds' or ;-check all' you will see if you are going outside the array/etc. This is not an uncommon thing to get hosed up, but the compiler will abort quickly when the dimension is outside.
Once it works then removed the -check bounds and/or -check all.
Thanks for your consideration francescalus and haraldkl.
It was not related to the dimension of arrays Holmz, but thank you to try to help
It seems I finally succeed to fix it. I will post an over answer If I fully understand why it was not working properly.
Apparently, it was related to the combination of a different argument order in a call procedure and the subroutine header + a declaration in the subroutine with intent(inout).
It was like the intent(inout) was masking the problem. But It a bit strange for me.
Some explanations about the code :
As I said, the code create a 3D grid where each intersection of the 3D grid correspond to a crystallographic site. I attribute a value at each site -1 for an empty site, 1 for a crystal atom (0 if there is a vacancy instead of a crystal atom), 2,3,4,5 for different impurities. Actually, the empty sites and the sites which received crystal atoms are not of the same type, that's why an empty site and a vacancy are distinguished. The impurities can only occupied the empty site and are forbidden to occupied a crystal site.
The aim of the code is to explore the configurational space of the system, in other words all the possible distribution we can obtained with the different elements. To do so I start from a initial configuration and I choose randomly to site (respecting the rules of occupation) and I virtually switch them. I calculate the energy of the old an new configurations, if the new has a lower energy I keep it, if not, i keep the old one. The calculus of the energy is based on the knowledge of the environment of each vacancies and impurities, so we need to know their neighbors. And I repeat the all procedure again and again to converge to the most stable (so the most probable) configuration.
The next step is to include the temperature effect, and to add the second type of empty sites.
Have a nice day,
M.

How to display a dynamically allocated array in the Visual Studio debugger?

If you have a statically allocated array, the Visual Studio debugger can easily display all of the array elements. However, if you have an array allocated dynamically and pointed to by a pointer, it will only display the first element of the array when you click the + to expand it. Is there an easy way to tell the debugger, show me this data as an array of type Foo and size X?
Yes, simple.
say you have
char *a = new char[10];
writing in the debugger:
a,10
would show you the content as if it were an array.
There are two methods to view data in an array m4x4:
float m4x4[16]={
1.f,0.f,0.f,0.f,
0.f,2.f,0.f,0.f,
0.f,0.f,3.f,0.f,
0.f,0.f,0.f,4.f
};
One way is with a Watch window (Debug/Windows/Watch). Add watch =
m4x4,16
This displays data in a list:
Another way is with a Memory window (Debug/Windows/Memory). Specify a memory start address =
m4x4
This displays data in a table, which is better for two and three dimensional matrices:
Right-click on the Memory window to determine how the binary data is visualized. Choices are limited to integers, floats and some text encodings.
In a watch window, add a comma after the name of the array, and the amount of items you want to be displayed.
a revisit:
let's assume you have a below pointer:
double ** a; // assume 5*10
then you can write below in Visual Studio debug watch:
(double(*)[10]) a[0],5
which will cast it into an array like below, and you can view all contents in one go.
double[5][10] a;
For,
int **a; //row x col
add this to watch
(int(**)[col])a,row
Yet another way to do this is specified here in MSDN.
In short, you can display a character array as several types of string. If you've got an array declared as:
char *a = new char[10];
You could print it as a unicode string in the watch window with the following:
a,su
See the tables on the MSDN page for all of the different conversions possible since there are quite a few. Many different string variants, variants to print individual items in the array, etc.
You can find a list of many things you can do with variables in the watch window in this gem in the docs:
https://msdn.microsoft.com/en-us/library/75w45ekt.aspx
For a variable a, there are the things already mentioned in other answers like
a,10
a,su
but there's a whole lot of other specifiers for format and size, like:
a,en (shows an enum value by name instead of the number)
a,mb (to show 1 line of 'memory' view right there in the watch window)
For MFC arrays (CArray, CStringArray, ...)
following the next link in its Tip #4
http://www.codeproject.com/Articles/469416/10-More-Visual-Studio-Debugging-Tips-for-Native-De
For example for "CArray pArray", add in the Watch windows
pArray.m_pData,5
to see the first 5 elements .
If pArray is a two dimensional CArray you can look at any of the elements of the second dimension using the next syntax:
pArray.m_pData[x].m_pData,y
I haven't found a way to use this with a multidimensional array. But you can at least (if you know the index of your desired entry) add a watch to a specific value. Simply use the index-operator.
For an Array named current, which has an Array named Attribs inside, which has an Array named Attrib inside, it should look like this if you like to have to position 26:
((*((*current).Attribs)).Attrib)[26]
You can also use an offset
((*((*current).Attribs)).Attrib)+25
will show ne "next" 25 elements.
(I'm using VS2008, this shows only 25 elements maximum).