Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start to use more forward declarations #1464

Open
wants to merge 34 commits into
base: next
Choose a base branch
from
Open

Start to use more forward declarations #1464

wants to merge 34 commits into from

Conversation

d7919
Copy link
Member

@d7919 d7919 commented Dec 17, 2018

Work contributes towards resolving #1134

Alongside potential compilation speed improvements (that I've not observed yet), these changes (particularly once fully rolled out) should hopefully help make things a bit more flexible/easy to extend.

@d7919 d7919 added the work in progress Not ready for merging label Dec 17, 2018
@d7919
Copy link
Member Author

d7919 commented Dec 18, 2018

In terms of optimising the compilation I've done a bit of timing which shows that including bout_types.hxx has a cost of about 0.8s, which compares to a time to compile a single source file of somewhere between 2 and 6 seconds (for the majority of source files). As bout_types is included (directly or indirectly) in a large fraction of our source files we might be able to get a decent saving by splitting this header into separate parts. About 3/4 of the time comes from defining the maps used to convert enums to strings and the associated utility routines (with the other quarter coming from the includes of language standard libraries).

Just declaring these maps without initialising them in the header cuts the time from 0.8s to about 0.45s. It doesn't sound much but I think it could be a reasonable fraction saving across a full build (note configure+compile on travis takes about 10 minutes, with the tests then taking 2-7 minutes).

#include <bout_types.hxx>
#include <field2d.hxx>
#include <field3d.hxx>
#include <fieldperp.hxx>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused about this... should we use <> for system headers and "" for BOUT++ headers?

Copy link
Member Author

@d7919 d7919 Dec 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tend to view <> as being something provided by a library (including bout) and "" for local files. Or in other words <> for things in an include path and "" for things that aren't. This is just my interpretation though. I think "" can search more places, but if this is an advantage or a disadvantage may be a matter of opinion.

( I should add "" falls back to <> if the first (implementation defined) search fails -- in practice I think that means most of our uses of "" fall back to <> anyway ).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, there is not much difference. The C standard says both are implementation defined, which the exception that "" explicitly looks for a file and <> for a header, which might not be a file.

  • For "", gcc searches the current directory first, then paths specified with -iquote, then "a standard list of system paths" which includes those in -I.

  • For <>, gcc searches the system paths only (including those in -I and -isystem).

I don't think we use -I., so private headers do really need to be "", while the public ones can be <>. Beyond that, I think it is a matter of opinion -- but it would be nice to be consistent! As a note, the gcc docs below say to use "" for "your own program" and <> for "system headers".

https://gcc.gnu.org/onlinedocs/cpp/Search-Path.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One reason to prefer "" for all BOUT++ headers: clang-format and include-what-you-use can group headers together, and it might be nice to separate the system headers from ours.

@johnomotani
Copy link
Contributor

@d7919 tests are failing at the moment. Looks like maybe you forgot to add the .hxx files for ParallelTransform implementations in 4135a74?

@d7919
Copy link
Member Author

d7919 commented Dec 30, 2018

@johnomotani thanks, you're right -- I've now added the new files, thanks!

@ZedThree
Copy link
Member

ZedThree commented Jan 3, 2019

I think it's now just missing #include "dcomplex.hxx" in slepc.cxx

throw BoutException("Unhandled direction encountered in getAllowedStaggerLoc");
}
};
CELL_LOC getAllowedStaggerLoc(DIRECTION direction) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three functions now can't be inlined -- but it doesn't look like they're used in any tight loops so presumably this isn't that bad

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is one of the reasons I think this PR might be more for discussion/experimentation to decide on a policy. I'd prefer runtime performance over compilation performance but there may be places we can get both.

@ZedThree
Copy link
Member

ZedThree commented Jan 3, 2019

While we're tidying up, we should probably rename all the include guards as macros beginning with __ or _X are technically reserved by the preprocessor.

@@ -35,17 +35,29 @@

class Solver;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to delete this

@ZedThree
Copy link
Member

ZedThree commented Jan 4, 2019

I used include-what-you-use plus some manual fiddling to make sure everything in headers is inside include guards: https://travis-ci.org/boutproject/BOUT-dev/builds/475492401

Also made all BOUT++ headers included with "" and used clang-format to group headers together (main header (i.e. field3d.hxx for field3d.cxx-> system headers -> bout/ headers -> everything else)

Any gain over this PR is in the noise, but it would at least be a consistent treatment of headers. At the cost of 2k+ lines changed!

I'm in favour of merging this PR at least, it's about a 20% speedup of compile times on Travis

@d7919
Copy link
Member Author

d7919 commented Jan 5, 2019

I used include-what-you-use plus some manual fiddling to make sure everything in headers is inside include guards: https://travis-ci.org/boutproject/BOUT-dev/builds/475492401

Also made all BOUT++ headers included with "" and used clang-format to group headers together (main header (i.e. field3d.hxx for field3d.cxx-> system headers -> bout/ headers -> everything else)

Any gain over this PR is in the noise, but it would at least be a consistent treatment of headers. At the cost of 2k+ lines changed!

I'm in favour of merging this PR at least, it's about a 20% speedup of compile times on Travis

For reference I've made a branch that just includes the changes to bout_types and the travis build is at https://travis-ci.org/boutproject/BOUT-dev/builds/475809020?utm_source=github_status&utm_medium=notification -- this hasn't finished yet but I suspect this should get much of the compilation gain from this PR.

@bendudson
Copy link
Contributor

Is this one for tidying and merging, or closing?

@ZedThree
Copy link
Member

The tidying is likely going to be a nightmare so probably closing and rebasing. I did have a go last week, I'll check it still goes in cleanish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work in progress Not ready for merging
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants