KMR
testdp.c
1 /* testdp.c (2014-02-04) */
2 
3 /* Test for kmrdp.cpp. */
4 
5 /* RUN THIS WITH "mpirun -np 4 a.out -tb testdp.table -ot 3". */
6 
7 #include <mpi.h>
8 #include <stdio.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11 #include <time.h>
12 
13 char xargs[4 * 1024];
14 
15 extern int application(int argc, char *argv[]);
16 int init(int argc, char *argv[]);
17 int (*application_init)(int argc, char *argv[]) = &init;
18 int fin(int argc, char *argv[]);
19 int (*application_fin)(int argc, char *argv[]) = &fin;
20 
21 int
22 init(int argc, char *argv[])
23 {
24  printf("testdp:init() called.\n");
25  fflush(0);
26  return 0;
27 }
28 
29 int
30 fin(int argc, char *argv[])
31 {
32  printf("testdp:fin() called.\n");
33  fflush(0);
34  return 0;
35 }
36 
37 int
38 application(int argc, char *argv[])
39 {
40  int nprocs, rank;
41  MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
42  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
43 
44  int n = (int)sizeof(xargs);
45  int p = 0;
46  for (int i = 0; i < argc; i++) {
47  int cc = snprintf(&xargs[p], (n - p), " %s", argv[i]);
48  p += cc;
49  if ((n - p) < 1) {
50  break;
51  }
52  }
53  time_t ct = time(0);
54  char *cs = ctime(&ct);
55  char clock[20];
56  if (cs != 0) {
57  snprintf(clock, sizeof(clock), "%s", &cs[11]);
58  clock[8] = '\0';
59  } else {
60  snprintf(clock, sizeof(clock), "(time unknown)");
61  }
62  printf("Starting application on rank %04d (creates a file %s) %s...\n"
63  "Args:%s\n", rank, argv[7], clock, xargs);
64 
65  sleep(3);
66 
67  char buf[256];
68  snprintf(buf, 256, "touch %s", argv[7]);
69  system(buf);
70  return 0;
71 }
int application(int argc, char *argv[])
Application Code Entry.
Definition: testdp.c:38