开发者

F# - Scope of variables

I have an F# code computing liquid flow. The code consist of 2 projects. The core library and project to run simulations. When I run a parametric study like

open CoreLibrary
for lbmViscosity in [0.1] do
  for Re in [0.001; 0.5] do
    for lbmD in [6.;5.;4.;3.;2.5;2.;1.5;1.;0.8;0.6;0.4;0.2] do
      simulation setup
      let result = call CoreLibrary
      save result to file

then I obtain correct result. When I run the code as:

open CoreLibrary
for lbmViscosity in [0.1] do
  for Re in [0.1; 0.001; 0.5] do
    for lbmD in [6.;5.;4.;3.;2.5;2.;1.5;1.;0.8;0.6;0.4;0.2] do
      simulation setup
      let result = call CoreLibrary
      save result to file

Then for Re = 0.001, I get a w开发者_StackOverflow社区rong result. I have also tried Array.iter instead of for loop with the same result. When I compile my code and run it as exe with different input parameters then it works well.

Is there anything which could cause an incorrect result aside from mutation? May it be Garbage collector's fault? And is there any command which would completely clean up a memory at certain place? Something like:

open CoreLibrary
for lbmViscosity in [0.1] do
  for Re in [0.1; 0.001; 0.5] do
    for lbmD in [6.;5.;4.;3.;2.5;2.;1.5;1.;0.8;0.6;0.4;0.2] do
      clean everything
      simulation setup
      let result = call CoreLibrary
      save result to file

I mutate values only in the core library not in the for loops. Therefore I would expect that as soon as for loop goes to next cycle or as soon as the end of Array.iter occurs everything inside is erased.

Thanks for any help, hint etc :)


So I have found what was wrong - Massif was right! :) In the coreLibrary, we use ConcurrentDictionary. We wanted to use Records instead of Classes (to be functional :D) and records do not allow to create the dictionary inside of the class, so the dictionary has been created outside of the class and linked into the record by member functions. So once the dll was loaded the dictionary has been created and stayed alive for ever... Now we changed the record into class and everything works fine. Thank you very much for your hints


So I have found what was wrong - Massif was right! :) In the coreLibrary, we use ConcurrentDictionary. We wanted to use Records instead of Classes (to be functional :D) and records do not allow to create the dictionary inside of the class, so the dictionary has been created outside of the class and linked into the record by member functions. So once the dll was loaded the dictionary has been created and stayed alive for ever... Now we changed the record into class and everything works fine. Thank you very much for your hints


What data types are you using? Is it possible that the floating-point types that you are using are introducing representation errors? What constitutes "correct" and "incorrect" output?

As a general rule, opening or not opening a library won't have any impact on the result of a calculation (assuming that the code still compiles!).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜