Changes in sasmodels/kernel_iq.c [c57ee9e:70530778] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernel_iq.c
rc57ee9e r70530778 27 27 // parameters in the parameter table. 28 28 // CALL_VOLUME(table) : call the form volume function 29 // CALL_EFFECTIVE_RADIUS(type, table) : call the R_eff function30 29 // CALL_IQ(q, table) : call the Iq function for 1D calcs. 31 30 // CALL_IQ_A(q, table) : call the Iq function with |q| for 2D data. 32 // CALL_FQ(q, F1, F2, table) : call the Fq function for 1D calcs.33 // CALL_FQ_A(q, F1, F2, table) : call the Iq function with |q| for 2D data.34 31 // CALL_IQ_AC(qa, qc, table) : call the Iqxy function for symmetric shapes 35 32 // CALL_IQ_ABC(qa, qc, table) : call the Iqxy function for asymmetric shapes … … 39 36 // PROJECTION : equirectangular=1, sinusoidal=2 40 37 // see explore/jitter.py for definitions. 41 42 38 43 39 #ifndef _PAR_BLOCK_ // protected block so we can include this code twice. … … 192 188 QACRotation *rotation, 193 189 double qx, double qy, 194 double *qa _out, double *qc_out)190 double *qab_out, double *qc_out) 195 191 { 192 // Indirect calculation of qab, from qab^2 = |q|^2 - qc^2 196 193 const double dqc = rotation->R31*qx + rotation->R32*qy; 197 // Indirect calculation of qab, from qab^2 = |q|^2 - qc^2 198 const double dqa = sqrt(-dqc*dqc + qx*qx + qy*qy); 199 200 *qa_out = dqa; 194 const double dqab_sq = -dqc*dqc + qx*qx + qy*qy; 195 //*qab_out = sqrt(fabs(dqab_sq)); 196 *qab_out = dqab_sq > 0.0 ? sqrt(dqab_sq) : 0.0; 201 197 *qc_out = dqc; 202 198 } … … 274 270 #endif // _QABC_SECTION 275 271 272 276 273 // ==================== KERNEL CODE ======================== 277 #define COMPUTE_F1_F2 defined(CALL_FQ) 274 278 275 kernel 279 276 void KERNEL_NAME( … … 285 282 global const double *q, // nq q values, with padding to boundary 286 283 global double *result, // nq+1 return values, again with padding 287 const double cutoff, // cutoff in the dispersity weight product 288 int32_t effective_radius_type // which effective radius to compute 284 const double cutoff // cutoff in the dispersity weight product 289 285 ) 290 286 { … … 345 341 // version must loop over all q. 346 342 #ifdef USE_OPENCL 347 #if COMPUTE_F1_F2 348 double weight_norm = (pd_start == 0 ? 0.0 : result[2*nq]); 349 double weighted_volume = (pd_start == 0 ? 0.0 : result[2*nq+1]); 350 double weighted_radius = (pd_start == 0 ? 0.0 : result[2*nq+2]); 351 double this_F2 = (pd_start == 0 ? 0.0 : result[2*q_index+0]); 352 double this_F1 = (pd_start == 0 ? 0.0 : result[2*q_index+1]); 353 #else 354 double weight_norm = (pd_start == 0 ? 0.0 : result[nq]); 355 double weighted_volume = (pd_start == 0 ? 0.0 : result[nq+1]); 356 double weighted_radius = (pd_start == 0 ? 0.0 : result[nq+2]); 357 double this_result = (pd_start == 0 ? 0.0 : result[q_index]); 358 #endif 343 double pd_norm = (pd_start == 0 ? 0.0 : result[nq]); 344 double this_result = (pd_start == 0 ? 0.0 : result[q_index]); 359 345 #else // !USE_OPENCL 360 #if COMPUTE_F1_F2 361 double weight_norm = (pd_start == 0 ? 0.0 : result[2*nq]); 362 double weighted_volume = (pd_start == 0 ? 0.0 : result[2*nq+1]); 363 double weighted_radius = (pd_start == 0 ? 0.0 : result[2*nq+2]); 364 #else 365 double weight_norm = (pd_start == 0 ? 0.0 : result[nq]); 366 double weighted_volume = (pd_start == 0 ? 0.0 : result[nq+1]); 367 double weighted_radius = (pd_start == 0 ? 0.0 : result[nq+2]); 368 #endif 346 double pd_norm = (pd_start == 0 ? 0.0 : result[nq]); 369 347 if (pd_start == 0) { 370 348 #ifdef USE_OPENMP 371 349 #pragma omp parallel for 372 350 #endif 373 #if COMPUTE_F1_F2 374 // 2*nq for F^2,F pairs 375 for (int q_index=0; q_index < 2*nq; q_index++) result[q_index] = 0.0; 376 #else 377 for (int q_index=0; q_index < nq; q_index++) result[q_index] = 0.0; 378 #endif 351 for (int q_index=0; q_index < nq; q_index++) result[q_index] = 0.0; 379 352 } 380 //if (q_index==0) printf("start %d %g %g\n", pd_start, weighted_volume, result[0]);353 //if (q_index==0) printf("start %d %g %g\n", pd_start, pd_norm, result[0]); 381 354 #endif // !USE_OPENCL 382 355 … … 469 442 // inner loop and defines the macros that use them. 470 443 471 472 #if defined(CALL_FQ) // COMPUTE_F1_F2 is true 473 // unoriented 1D returning <F> and <F^2> 474 double qk; 475 double F1, F2; 476 #define FETCH_Q() do { qk = q[q_index]; } while (0) 477 #define BUILD_ROTATION() do {} while(0) 478 #define APPLY_ROTATION() do {} while(0) 479 #define CALL_KERNEL() CALL_FQ(qk,F1,F2,local_values.table) 480 481 #elif defined(CALL_FQ_A) 482 // unoriented 2D return <F> and <F^2> 483 double qx, qy; 484 double F1, F2; 485 #define FETCH_Q() do { qx = q[2*q_index]; qy = q[2*q_index+1]; } while (0) 486 #define BUILD_ROTATION() do {} while(0) 487 #define APPLY_ROTATION() do {} while(0) 488 #define CALL_KERNEL() CALL_FQ_A(sqrt(qx*qx+qy*qy),F1,F2,local_values.table) 489 490 #elif defined(CALL_IQ) 491 // unoriented 1D return <F^2> 444 #if defined(CALL_IQ) 445 // unoriented 1D 492 446 double qk; 493 447 #define FETCH_Q() do { qk = q[q_index]; } while (0) 494 448 #define BUILD_ROTATION() do {} while(0) 495 449 #define APPLY_ROTATION() do {} while(0) 496 #define CALL_KERNEL() CALL_IQ(qk, local_values.table)450 #define CALL_KERNEL() CALL_IQ(qk, local_values.table) 497 451 498 452 #elif defined(CALL_IQ_A) … … 528 482 #define APPLY_ROTATION() qabc_apply(&rotation, qx, qy, &qa, &qb, &qc) 529 483 #define CALL_KERNEL() CALL_IQ_ABC(qa, qb, qc, local_values.table) 530 531 484 #elif defined(CALL_IQ_XY) 532 485 // direct call to qx,qy calculator … … 542 495 // logic in the IQ_AC and IQ_ABC branches. This will become more important 543 496 // if we implement more projections, or more complicated projections. 544 #if defined(CALL_IQ) || defined(CALL_IQ_A) || defined(CALL_FQ) || defined(CALL_FQ_A) 545 // no orientation 497 #if defined(CALL_IQ) || defined(CALL_IQ_A) // no orientation 546 498 #define APPLY_PROJECTION() const double weight=weight0 547 499 #elif defined(CALL_IQ_XY) // pass orientation to the model … … 693 645 // Note: weight==0 must always be excluded 694 646 if (weight > cutoff) { 695 weighted_volume += weight * CALL_VOLUME(local_values.table); 696 #if COMPUTE_F1_F2 697 weight_norm += weight; 698 #endif 699 if (effective_radius_type != 0) { 700 weighted_radius += weight * CALL_EFFECTIVE_RADIUS(effective_radius_type, local_values.table); 701 } 647 pd_norm += weight * CALL_VOLUME(local_values.table); 702 648 BUILD_ROTATION(); 703 649 … … 747 693 } 748 694 #else // !MAGNETIC 749 #if COMPUTE_F1_F2 750 CALL_KERNEL(); // sets F1 and F2 by reference 751 #else 752 const double scattering = CALL_KERNEL(); 753 #endif 695 const double scattering = CALL_KERNEL(); 754 696 #endif // !MAGNETIC 755 697 //printf("q_index:%d %g %g %g %g\n", q_index, scattering, weight0); 756 698 757 699 #ifdef USE_OPENCL 758 #if COMPUTE_F1_F2 759 this_F2 += weight * F2; 760 this_F1 += weight * F1; 761 #else 762 this_result += weight * scattering; 763 #endif 700 this_result += weight * scattering; 764 701 #else // !USE_OPENCL 765 #if COMPUTE_F1_F2 766 result[2*q_index+0] += weight * F2; 767 result[2*q_index+1] += weight * F1; 768 #else 769 result[q_index] += weight * scattering; 770 #endif 702 result[q_index] += weight * scattering; 771 703 #endif // !USE_OPENCL 772 704 } 773 705 } 774 706 } 707 775 708 // close nested loops 776 709 ++step; … … 793 726 // Remember the current result and the updated norm. 794 727 #ifdef USE_OPENCL 795 #if COMPUTE_F1_F2 796 result[2*q_index+0] = this_F2; 797 result[2*q_index+1] = this_F1; 798 if (q_index == 0) { 799 result[2*nq+0] = weight_norm; 800 result[2*nq+1] = weighted_volume; 801 result[2*nq+2] = weighted_radius; 802 } 803 #else 804 result[q_index] = this_result; 805 if (q_index == 0) { 806 result[nq+0] = weight_norm; 807 result[nq+1] = weighted_volume; 808 result[nq+2] = weighted_radius; 809 } 810 #endif 811 812 //if (q_index == 0) printf("res: %g/%g\n", result[0], weigthed_volume); 728 result[q_index] = this_result; 729 if (q_index == 0) result[nq] = pd_norm; 730 //if (q_index == 0) printf("res: %g/%g\n", result[0], pd_norm); 813 731 #else // !USE_OPENCL 814 #if COMPUTE_F1_F2 815 result[2*nq] = weight_norm; 816 result[2*nq+1] = weighted_volume; 817 result[2*nq+2] = weighted_radius; 818 #else 819 result[nq] = weight_norm; 820 result[nq+1] = weighted_volume; 821 result[nq+2] = weighted_radius; 822 #endif 823 //printf("res: %g/%g\n", result[0], weighted_volume); 732 result[nq] = pd_norm; 733 //printf("res: %g/%g\n", result[0], pd_norm); 824 734 #endif // !USE_OPENCL 825 735 826 736 // ** clear the macros in preparation for the next kernel ** 827 #undef COMPUTE_F1_F2828 737 #undef PD_INIT 829 738 #undef PD_OPEN
Note: See TracChangeset
for help on using the changeset viewer.