grimme-lab / mctc-lib

Modular computation tool chain library
https://grimme-lab.github.io/mctc-lib
Apache License 2.0
15 stars 17 forks source link

add copy assignment to structure_type #58

Closed pitsteinbach closed 1 year ago

pitsteinbach commented 1 year ago

Hey,

I suggest this addition of a copy assignment as it resolves an issue I and probably also other people have when trying to compile the related dftd4 project with the newest intel oneAPI compiles (2023.0). Due to the implementation of the numeric hessian calculation in dftd4 in the file numdiff.f90, line 63 is not well defined and it seems that the new intel compilers can not cope with this resulting in a Segmentation Fault.

The explicit definition of the assignment of the "=" operator leads to a smooth compilation and the testsuite passes, for the C-API as well.

Maybe the addition of pdb and sdf is also necessary.

Best regards Pit

pitsteinbach commented 1 year ago

The issue by itself should be raised in dftd4, I agree. However, the changes here are sufficient to solve the issue, so I did not want to overcomplicate things. But I can open an issue in dftd4 and once the changes here are done the subproject dependency can be updated in dftd4.

awvwgk commented 1 year ago

I don't see how there is an issue in mctc-lib here. An assignment of a derived type instance without pointer components is equivalent with a deep copy. Overriding the assignment in this case is not necessary.

In the context of OMP there is definitely an issue with copying in derived types, as private variables are a memcooy rather than a deep copy, which means pointer addressed in every thread local copy point to the same memory location. The solution used in dftd4 relies on the deep copy mechanism described above, maybe it has to be made more explicit with a block scope inside the parallel region rather than copying in an uninitialized local variable and assigning from a shared one.

In any case mctc-lib is the wrong place to address this issue.

pitsteinbach commented 1 year ago

solved by intel compiler update to 2023.1