Changeset f2f67a6 in sasmodels for sasmodels/kernel_iq.c


Ignore:
Timestamp:
Apr 15, 2016 7:26:24 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
ae2b6b5, 38a9b07, eb97b11
Parents:
0ff62d4
Message:

reenable opencl; works on cpu but not gpu

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernel_iq.c

    r6e7ff6d rf2f67a6  
    5454  local ParameterBlock local_values;  // current parameter values 
    5555  double *pvec = (double *)(&local_values);  // Alias named parameters with a vector 
     56  double norm; 
     57 
     58  // number of active loops 
     59  const int num_active = details->num_active; 
    5660 
    5761  // Fill in the initial variables 
     
    6367  } 
    6468 
     69  // Monodisperse computation 
     70  if (num_active == 0) { 
     71    #ifdef INVALID 
     72    if (INVALID(local_values)) { return; } 
     73    #endif 
     74    norm = CALL_VOLUME(local_values); 
     75 
     76    const double scale = values[0]; 
     77    const double background = values[1]; 
     78    // result[nq] = norm; // Total volume normalization 
     79 
     80    #ifdef USE_OPENMP 
     81    #pragma omp parallel for 
     82    #endif 
     83    for (int i=0; i < nq; i++) { 
     84      double scattering = CALL_IQ(q, i, local_values); 
     85      result[i] = (norm>0. ? scale*scattering/norm + background : background); 
     86    } 
     87    return; 
     88  } 
     89 
     90#if MAX_PD > 0 
    6591  // If it is the first round initialize the result to zero, otherwise 
    6692  // assume that the previous result has been passed back. 
     
    75101      result[i] = 0.0; 
    76102    } 
    77   } 
    78  
    79   // Monodisperse computation 
    80   if (details->num_active == 0) { 
    81     #ifdef INVALID 
    82     if (INVALID(local_values)) { return; } 
    83     #endif 
    84  
    85     const double norm = CALL_VOLUME(local_values); 
    86     const double scale = values[0]; 
    87     const double background = values[1]; 
    88     #ifdef USE_OPENMP 
    89     #pragma omp parallel for 
    90     #endif 
    91     result[nq] = norm; // Total volume normalization 
    92     for (int i=0; i < nq; i++) { 
    93       double scattering = CALL_IQ(q, i, local_values); 
    94       result[i] = (norm>0. ? scale*scattering/norm + background : background); 
    95     } 
    96     return; 
    97   } 
    98  
    99 #if MAX_PD > 0 
    100   //printf("Entering polydispersity from %d to %d\n", pd_start, pd_stop); 
    101   // Since we are no longer looping over the entire polydispersity hypercube 
    102   // for each q, we need to track the normalization values between calls. 
    103   double norm = 0.0; 
     103    norm = 0.0; 
     104  } else { 
     105    norm = result[nq]; 
     106  } 
    104107 
    105108  // need product of weights at every Iq calc, so keep product of 
     
    119122  pd_index[0] = fast_length; 
    120123 
     124  // Number of coordinated indices 
     125  const int num_coord = details->num_coord; 
     126 
    121127  // Loop over the weights then loop over q, accumulating values 
    122128  for (int loop_index=pd_start; loop_index < pd_stop; loop_index++) { 
    123     // check if indices need to be updated 
     129    // check if fast loop needs to be reset 
    124130    if (pd_index[0] == fast_length) { 
    125       //printf("should be here with %d active\n", details->num_active); 
     131      //printf("should be here with %d active\n", num_active); 
    126132 
    127133      // Compute position in polydispersity hypercube 
    128       for (int k=0; k < details->num_active; k++) { 
     134      for (int k=0; k < num_active; k++) { 
    129135        pd_index[k] = (loop_index/details->pd_stride[k])%details->pd_length[k]; 
    130136        //printf("pd_index[%d] = %d\n",k,pd_index[k]); 
     
    134140      partial_weight = 1.0; 
    135141      //printf("partial weight %d: ", loop_index); 
    136       for (int k=1; k < details->num_active; k++) { 
     142      for (int k=1; k < num_active; k++) { 
    137143        double wi = weights[details->pd_offset[k] + pd_index[k]]; 
    138144        //printf("pd[%d]=par[%d]=%g ", k, details->pd_par[k], wi); 
     
    143149      // Update parameter offsets in weight vector 
    144150      //printf("slow %d: ", loop_index); 
    145       for (int k=0; k < details->num_coord; k++) { 
     151      for (int k=0; k < num_coord; k++) { 
    146152        int par = details->par_coord[k]; 
    147153        int coord = details->pd_coord[k]; 
     
    160166        // if theta is not coordinated with fast index, precompute spherical correction 
    161167        if (par == details->theta_par && !(details->par_coord[k]&1)) { 
    162           spherical_correction = fmax(fabs(cos(M_PI_180*pvec[details->theta_par])), 1e-6); 
     168          spherical_correction = fmax(fabs(cos(M_PI_180*pvec[details->theta_par])), 1.e-6); 
    163169        } 
    164170      } 
     
    170176    double weight = partial_weight*wi; 
    171177    //printf("fast %d: ", loop_index); 
    172     for (int k=0; k < details->num_coord; k++) { 
     178    for (int k=0; k < num_coord; k++) { 
    173179      if (details->pd_coord[k]&1) { 
    174180        const int par = details->par_coord[k]; 
     
    177183        // if theta is coordinated with fast index, compute spherical correction each time 
    178184        if (par == details->theta_par) { 
    179           spherical_correction = fmax(fabs(cos(M_PI_180*pvec[details->theta_par])), 1e-6); 
     185          spherical_correction = fmax(fabs(cos(M_PI_180*pvec[details->theta_par])), 1.e-6); 
    180186        } 
    181187      } 
     
    205211  } 
    206212 
    207   // Accumulate norm. 
    208   result[nq] += norm; 
    209  
    210213  // End of the PD loop we can normalize 
    211214  if (pd_stop >= details->total_pd) { 
     
    219222    } 
    220223  } 
     224 
     225  // Remember the updated norm. 
     226  result[nq] = norm; 
    221227#endif // MAX_PD > 0 
    222228} 
Note: See TracChangeset for help on using the changeset viewer.