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.

Function Documentation

◆ main()

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

Definition at line 12 of file gnunet_mpi_test.c.

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 
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);
53  if (GNUNET_OK ==
54  GNUNET_DISK_fn_write (filename, msg, msg_size,
59  ret = GNUNET_OK;
61  GNUNET_free (msg);
62  if (GNUNET_OK != ret)
63  {
64  GNUNET_break (0);
65  goto finalize;
66  }
67 
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);
89  if (GNUNET_OK == ret)
90  {
91  if (0 != code)
92  {
93  LOG (GNUNET_ERROR_TYPE_WARNING, "Child terminated abnormally\n");
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
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static char * filename
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
@ GNUNET_OK
Definition: gnunet_common.h:95
@ GNUNET_NO
Definition: gnunet_common.h:94
@ GNUNET_SYSERR
Definition: gnunet_common.h:93
#define LOG(kind,...)
Generic logging shorthand.
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:1085
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_GROUP_WRITE
Group can write.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_WARNING
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_free(ptr)
Wrapper around free.
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
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
GNUNET_OS_ProcessStatusType
Process status types.
@ GNUNET_OS_INHERIT_STD_ALL
Use this option to have all of the standard streams (stdin, stdout and stderror) be inherited.

References 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.

Here is the call graph for this function: