0

What type and value does PETSC_COMM_WORLD in the following header expand to? Is it just a redefinition for MPI_Comm with extern scope?

#define PETSC_EXTERN extern PETSC_VISIBILITY_PUBLIC

PETSC_EXTERN MPI_Comm PETSC_COMM_WORLD;
ocramz
  • 816
  • 6
  • 18

1 Answers1

2

It's simple text substitution, so you end up with:

extern PETSC_VISIBILITY_PUBLIC MPI_Comm PETSC_COMM_WORLD;

Hence the type of PETSC_COMM_WORLD is PETSC_VISIBILITY_PUBLIC MPI_Comm and so depends on the definition of PETSC_VISIBILITY_PUBLIC, which hasn't been provided.

From a cursory search of the net, it will be empty when building the petsc DLL or the attribute __attribute__((visibility ("default"))) when using it.

The extern itself doesn't control or modify the type (nor does that attribute for that matter) it simply states that this variable is not being created here, but should be made available elsewhere.

The value depends entirely on where you're defining the variable, what scope it's at, whether you initialise it, and so on.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • Thank you for the thorough explanation; from one MPI implementation, I was expecting `MPI_COMM_WORLD` and similar to be an integer constant, fixed after configuration. I am interested in fishing out its value at compile time (I'm wrapping this library in a different language), what's the idiomatic way of doing it? Thanks again – ocramz May 18 '15 at 10:12
  • 1
    @ocramz, you can use something like `gcc -E yourfile.c | less` to have it output the translation unit _after_ the preprocessing step. That should give you all preprocessed symbols. Microsoft has the `/P /C` options which will give you a `yourfile.i` file containing the preprocessor output (with comments left in). – paxdiablo May 18 '15 at 10:23
  • Thank you again; I'm on a Unix; however the configure/build is quite involved (a very large makefile); I was wondering if there's perhaps a way of writing a thin C wrapper that exposes functions that return only the value of these constants.. – ocramz May 18 '15 at 11:16
  • 1
    @ocramz, that's possible as well, such as putting at the start of `main`: `if (argc > 1) { if (strcmp (argv[1],"xyzzy")==0) { printf ("Value of PLUGH is %d\n", PLUGH); return 0; } }`, then running your code with `myprog xyzzy`. – paxdiablo May 18 '15 at 12:35