216 | | * C code : |
217 | | {{{ |
218 | | #!cpp |
219 | | #include <stdio.h> |
220 | | #include <string.h> |
221 | | #include <stdlib.h> |
222 | | |
223 | | int main (int argc, char** args) |
224 | | { |
225 | | int task_id; |
226 | | int total_tasks; |
227 | | long long int n; |
228 | | long long int i; |
229 | | |
230 | | double l_sum, x, h; |
231 | | |
232 | | task_id = 0; |
233 | | total_tasks = 100; |
234 | | n = atoll(args[1]); |
235 | | |
236 | | fprintf(stderr, "task_id=%d total_tasks=%d n=%lld\n", task_id, total_tasks, n); |
237 | | |
238 | | h = 1.0/n; |
239 | | |
240 | | l_sum = 0.0; |
241 | | |
242 | | for (i = task_id; i < n; i += total_tasks) |
243 | | { |
244 | | x = (i + 0.5)*h; |
245 | | l_sum += 4.0/(1.0 + x*x); |
246 | | } |
247 | | |
248 | | l_sum *= h; |
249 | | |
250 | | printf("%0.12g\n", l_sum); |
251 | | |
252 | | return 0; |
253 | | } |
254 | | }}} |
| 216 | * C binary |