Changes between Version 29 and Version 30 of DRM4G/Tutorial


Ignore:
Timestamp:
Jun 27, 2016 9:16:51 AM (6 years ago)
Author:
carlos
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DRM4G/Tutorial

    v29 v30  
    193193{{{
    194194#!cpp
    195   #include <stdio.h>
    196   #include <string.h>
    197  
    198   int main (int argc, char** args)
     195#include <stdio.h>
     196#include <string.h>
     197#include <stdlib.h>
     198
     199int main (int argc, char** args)
     200{
     201  int task_id;
     202  int total_tasks;
     203  long long int n;
     204  long long int i;
     205
     206  double l_sum, x, h;
     207
     208  task_id = atoi(args[1]);
     209  total_tasks = atoi(args[2]);
     210  n = atoll(args[3]);
     211
     212  fprintf(stderr, "task_id=%d total_tasks=%d n=%lld\n", task_id, total_tasks, n);
     213
     214  h = 1.0/n;
     215
     216  l_sum = 0.0;
     217
     218  for (i = task_id; i < n; i += total_tasks)
    199219  {
    200     int task_id;
    201     int total_tasks;
    202     long long int n;
    203     long long int i;
    204  
    205     double l_sum, x, h;
    206  
    207     task_id = atoi(args[1]);
    208     total_tasks = atoi(args[2]);
    209     n = atoll(args[3]);
    210  
    211     fprintf(stderr, "task_id=%d total_tasks=%d n=%lld\n", task_id, total_tasks, n);
    212  
    213     h = 1.0/n;
    214  
    215     l_sum = 0.0;
    216  
    217     for (i = task_id; i < n; i += total_tasks)
    218     {
    219       x = (i + 0.5)*h;
    220       l_sum += 4.0/(1.0 + x*x);
    221     }
    222  
    223     l_sum *= h;
    224  
    225     printf("%0.12g\n", l_sum);
    226  
    227     return 0;
     220    x = (i + 0.5)*h;
     221    l_sum += 4.0/(1.0 + x*x);
    228222  }
     223
     224  l_sum *= h;
     225
     226  printf("%0.12g\n", l_sum);
     227
     228  return 0;
     229}
    229230}}}
    230231