Changeset 753


Ignore:
Timestamp:
Oct 7, 2010 10:40:18 AM (12 years ago)
Author:
srkline
Message:

Bug fix: changed 2D functions to use MultiThread? keyword. Hand-threading previusly worked in Igor 6.12, but gives an index out of range error in Igor 6.2. New version is easier, bug report sent to WM.

Location:
sans/Dev/trunk/NCNR_User_Procedures/Analysis
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/CoreShellCyl2D_v40.ipf

    r570 r753  
    124124// 
    125125 
    126 //threaded version of the function 
    127 ThreadSafe Function CoreShellCylinder2D_T(cw,zw,xw,yw,p1,p2) 
    128         WAVE cw,zw,xw,yw 
    129         Variable p1,p2 
    130          
    131 #if exists("CoreShellCylinder_2DX")                     //to hide the function if XOP not installed 
    132  
    133         Make/O/D/N=15 CSCyl2D_tmp 
    134         CSCyl2D_tmp = cw 
    135         CSCyl2D_tmp[14] = 25 
    136         CSCyl2D_tmp[7] = 0              //send a zero background to the calculation, add it in later 
    137  
    138         zw[p1,p2]= CoreShellCylinder_2DX(CSCyl2D_tmp,xw,yw) + cw[7] 
    139          
    140 #endif 
    141  
    142         return 0 
    143 End 
     126////threaded version of the function 
     127//ThreadSafe Function CoreShellCylinder2D_T(cw,zw,xw,yw,p1,p2) 
     128//      WAVE cw,zw,xw,yw 
     129//      Variable p1,p2 
     130//       
     131//#if exists("CoreShellCylinder_2DX")                   //to hide the function if XOP not installed 
     132// 
     133//      Make/O/D/N=15 CSCyl2D_tmp 
     134//      CSCyl2D_tmp = cw 
     135//      CSCyl2D_tmp[14] = 25 
     136//      CSCyl2D_tmp[7] = 0              //send a zero background to the calculation, add it in later 
     137// 
     138//      zw[p1,p2]= CoreShellCylinder_2DX(CSCyl2D_tmp,xw,yw) + cw[7] 
     139//       
     140//#endif 
     141// 
     142//      return 0 
     143//End 
     144// 
     145//// 
     146////  Fit function that is actually a wrapper to dispatch the calculation to N threads 
     147//// 
     148//// nthreads is 1 or an even number, typically 2 
     149//// it doesn't matter if npt is odd. In this case, fractional point numbers are passed 
     150//// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points 
     151//// and the points "2.5" and "3.5" evaluate correctly as 2 and 3 
     152//// 
     153//Function CoreShellCylinder2D(cw,zw,xw,yw) : FitFunc 
     154//      Wave cw,zw,xw,yw 
     155//       
     156//      Variable npt=numpnts(yw) 
     157//      Variable i,nthreads= ThreadProcessorCount 
     158//      variable mt= ThreadGroupCreate(nthreads) 
     159// 
     160//      for(i=0;i<nthreads;i+=1) 
     161//      //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1) 
     162//              ThreadStart mt,i,CoreShellCylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) 
     163//      endfor 
     164// 
     165//      do 
     166//              variable tgs= ThreadGroupWait(mt,100) 
     167//      while( tgs != 0 ) 
     168// 
     169//      variable dummy= ThreadGroupRelease(mt) 
     170//       
     171//      return(0) 
     172//End 
    144173 
    145174// 
     
    154183        Wave cw,zw,xw,yw 
    155184         
    156         Variable npt=numpnts(yw) 
    157         Variable i,nthreads= ThreadProcessorCount 
    158         variable mt= ThreadGroupCreate(nthreads) 
     185#if exists("CoreShellCylinder_2DX")                     //to hide the function if XOP not installed 
    159186 
    160         for(i=0;i<nthreads;i+=1) 
    161         //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1) 
    162                 ThreadStart mt,i,CoreShellCylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) 
    163         endfor 
     187        Make/O/D/N=15 CSCyl2D_tmp 
     188        CSCyl2D_tmp = cw 
     189        CSCyl2D_tmp[14] = 25 
     190        CSCyl2D_tmp[7] = 0              //send a zero background to the calculation, add it in later 
    164191 
    165         do 
    166                 variable tgs= ThreadGroupWait(mt,100) 
    167         while( tgs != 0 ) 
     192        MultiThread zw= CoreShellCylinder_2DX(CSCyl2D_tmp,xw,yw) + cw[7] 
     193         
     194#endif 
    168195 
    169         variable dummy= ThreadGroupRelease(mt) 
    170          
    171196        return(0) 
    172197End 
  • sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/Cylinder_2D_v40.ipf

    r570 r753  
    122122// 
    123123 
    124 //threaded version of the function 
    125 ThreadSafe Function Cylinder2D_T(cw,zw,xw,yw,p1,p2) 
    126         WAVE cw,zw,xw,yw 
    127         Variable p1,p2 
     124////threaded version of the function 
     125//ThreadSafe Function Cylinder2D_T(cw,zw,xw,yw,p1,p2) 
     126//      WAVE cw,zw,xw,yw 
     127//      Variable p1,p2 
     128//       
     129//#if exists("Cylinder_2DX")                    //to hide the function if XOP not installed 
     130// 
     131//      Make/O/D/N=12 Cyl2D_tmp                         // there seems to be no speed penalty for doing this... 
     132//      Cyl2D_tmp = cw 
     133//      Cyl2D_tmp[11] = 25                                      // hard-wire the number of integration points 
     134//      Cyl2D_tmp[5] = 0                                                // send a background of zero 
     135//       
     136//      zw[p1,p2]= Cylinder_2DX(Cyl2D_tmp,xw,yw) + cw[5]                //add in the proper background here 
     137// 
     138//#endif 
     139// 
     140//      return 0 
     141//End 
     142// 
     143//// 
     144////  Fit function that is actually a wrapper to dispatch the calculation to N threads 
     145//// 
     146//// nthreads is 1 or an even number, typically 2 
     147//// it doesn't matter if npt is odd. In this case, fractional point numbers are passed 
     148//// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points 
     149//// and the points "2.5" and "3.5" evaluate correctly as 2 and 3 
     150//// 
     151//Function Cylinder2D(cw,zw,xw,yw) : FitFunc 
     152//      Wave cw,zw,xw,yw 
     153//       
     154//      Variable npt=numpnts(yw) 
     155//      Variable ii,nthreads= ThreadProcessorCount 
     156//      variable mt= ThreadGroupCreate(nthreads) 
     157// 
     158////    Variable t1=StopMSTimer(-2) 
     159//       
     160//      for(ii=0;ii<nthreads;ii+=1) 
     161//      //      Print (ii*npt/nthreads),((ii+1)*npt/nthreads-1) 
     162//              ThreadStart mt,ii,Cylinder2D_T(cw,zw,xw,yw,(ii*npt/nthreads),((ii+1)*npt/nthreads-1)) 
     163//      endfor 
     164// 
     165//      do 
     166//              variable tgs= ThreadGroupWait(mt,100) 
     167//      while( tgs != 0 ) 
     168// 
     169//      variable dummy= ThreadGroupRelease(mt) 
     170//       
     171////    Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6 
     172//       
     173//      return(0) 
     174//End 
     175 
     176 
     177/// now using the MultiThread keyword. as of Igor 6.20, the manual threading 
     178// as above gives a wave read error (index out of range). Same code works fine in Igor 6.12 
     179Function Cylinder2D(cw,zw,xw,yw) : FitFunc 
     180        Wave cw,zw,xw,yw 
    128181         
     182        //      Variable t1=StopMSTimer(-2) 
     183 
    129184#if exists("Cylinder_2DX")                      //to hide the function if XOP not installed 
    130185 
     
    134189        Cyl2D_tmp[5] = 0                                                // send a background of zero 
    135190         
    136         zw[p1,p2]= Cylinder_2DX(Cyl2D_tmp,xw,yw) + cw[5]                //add in the proper background here 
     191        MultiThread zw = Cylinder_2DX(Cyl2D_tmp,xw,yw) + cw[5]          //add in the proper background here 
    137192 
    138193#endif 
    139194 
    140         return 0 
    141 End 
    142  
    143 // 
    144 //  Fit function that is actually a wrapper to dispatch the calculation to N threads 
    145 // 
    146 // nthreads is 1 or an even number, typically 2 
    147 // it doesn't matter if npt is odd. In this case, fractional point numbers are passed 
    148 // and the wave indexing works just fine - I tested this with test waves of 7 and 8 points 
    149 // and the points "2.5" and "3.5" evaluate correctly as 2 and 3 
    150 // 
    151 Function Cylinder2D(cw,zw,xw,yw) : FitFunc 
    152         Wave cw,zw,xw,yw 
    153          
    154         Variable npt=numpnts(yw) 
    155         Variable i,nthreads= ThreadProcessorCount 
    156         variable mt= ThreadGroupCreate(nthreads) 
    157  
    158 //      Variable t1=StopMSTimer(-2) 
    159          
    160         for(i=0;i<nthreads;i+=1) 
    161         //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1) 
    162                 ThreadStart mt,i,Cylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) 
    163         endfor 
    164  
    165         do 
    166                 variable tgs= ThreadGroupWait(mt,100) 
    167         while( tgs != 0 ) 
    168  
    169         variable dummy= ThreadGroupRelease(mt) 
    170          
    171195//      Print "elapsed time = ",(StopMSTimer(-2) - t1)/1e6 
    172196         
  • sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/Ellipsoid2D_v40.ipf

    r570 r753  
    123123//      return(0) 
    124124//End 
     125//// 
    125126// 
    126  
    127 //threaded version of the function 
    128 ThreadSafe Function Ellipsoid2D_T(cw,zw,xw,yw,p1,p2) 
    129         WAVE cw,zw,xw,yw 
    130         Variable p1,p2 
    131          
    132 #if exists("Ellipsoid_2DX")                     //to hide the function if XOP not installed 
    133  
    134         Make/O/D/N=13 Ellip2D_tmp 
    135         Ellip2D_tmp = cw 
    136         Ellip2D_tmp[12] = 25 
    137         Ellip2D_tmp[5] = 0              //pass in a zero background and add it in later 
    138          
    139         zw[p1,p2]= Ellipsoid_2DX(Ellip2D_tmp,xw,yw) + cw[5] 
    140          
    141 #endif 
    142  
    143         return 0 
    144 End 
     127////threaded version of the function 
     128//ThreadSafe Function Ellipsoid2D_T(cw,zw,xw,yw,p1,p2) 
     129//      WAVE cw,zw,xw,yw 
     130//      Variable p1,p2 
     131//       
     132//#if exists("Ellipsoid_2DX")                   //to hide the function if XOP not installed 
     133// 
     134//      Make/O/D/N=13 Ellip2D_tmp 
     135//      Ellip2D_tmp = cw 
     136//      Ellip2D_tmp[12] = 25 
     137//      Ellip2D_tmp[5] = 0              //pass in a zero background and add it in later 
     138//       
     139//      zw[p1,p2]= Ellipsoid_2DX(Ellip2D_tmp,xw,yw) + cw[5] 
     140//       
     141//#endif 
     142// 
     143//      return 0 
     144//End 
     145// 
     146//// 
     147////  Fit function that is actually a wrapper to dispatch the calculation to N threads 
     148//// 
     149//// nthreads is 1 or an even number, typically 2 
     150//// it doesn't matter if npt is odd. In this case, fractional point numbers are passed 
     151//// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points 
     152//// and the points "2.5" and "3.5" evaluate correctly as 2 and 3 
     153//// 
     154//Function Ellipsoid2D(cw,zw,xw,yw) : FitFunc 
     155//      Wave cw,zw,xw,yw 
     156//       
     157//      Variable npt=numpnts(yw) 
     158//      Variable i,nthreads= ThreadProcessorCount 
     159//      variable mt= ThreadGroupCreate(nthreads) 
     160// 
     161//      for(i=0;i<nthreads;i+=1) 
     162//      //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1) 
     163//              ThreadStart mt,i,Ellipsoid2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) 
     164//      endfor 
     165// 
     166//      do 
     167//              variable tgs= ThreadGroupWait(mt,100) 
     168//      while( tgs != 0 ) 
     169// 
     170//      variable dummy= ThreadGroupRelease(mt) 
     171//       
     172//      return(0) 
     173//End 
    145174 
    146175// 
     
    155184        Wave cw,zw,xw,yw 
    156185         
    157         Variable npt=numpnts(yw) 
    158         Variable i,nthreads= ThreadProcessorCount 
    159         variable mt= ThreadGroupCreate(nthreads) 
     186#if exists("Ellipsoid_2DX")                     //to hide the function if XOP not installed 
    160187 
    161         for(i=0;i<nthreads;i+=1) 
    162         //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1) 
    163                 ThreadStart mt,i,Ellipsoid2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) 
    164         endfor 
    165  
    166         do 
    167                 variable tgs= ThreadGroupWait(mt,100) 
    168         while( tgs != 0 ) 
    169  
    170         variable dummy= ThreadGroupRelease(mt) 
     188        Make/O/D/N=13 Ellip2D_tmp 
     189        Ellip2D_tmp = cw 
     190        Ellip2D_tmp[12] = 25 
     191        Ellip2D_tmp[5] = 0              //pass in a zero background and add it in later 
     192         
     193        MultiThread zw= Ellipsoid_2DX(Ellip2D_tmp,xw,yw) + cw[5] 
     194         
     195#endif 
    171196         
    172197        return(0) 
  • sans/Dev/trunk/NCNR_User_Procedures/Analysis/Models/Models_2D/EllipticalCylinder2D_v40.ipf

    r570 r753  
    126126// 
    127127 
    128 //threaded version of the function 
    129 ThreadSafe Function EllipticalCylinder2D_T(cw,zw,xw,yw,p1,p2) 
    130         WAVE cw,zw,xw,yw 
    131         Variable p1,p2 
    132          
    133 #if exists("EllipticalCylinder_2DX")                    //to hide the function if XOP not installed 
    134  
    135         Make/O/D/N=15 EllCyl2D_tmp 
    136         EllCyl2D_tmp = cw 
    137         EllCyl2D_tmp[14] = 25 
    138         EllCyl2D_tmp[6] = 0             //pass in a zero background and add it in later 
    139          
    140         zw[p1,p2]= EllipticalCylinder_2DX(EllCyl2D_tmp,xw,yw) + cw[6] 
    141          
    142 #endif 
    143  
    144         return 0 
    145 End 
     128////threaded version of the function 
     129//ThreadSafe Function EllipticalCylinder2D_T(cw,zw,xw,yw,p1,p2) 
     130//      WAVE cw,zw,xw,yw 
     131//      Variable p1,p2 
     132//       
     133//#if exists("EllipticalCylinder_2DX")                  //to hide the function if XOP not installed 
     134// 
     135//      Make/O/D/N=15 EllCyl2D_tmp 
     136//      EllCyl2D_tmp = cw 
     137//      EllCyl2D_tmp[14] = 25 
     138//      EllCyl2D_tmp[6] = 0             //pass in a zero background and add it in later 
     139//       
     140//      zw[p1,p2]= EllipticalCylinder_2DX(EllCyl2D_tmp,xw,yw) + cw[6] 
     141//       
     142//#endif 
     143// 
     144//      return 0 
     145//End 
     146// 
     147//// 
     148////  Fit function that is actually a wrapper to dispatch the calculation to N threads 
     149//// 
     150//// nthreads is 1 or an even number, typically 2 
     151//// it doesn't matter if npt is odd. In this case, fractional point numbers are passed 
     152//// and the wave indexing works just fine - I tested this with test waves of 7 and 8 points 
     153//// and the points "2.5" and "3.5" evaluate correctly as 2 and 3 
     154//// 
     155//Function EllipticalCylinder2D(cw,zw,xw,yw) : FitFunc 
     156//      Wave cw,zw,xw,yw 
     157//       
     158//      Variable npt=numpnts(yw) 
     159//      Variable i,nthreads= ThreadProcessorCount 
     160//      variable mt= ThreadGroupCreate(nthreads) 
     161// 
     162//      for(i=0;i<nthreads;i+=1) 
     163//      //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1) 
     164//              ThreadStart mt,i,EllipticalCylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) 
     165//      endfor 
     166// 
     167//      do 
     168//              variable tgs= ThreadGroupWait(mt,100) 
     169//      while( tgs != 0 ) 
     170// 
     171//      variable dummy= ThreadGroupRelease(mt) 
     172//       
     173//      return(0) 
     174//End 
    146175 
    147176// 
     
    156185        Wave cw,zw,xw,yw 
    157186         
    158         Variable npt=numpnts(yw) 
    159         Variable i,nthreads= ThreadProcessorCount 
    160         variable mt= ThreadGroupCreate(nthreads) 
     187#if exists("EllipticalCylinder_2DX")                    //to hide the function if XOP not installed 
    161188 
    162         for(i=0;i<nthreads;i+=1) 
    163         //      Print (i*npt/nthreads),((i+1)*npt/nthreads-1) 
    164                 ThreadStart mt,i,EllipticalCylinder2D_T(cw,zw,xw,yw,(i*npt/nthreads),((i+1)*npt/nthreads-1)) 
    165         endfor 
    166  
    167         do 
    168                 variable tgs= ThreadGroupWait(mt,100) 
    169         while( tgs != 0 ) 
    170  
    171         variable dummy= ThreadGroupRelease(mt) 
     189        Make/O/D/N=15 EllCyl2D_tmp 
     190        EllCyl2D_tmp = cw 
     191        EllCyl2D_tmp[14] = 25 
     192        EllCyl2D_tmp[6] = 0             //pass in a zero background and add it in later 
     193         
     194        MultiThread zw= EllipticalCylinder_2DX(EllCyl2D_tmp,xw,yw) + cw[6] 
     195         
     196#endif 
    172197         
    173198        return(0) 
  • sans/Dev/trunk/NCNR_User_Procedures/Analysis/Packages/Wrapper_v40.ipf

    r751 r753  
    13431343                                Button button_2D_0,disable=0            //visible again, and enabled 
    13441344                                Button button_2D_1,disable=0 
     1345                                 
     1346                                CheckBox check_6,disable=1                      //info box and residual check, remove these from view 
     1347                                CheckBox check_7,disable=1 
    13451348                        else 
    13461349                                //print "unchecked, change them back to 1D" 
     
    13521355                                Button button_2D_0,disable=3    //hide the extra 2D buttons, and disable 
    13531356                                Button button_2D_1,disable=3 
     1357                                 
     1358                                CheckBox check_6,disable=0                      //info box and residual check, bring them back 
     1359                                CheckBox check_7,disable=0 
    13541360                        endif 
    13551361                        break 
Note: See TracChangeset for help on using the changeset viewer.