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

[CoSim] Changing CMAKE to C++17 in CoSIm External Lib #12209

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

Igarizza
Copy link
Member

📝 Description
During compilation on HPC we found that cosim appliction can be compiled only with c++11, which caused errors in our compilation. Changing cmake file to use c++17 helped.

@Igarizza Igarizza requested a review from a team as a code owner March 19, 2024 16:50
@Igarizza Igarizza changed the title required changes [CoSim] Changing CMAKE to C++17 in CoSIm External Lib Mar 19, 2024
@Igarizza
Copy link
Member Author

@matekelemen FYI

@philbucher
Copy link
Member

Hey, not against but would like to know the errors

Perhaps there is a better fix

@matekelemen
Copy link
Contributor

matekelemen commented Mar 20, 2024

I never tried compiling parts of the same program with different standards, but I wouldn't be surprised if it were dangerous.

One of the errors I remember when we tried compiling on the cluster is that std:filesystem namespace was (obviously) not found.

P.S.: here

@philbucher
Copy link
Member

I agree that this has to be improved, I wonder why I did it like this in the first place.

And how it was working on otter systems.

I need to think a bit

@Igarizza
Copy link
Member Author

Igarizza commented Mar 21, 2024

I never tried compiling parts of the same program with different standards, but I wouldn't be surprised if it were dangerous.

One of the errors I remember when we tried compiling on the cluster is that std:filesystem namespace was (obviously) not found.

P.S.: here

/home/ihaanton/Software/Kratos/applications/CoSimulationApplication/custom_external_libraries/CoSimIO/co_sim_io/includes/filesystem_inc.hpp:17:21: error: ‘filesystem’ is not a namespace-name; did you mean ‘system’?
   17 | namespace fs = std::filesystem;
        |                     ^~~~~~~~~~
        |                     system

@philbucher
Copy link
Member

I never tried compiling parts of the same program with different standards, but I wouldn't be surprised if it were dangerous.

not sure I follow. Different programs can use different compilers, standards, even languages ...?
E.g. feast (eigensolver) which is written in fortran

Copy link
Member

@philbucher philbucher left a comment

Choose a reason for hiding this comment

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

since I manually removed the filesystem bcs Kratos is C++17, I think it is also ok to hack it like this. I will keep it in mind, maybe I come across a smarter/automatic solution

@matekelemen
Copy link
Contributor

matekelemen commented Mar 24, 2024

not sure I follow. Different programs can use different compilers, standards, even languages

Sure, but as always it's a bit difficult with C++. I'm by no means an expert at this, but as far as I know you must keep a few things in mind when you want to mix standards/compilers/etc:

First that comes to mind is never to pass standard classes through API boundaries, because the binary layout may be different across programs if compiled with different compilers. For example

dependency.hpp

#include <vector>
void dependency(std::vector<int>& arg);

dependency.cpp

void dependency(std::Vector<int>& arg)
{
    // do some stuff with arg
}

user.cpp

#include "dependency.hpp"
#include <vector>
int main()
{
    dependency(std::vector<int> {});
}

if dependency is a library compiled with GCC and user is a program compiled with Clang, they may have a different implementation of vector and have different binary layouts as a result, i.e.: when user constructs and passes a vector, dependency will receive a vector that is corrupt (from its point of view).

Another problem is which headers to include. user.cpp includes GCC vector, but it should also indirectly include Clang vector via dependency.hpp, but there must only be one definition of std::vector.

These are just some things that come to mind, and CoSimIO is definitely affected, as the main interface header includes standard headers and also puts standard classes on its API:

#include <vector>
#include <string>
#include <unordered_map>
#include <atomic>
#include <ostream>

https://github.com/KratosMultiphysics/CoSimIO/blob/a1feb8fe6e1ca7ba42e56c39202aa9e519129ea8/co_sim_io/sources/co_sim_io.cpp#L68-L72

P.S.: the same issues are still valid with the same compiler but different standards. Some standards might retain binary compatibility, but they will almost certainly have different headers.

@philbucher
Copy link
Member

Thanks for the explanation, that makes sense

I think trilinos, metis etc have a C API, guess for this reason

For me still unclear is how it works e.g. in the CI bit not ok your machines

Kratos sets c++17 as standard, do you have a clue why it is not applied go CoSimIO? It is a subdir, so it should IMO. Maybe it is the order of compilation?

@roigcarlo perhaps you have an idea?

@matekelemen
Copy link
Contributor

matekelemen commented Mar 25, 2024

For me still unclear is how it works e.g. in the CI bit not ok your machines

I'm also surprised about that

Kratos sets c++17 as standard, do you have a clue why it is not applied go CoSimIO?

Because CoSimIO explicitly sets the C++11 standard via compiler flags (see the changes in this PR). I think we could just remove the -std=c++xx flag, and that would allow the parent project (Kratos) to set its desired standard (17).

The problem is what happens when someone wants to compile CoSimIO on its own? Then CoSimIO would have to set the minimum version it requires (11). I suggest adding a CMake flag for CoSimIO that controls what the preferred C++ standard should be, whose default value is 11.

@roigcarlo
Copy link
Member

I will investigate, but as you said, if the CoSim sets the flat to 11, and it get added after the Kratos one, it will use 11 regardless of what Kratos says.

@matekelemen
Copy link
Contributor

matekelemen commented Apr 4, 2024

@roigcarlo any updates?

I think this should be fixed upstream, and then ported to kratos. Any objections? Should I do it?

@roigcarlo
Copy link
Member

No so far sorry :/ but I would merge the PR if that solves the issue.

@matekelemen matekelemen merged commit e2ec331 into master Apr 25, 2024
11 checks passed
@matekelemen matekelemen deleted the cosim/c++17_cmake branch April 25, 2024 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants