PhreeqcUsers Discussion Forum
Click here to donate to keep PhreeqcUsers open

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 

  • Forum Home
  • Login
  • Register

  • PhreeqcUsers Discussion Forum »
  • Conceptual Models »
  • Incorporation PHREEQC in programming languages »
  • Beginner Question: PhreeqcRM + Fortran - Debug issues & Dumpfile generation
« previous next »
  • Print
Pages: [1]   Go Down

Author Topic: Beginner Question: PhreeqcRM + Fortran - Debug issues & Dumpfile generation  (Read 295 times)

RayTherminator

  • Contributor
  • Posts: 3
Beginner Question: PhreeqcRM + Fortran - Debug issues & Dumpfile generation
« on: August 09, 2021, 11:34:40 AM »
Dear Sir or Madam,

I have been trying to implement a geochemical simulation with PhreeqcRM by using Fortran.

As a first demonstration case I simply want to calculate a (initialization) reaction of a single cell.
My code is mostly based on the advection.f90 case which is distributed with PhreeqcRM.

I was lately finally able to make it run (after some issues with symbol loading and linking), however only in release mode (I use VS2019)

When building in Debug mode, it is possible to debug until the
Code: [Select]
status = RM_LoadDatabase(id, trim(adjustl(database_filename))command.

After then the program crashes with following error:
Code: [Select]
Debug Assertion Failed!
File: minkernel\crtst\ucrt\src\appcrt\liowio\read.cpp
Line: 381
Expression: _osfile(fh) & FOPEN

I didnt include any OpenMP or MPI stuff since I am yet not interested in parallelization (nthreads=1).
Still internet research let me confused, therefore I hoped to receive help here.


My second issue happens during the generation of the dumpfile. The error occurs in both debug & release mode. The programm crashes during the line
Code: [Select]
status = RM_DumpModule(id, dump_on, append)The method starts with writing
Code: [Select]
Dump 0%and then the program crashes with
Code: [Select]
forrtl: severe (164): Program Exception - integer divide by zeroI am able to continue my work without the dumpfile, however I am interested if anyone has experienced similar issues.

Thank you in advance.
Best regards,
Markus
Logged

dlparkhurst

  • Top Contributor
  • Posts: 2508
Re: Beginner Question: PhreeqcRM + Fortran - Debug issues & Dumpfile generation
« Reply #1 on: August 09, 2021, 04:34:37 PM »
If the tests for PhreeqcRM run correctly when you compile it, my guess for the first error is that the database file has not been found. Maybe the path is wrong? I guess it is possible there is a problem in the database that is causing the failure. The debugger should help find the problem.

The second error is a bug. It will work if you have two or more threads, but not with one. The fix is pretty simple. At about line 2392 you will find the first line listed below (assuming you are using OpenMP, the default). Add the second line after the first line and recompile PhreeqcRM. That  should fix the dump error.

      int total_cells = this->end_cell[this->nthreads - 1];
      if (total_cells <= 0) total_cells = 1;
Logged

RayTherminator

  • Contributor
  • Posts: 3
Re: Beginner Question: PhreeqcRM + Fortran - Debug issues & Dumpfile generation
« Reply #2 on: August 11, 2021, 08:45:42 AM »
Dear. Mr. Parkhurst,

First of all thank you very much for your fast reply.

Regarding my first issue:
Looking into the compilation of PhreeqcRM did actually help. My amateurish mistake was that I only compiled in release mode - thus, only a release PhreeqcRM.lib was created. I was unaware that PhreeqcRMd.lib was needed for debugging mode. After compiling and linking the correct *.lib (*d.lib for debug and *.lib for release) the database issue was solved.

for my second issue your guideline helped me too. Although, I am unsure if it worked as planned. I implemented your bugfix as told so in addition with a print out to check if it does work correctly:
Code: [Select]
if (total_cells <= 0) this->ScreenMessage(" solve BUG with NTHREAD = 1 ");
if (total_cells <= 0) total_cells = 1; //bugfix by mr DLparkhurst to fix NTHREAD=1 issue

However, even if I am running with 2 or more threads the statement gets printed anyway. Now my question is if the "ScreenMessage" method does print anyway (so wrongly implemented) or if there is now an issue with thread allocation?

Thank you very much for your relentless work here in helping us in this forum.

Best Regards,
Markus
Logged

dlparkhurst

  • Top Contributor
  • Posts: 2508
Re: Beginner Question: PhreeqcRM + Fortran - Debug issues & Dumpfile generation
« Reply #3 on: August 14, 2021, 12:19:22 AM »
You should look at the debugger again. The variable this->nthreads will give the defined number of threads. If it is not what you expected, then maybe you compiled without setting USE_OPENMP in your Visual Studio solution.

The variable total_cells does not actually affect the calculations. It is used simply to monitor the progress of dumping the model contents. So, as long as a zero-divide error is not thrown, the dump function should eventually be completed, but the progress indicator could be wrong.
Logged

  • Print
Pages: [1]   Go Up
« previous next »
  • PhreeqcUsers Discussion Forum »
  • Conceptual Models »
  • Incorporation PHREEQC in programming languages »
  • Beginner Question: PhreeqcRM + Fortran - Debug issues & Dumpfile generation
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines | Terms and Policies
  • XHTML
  • RSS
  • WAP2