[sundials-users] CVODE Fortran Interface Thread Safe?

12 views
Skip to first unread message

00002ce5063010f...@listserv.llnl.gov

unread,
Apr 10, 2025, 2:07:19 PMApr 10
to SUNDIAL...@listserv.llnl.gov
Hello,

I'm currently working to replace the use of ODEPACK (LSODE specifically) in a older Fortran codebase with CVODE because of some thread-safety issues that we're encountering. The section of code I'm working in is in a subroutine called from an OpenMP loop, so I'm using the second approach from the example here (https://sundials.readthedocs.io/en/latest/sundials/SUNContext_link.html#implications-for-task-based-programming-and-multi-threading). The codebase is on the order of ~100k lines of code, so restructuring things isn't feasible at this time.

I'm however encountering what appear to be thread-safety issues in some serial N_Vectors that I have created for use in CVODE. Can I expect thread-safety from the Fortran interface in this case? If so, should I be using OpenMP N_Vectors (and a single dense matrix) instead of serial N_Vectors? My problem size is fairly small, so I was trying to avoid the overhead of using the OpenMP N_Vectors.

Thanks,


JERRED JESSE, Ph.D


'NOTICE: This email message and all attachments transmitted with it may contain privileged and confidential information, and information that is protected by, and proprietary to, Parsons Corporation, and is intended solely for the use of the addressee for the specific purpose set forth in this communication. If the reader of this message is not the intended recipient, you are hereby notified that any reading, dissemination, distribution, copying, or other use of this message or its attachments is strictly prohibited, and you should delete this message and all copies and backups thereof. The recipient may not further distribute or use any of the information contained herein without the express written authorization of the sender. If you have received this message in error, or if you have any questions regarding the use of the proprietary information contained therein, please contact the sender of this message immediately, and the sender will provide you with further instructions.'


To unsubscribe from the SUNDIALS-USERS list: write to: mailto:SUNDIALS-USERS-...@LISTSERV.LLNL.GOV

Balos, Cody

unread,
Apr 10, 2025, 2:24:15 PMApr 10
to SUNDIAL...@listserv.llnl.gov

Hi Jerred,

 

If you are creating the serial N_Vectors within the OpenMP loop such that they are private to a thread (along with the SUNContext and CVODE memory) then you should not have any thread-safety issues. E.g., expanding on the second approach in the documentation section you cited

 

// Create, Solve, Destroy

#pragma omp parallel for

for (int i = 0; i < num_problems; i++) {

   int retval = 0;

   void* cvode_mem;

   SUNContext sunctx;
   N_Vector y;

 

   sunctx = SUNContext_Create(...);

   y = N_VNew_Serial(neq, sunctx);

   cvode_mem = CVodeCreate(..., sunctx);

   retval = CVodeInit(cvode_mem, ...);

 

   // set optional cvode inputs...

 

   CVode(cvode_mem, ...);

 

   // get optional cvode outputs...

 

   CVodeFree(&cvode_mem);

   N_VDestroy(y);

   SUNContext_Free(&sunctx);

}

 

 

The OpenMP N_Vector simply parallelizes the loops within the N_Vector operations using OpenMP, so it will not solve a thread-safety problem.

 

Cody

Reply all
Reply to author
Forward
0 new messages