Ignore:
Timestamp:
Nov 26, 2008 2:56:05 PM (14 years ago)
Author:
srkline
Message:

Added poor man's threading to the MonteCarlo? calculation.

My guess is that the ran() function from NR is not thread safe (it is non-reentrant). So I simply duplicated Monte_SANSX to Monte_SANSX2, where each incarnation uses a different random number generator, either ran1() or ran3(). This means that currently only two processors are supported. Not a big deal. At least it works.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sans/XOP_Dev/MonteCarlo/MonteCarlo.c

    r437 r458  
    3333// - some locks are non-existent 
    3434// - supposedly safe wave access routines are used 
     35// 
     36// random number generators are not thread-safe, and can give less than random results, but is this enough to crash? 
     37// -- a possible workaround is to define multiple versions (poor man's threading) 
     38// 
    3539// 
    3640// 
     
    220224        do { 
    221225                ////SpinProcess() IS A CALLBACK, and not good for Threading! 
    222                 if ((n1 % 1000 == 0) && gCallSpinProcess && SpinProcess()) {            // Spins cursor and allows background processing. 
    223                                 result = -1;                                                            // User aborted. 
    224                                 break; 
    225                 } 
     226//              if ((n1 % 1000 == 0) && gCallSpinProcess && SpinProcess()) {            // Spins cursor and allows background processing. 
     227//                              result = -1;                                                            // User aborted. 
     228//                              break; 
     229//              } 
    226230         
    227231                vx = 0.0;                       // Initialize direction vector. 
     
    436440 
    437441//      HSetState((Handle)wavH, hState);                //release the handle of the 2D data wave 
    438         WaveHandleModified(wavH);                       // Inform Igor that we have changed the wave. (CALLBACK! needed, but not allowed in Threading) 
     442//      WaveHandleModified(wavH);                       // Inform Igor that we have changed the wave. (CALLBACK! needed, but not allowed in Threading) 
    439443         
    440444        return(0); 
     
    520524        return(retval); 
    521525} 
     526 
    522527 
    523528#define IA 16807 
     
    665670                        return((long)Monte_SANSX); 
    666671                        break; 
     672                case 1:                                         //  
     673                        return((long)Monte_SANSX2); 
     674                        break; 
     675 
    667676        } 
    668677        return(NIL); 
Note: See TracChangeset for help on using the changeset viewer.