Changes between Version 26 and Version 27 of DRM4G/Tutorial


Ignore:
Timestamp:
Jun 26, 2016 7:59:41 PM (6 years ago)
Author:
carlos
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DRM4G/Tutorial

    v26 v27  
    231231== Array Jobs ==
    232232
     233=== C Code ===
     234{{{
     235#!cpp
     236  #include <stdio.h>
     237  #include <string.h>
     238 
     239  int main (int argc, char** args)
     240  {
     241    int task_id;
     242    int total_tasks;
     243    long long int n;
     244    long long int i;
     245 
     246    double l_sum, x, h;
     247 
     248    task_id = atoi(args[1]);
     249    total_tasks = atoi(args[2]);
     250    n = atoll(args[3]);
     251 
     252    fprintf(stderr, "task_id=%d total_tasks=%d n=%lld\n", task_id, total_tasks, n);
     253 
     254    h = 1.0/n;
     255 
     256    l_sum = 0.0;
     257 
     258    for (i = task_id; i < n; i += total_tasks)
     259    {
     260      x = (i + 0.5)*h;
     261      l_sum += 4.0/(1.0 + x*x);
     262    }
     263 
     264    l_sum *= h;
     265 
     266    printf("%0.12g\n", l_sum);
     267 
     268    return 0;
     269  }
     270}}}
     271
    233272=== Job Template ===
    234273{{{