Page 1 of 1
Global cell index
Posted: Fri May 10, 2013 11:04 am
by zeph67
Hello,
I'm wondering how one can get the global cell-ID on CS3.0.0 . This was possible with the parallel subroutine PARCLG on some former versions. I read the cs_parall.c file but I didn't find...
Thanks in advance.
Re: Global cell index
Posted: Fri May 10, 2013 11:24 am
by Yvan Fournier
Hello,
Access to this from Fortran was removed, because it was unsafe (for huge meshes, an int may not be enough), so it would have needed to be improved, and it seemed that if you need to acess something this low-level (usually for I-O), accessing the C api (cs_glob_mesh->global_cell_num[]) is preferred.
You may always redefine your own wrapper, for example in cs_user_mesh.c, then access it from Fortran.
For a function similar to that of version 2.0 (including a "do nothing" bug when the code is run in serial):
Code: Select all
void
CS_PROCF (parcel, PARCEL)(cs_int_t *lnum,
cs_int_t *rankid,
cs_int_t *gnum)
{
#if defined(HAVE_MPI)
if (*rankid == cs_glob_rank_id)
*gnum = cs_glob_mesh->global_cell_num[*lnum - 1];
else
*gnum = 0;
MPI_Bcast(gnum, 1, CS_MPI_INT, *rankid, cs_glob_mpi_comm);
#endif
}
to simply obtain the global number (better in my opinion):
Code: Select all
void
CS_PROCF (parcel, PARCEL)(cs_int_t *lnum,
cs_int_t *gnum)
{
if (cs_glob_mesh->global_cell_num != NULL)
*gnum = cs_glob_mesh->global_cell_num[*lnum - 1];
else
*gnum = *lnum;
}
What do you need the global cell number for ?
Regards,
Yvan
Re: Global cell index
Posted: Fri May 10, 2013 8:13 pm
by zeph67
Thanks for this rich answer. I must admit that C programming is above my skills. Maybe I should improve them...
To answer your question, let's say that during a calculation, I perform some "pseudo-postprocessing" ; at each time step, I need averages in some directions. Determining, once and for all, for each cell, its rank in X, Y, Z directions (this example holds for a purely parallelepipedic domain), in cs_user_initialization.f90 (previously, in usiniv.F) is my strategy.
Indeed, at each time step, I just have to calculate the averages in the desired direction(s), by looping on the indices.
Anyway, getting the "global IEL" allows to perform what I need, for any configuration.
It is not the only way, I agree (*), but it is the simplest to code.
(*) for instance, an initial test on coordinates would also be OK.
Re: Global cell index
Posted: Sat May 11, 2013 9:06 am
by zeph67
Yvan,
In your second example for "parcel" function, I don't understand why the "rankid" variable is not required as input. How can the global cell number be determined with the sole local number ?
Thanks in advance.
Re: Global cell index
Posted: Sat May 11, 2013 5:35 pm
by Yvan Fournier
Hello,
in the second example, without the rankid variable, the returned global number is that of the cell with the given local number for the processor on which the function is called.
For example, for 9-cell a mesh with simple partitioning on 2 processors, with cells 1-5 on rank 0, and 6-9 on rank 1, given local cell number 2, the returned global cell number would be 2 for rank 0, 7 for rank 1.
In any case, you need to call the function only for local cells with a number between 1 an ncel. For that same example, calling it on rank 0 for cell 5 would return 6, but calling it on rank 1 for cell 4 would return an invalid number, or even cause a crash, as there are only 4 cells on that processor, and the local->global numbering array is the size of ncel.
Meaning the old function is not any safer when you have a varying number of cells per processor than the simpler one I suggested in the second example. I am not sure why the initial function used the rank as an argument, except perhaps as a (dangerous) means of finding on which rank a given global cell is found... I probably wrote that some 10 years+ ago, as I wrote most of the parallelizing code at the time, but I do not know what I was thinking...
For postprocessing a better function for you may be "paragv". Search for it in different examples of usproj.f90/cs_user_extra_operations.f90. I am not too fond of its logic (gather everything to a single rank), for for postprocessing a reasonbaly-sized data, it is quite useful.
Regards,
Yvan
Re: Global cell index
Posted: Mon May 13, 2013 5:40 pm
by zeph67
OK thank you.
I tried both parcel's you gave me, but none seems to work. Here is the compile.log file.
I had a look on paragv, but I don't understand it.
Any idea ?
Re: Global cell index
Posted: Mon May 13, 2013 8:51 pm
by Yvan Fournier
Hello,
Yes, cs_glob_mesh is undefined, so you need to add
#include "cs_mesh."
in the headers inclusion section of the source file (search for #include "cs_parall.h", add it just before to be safe).
Regards,
Yvan