API Reference Manual  1.46.0
odp_hello.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2016-2018 Linaro Limited
3  */
4 
16 #include <stdio.h>
17 #include <string.h>
18 
19 #include <odp_api.h>
20 
21 typedef struct {
22  int num;
23 } options_t;
24 
25 static int parse_args(int argc, char *argv[], options_t *opt)
26 {
27  static const char * const args[] = {"-n"};
28  int i, tmp;
29 
30  for (i = 1; i < argc; i++) {
31  if ((strcmp(argv[i], args[0]) == 0) && argv[i + 1] &&
32  (sscanf(argv[i + 1], "%i", &tmp) == 1)) {
33  opt->num = tmp;
34  i++;
35  } else {
36  printf("\nUsage:\n"
37  " [%s Number of iterations]\n\n",
38  args[0]);
39  return -1;
40  }
41  }
42 
43  return 0;
44 }
45 
46 int main(int argc, char *argv[])
47 {
48  odp_instance_t inst;
49  options_t opt;
50  int i;
51 
52  memset(&opt, 0, sizeof(opt));
53  opt.num = 1;
54 
55  if (parse_args(argc, argv, &opt))
56  return -1;
57 
58  if (odp_init_global(&inst, NULL, NULL)) {
59  printf("Global init failed.\n");
60  return -1;
61  }
62 
64  printf("Local init failed.\n");
65  return -1;
66  }
67 
68  for (i = 0; i < opt.num; i++) {
69  printf("Hello world from CPU %i!\n", odp_cpu_id());
71  }
72 
73  if (odp_term_local()) {
74  printf("Local term failed.\n");
75  return -1;
76  }
77 
78  if (odp_term_global(inst)) {
79  printf("Global term failed.\n");
80  return -1;
81  }
82 
83  return 0;
84 }
int odp_cpu_id(void)
CPU identifier.
int odp_init_local(odp_instance_t instance, odp_thread_type_t thr_type)
Thread local ODP initialization.
int odp_init_global(odp_instance_t *instance, const odp_init_t *params, const odp_platform_init_t *platform_params)
Global ODP initialization.
int odp_term_local(void)
Thread local ODP termination.
int odp_term_global(odp_instance_t instance)
Global ODP termination.
uint64_t odp_instance_t
ODP instance ID.
@ ODP_THREAD_CONTROL
Control thread.
#define ODP_TIME_SEC_IN_NS
A second in nanoseconds.
void odp_time_wait_ns(uint64_t ns)
Wait the specified number of nanoseconds.
The OpenDataPlane API.