Changes between Version 30 and Version 31 of DRM4G/Tutorial
- Timestamp:
- Jun 27, 2016 9:24:10 AM (6 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
DRM4G/Tutorial
v30 v31 235 235 {{{ 236 236 #!cpp 237 #include <stdio.h> 238 #include <string.h> 239 240 int main (int argc, char** args) 237 #include <stdio.h> 238 #include <string.h> 239 #include <stdlib.h> 240 241 int main (int argc, char** args) 242 { 243 int task_id; 244 int total_tasks; 245 long long int n; 246 long long int i; 247 248 double l_sum, x, h; 249 250 task_id = atoi(args[1]); 251 total_tasks = atoi(args[2]); 252 n = atoll(args[3]); 253 254 fprintf(stderr, "task_id=%d total_tasks=%d n=%lld\n", task_id, total_tasks, n); 255 256 h = 1.0/n; 257 258 l_sum = 0.0; 259 260 for (i = task_id; i < n; i += total_tasks) 241 261 { 242 int task_id; 243 int total_tasks; 244 long long int n; 245 long long int i; 246 247 double l_sum, x, h; 248 249 task_id = atoi(args[1]); 250 total_tasks = atoi(args[2]); 251 n = atoll(args[3]); 252 253 fprintf(stderr, "task_id=%d total_tasks=%d n=%lld\n", task_id, total_tasks, n); 254 255 h = 1.0/n; 256 257 l_sum = 0.0; 258 259 for (i = task_id; i < n; i += total_tasks) 260 { 261 x = (i + 0.5)*h; 262 l_sum += 4.0/(1.0 + x*x); 263 } 264 265 l_sum *= h; 266 267 printf("%0.12g\n", l_sum); 268 269 return 0; 262 x = (i + 0.5)*h; 263 l_sum += 4.0/(1.0 + x*x); 270 264 } 271 }}} 272 273 * Job template : 274 {{{ 275 EXECUTABLE = pi 265 266 l_sum *= h; 267 268 printf("%0.12g\n", l_sum); 269 270 return 0; 271 } 272 }}} 273 274 * DRM4G job template : 275 {{{ 276 EXECUTABLE = pi.sh 276 277 ARGUMENTS = ${TASK_ID} ${TOTAL_TASKS} 100000 277 278 STDOUT_FILE = stdout_file.${TASK_ID} 278 279 STDERR_FILE = stderr_file.${TASK_ID} 280 INPUT_FILES = pi.c, pi.sh 281 }}} 282 283 * pi.sh script: 284 {{{ 285 #!sh 286 #!/bin/bash 287 gcc -o pi pi.c 288 chmod +x ./pi 289 ./pi $@ 279 290 }}} 280 291 == MPI Jobs ==