t-sakashita / rokko

Integrated Interface for libraries of eigenvalue decomposition
Boost Software License 1.0
10 stars 2 forks source link

Ubuntu + gccで、ソルバが一つも登録されない。 #608

Closed t-sakashita closed 1 year ago

t-sakashita commented 1 year ago

Pythonバインディングではなく、C++で使用した場合の問題。

Ubuntu latest (focal)をVirtualBoxで立ち上げて使用。

Mac (clang++)では、正常動作。

t-sakashita commented 1 year ago
./rokko_solvers 

の実行結果:

[serial dense solvers]
[parallel dense solvers]
[parallel sparse solvers]
t-sakashita commented 1 year ago

ファクトリにstatic inlineを用いる直前のコミットに戻してみる。 81a6d19e5a53851f1dee3a312394c0446567ed14

Ubuntu + gccでも、rokko_solversの出力結果は正常:

[serial dense solvers]
  eigen3
  lapack
[parallel dense solvers]
  eigenexa
  elemental
  scalapack
[parallel sparse solvers]
  anasazi
  original
  slepc
t-sakashita commented 1 year ago

gcc9を用いているが、バージョンが古い?

t-sakashita commented 1 year ago

Ubuntu jammyにおいて、gcc11.4を用いても、ソルバは一つも登録されない。

t-sakashita commented 1 year ago

test/factory/register_products.cppで試したら、segmentation faultが起きた。 register_products.cppは固有値ソルバを用いず、クラスの登録もregister_products.cppの中で行っているから、原因の切り分けに役立ちそう。

t-sakashita commented 1 year ago

factoryクラスでは、instance_だけでなく、全てのプライベートオブジェクトを、static inlineにして良い? すべきか?

private:
  static inline std::unique_ptr<factory> instance_ = nullptr;
  static inline creator_map_type creators_;
  static inline int largest_priority_ = 0;
  static inline std::string default_product_;
t-sakashita commented 1 year ago

main関数以前に記述された、static変数の初期化は保証されない。 https://stackoverflow.com/questions/73875402/why-does-stdmap-crash-when-it-is-declared-static-inline-inside-a-class-and-use https://stackoverflow.com/questions/46884933/c-initialize-static-map-of-objects

t-sakashita commented 1 year ago

固有値ソルバの登録が一切されない問題の解決法:

main関数以前の、static変数の初期化は保証されるために、以下を試した。(規格として保証されるのかは不明だが。) factoryクラスのlargest_priority_static inlineを指定した。 このゼロ初期化もコンストラクタではなく、= 0と書いたので見やすくなった。 94df0f4e9a6448e6129f66837058a8bb7f2f62cd

Ubuntu jammyにおいて、gcc11.4を用いた場合にも、test/factory/register_products.cppが正常終了するようになった。 なぜ?

なお、serial_dense_evのファクトリの登録をするだけでも、正常終了した。 factoryの他のテンプレートによるderived classも実体化されたようだ。

t-sakashita commented 1 year ago

メインプログラム側でインクルードするヘッダファイルdeclare_factory_instance.hppを用意した。 これは、factoryクラスのinstance_オブジェクトの宣言を行う。 (その際、inlineが指定されているので、externは不要。) (declare_factory_instance.hppを、ライブラリlibrokko.soの作成に用いるソースファイルでインクルードすると、リンクエラーとなることに注意。) 4f685d3197559084b6acb77083c90ef1b923c5f0

以上のコミットにより、Ubuntu jammyにおいて、gcc11.4を用いた場合にも、全てのソルバが登録されるようになった。

t-sakashita commented 1 year ago

Githubのautorunでも、testディレクトリのプログラムでソルバが登録されるようになった。