GNUnet  0.11.x
Macros | Functions
gnunet_mpi_test.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include <mpi.h>
Include dependency graph for gnunet_mpi_test.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "gnunet-mpi-test", __VA_ARGS__)
 Generic logging shorthand. More...
 

Functions

int main (int argc, char *argv[])
 

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "gnunet-mpi-test", __VA_ARGS__)

Generic logging shorthand.

Definition at line 8 of file gnunet_mpi_test.c.

Referenced by main().

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 12 of file gnunet_mpi_test.c.

References argv2, filename, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_DISK_directory_remove(), GNUNET_DISK_fn_write(), GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_GROUP_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_malloc, GNUNET_NO, GNUNET_OK, GNUNET_OS_INHERIT_STD_ALL, GNUNET_OS_process_status(), GNUNET_OS_start_process_vap(), GNUNET_SYSERR, LOG, msg, pid, and ret.

13 {
14  char *msg;
15  char *filename;
16  char **argv2;
17  struct GNUNET_OS_Process *proc;
18  unsigned long code;
19  pid_t pid;
20  enum GNUNET_OS_ProcessStatusType proc_status;
21  int ntasks;
22  int rank;
23  int msg_size;
24  int ret;
25  unsigned int cnt;
26 
27  ret = GNUNET_SYSERR;
28  if (argc < 2)
29  {
30  printf ("Need arguments: gnunet-mpi-test <cmd> <cmd_args>");
31  return 1;
32  }
33  if (MPI_SUCCESS != MPI_Init (&argc, &argv))
34  {
35  GNUNET_break (0);
36  return 1;
37  }
38  if (MPI_SUCCESS != MPI_Comm_size (MPI_COMM_WORLD, &ntasks))
39  {
40  GNUNET_break (0);
41  goto finalize;
42  }
43  if (MPI_SUCCESS != MPI_Comm_rank (MPI_COMM_WORLD, &rank))
44  {
45  GNUNET_break (0);
46  goto finalize;
47  }
48  pid = getpid ();
49  (void) GNUNET_asprintf (&filename, "%d-%d.mpiout", (int) pid, rank);
50  msg_size = GNUNET_asprintf (&msg, "My rank is: %d\n", rank);
51  printf ("%s", msg);
52  (void) GNUNET_DISK_directory_remove (filename);
53  if (GNUNET_OK ==
54  GNUNET_DISK_fn_write (filename, msg, msg_size,
59  ret = GNUNET_OK;
60  GNUNET_free (filename);
61  GNUNET_free (msg);
62  if (GNUNET_OK != ret)
63  {
64  GNUNET_break (0);
65  goto finalize;
66  }
67 
68  ret = GNUNET_SYSERR;
69  argv2 = GNUNET_malloc (sizeof(char *) * (argc));
70  for (cnt = 1; cnt < argc; cnt++)
71  argv2[cnt - 1] = argv[cnt];
72  proc =
74  NULL, NULL, argv2[0], argv2);
75  if (NULL == proc)
76  {
77  printf ("Cannot exec\n");
78  GNUNET_free (argv2);
79  goto finalize;
80  }
81  do
82  {
83  (void) sleep (1);
84  ret = GNUNET_OS_process_status (proc, &proc_status, &code);
85  }
86  while (GNUNET_NO == ret);
87  GNUNET_free (argv2);
88  GNUNET_assert (GNUNET_NO != ret);
89  if (GNUNET_OK == ret)
90  {
91  if (0 != code)
92  {
93  LOG (GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n");
94  ret = GNUNET_SYSERR;
95  GNUNET_break (0);
96  goto finalize;
97  }
98  }
99  else
100  GNUNET_break (0);
101 
102 finalize:
103  (void) MPI_Finalize ();
104  if (GNUNET_OK == ret)
105  return 0;
106  printf ("Something went wrong\n");
107  return 1;
108 }
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_OS_Process * GNUNET_OS_start_process_vap(enum GNUNET_OS_InheritStdioFlags std_inheritance, struct GNUNET_DISK_PipeHandle *pipe_stdin, struct GNUNET_DISK_PipeHandle *pipe_stdout, struct GNUNET_DISK_PipeHandle *pipe_stderr, const char *filename, char *const argv[])
Start a process.
Definition: os_priority.c:604
int GNUNET_OS_process_status(struct GNUNET_OS_Process *proc, enum GNUNET_OS_ProcessStatusType *type, unsigned long *code)
Retrieve the status of a process.
Definition: os_priority.c:946
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Use this option to have all of the standard streams (stdin, stdout and stderror) be inherited...
GNUNET_OS_ProcessStatusType
Process status types.
static char * filename
static char ** argv2
The arguments including the binary to spawn.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
Definition: disk.c:725
enum GNUNET_GenericReturnValue GNUNET_DISK_directory_remove(const char *filename)
Remove all files in a directory (rm -rf).
Definition: disk.c:1062
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
#define LOG(kind,...)
Generic logging shorthand.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function: