BIPS/Examples/C++: Difference between revisions

From RidgeRun Developer Wiki
No edit summary
No edit summary
Line 3: Line 3:
</noinclude>
</noinclude>


'''One to one example'''
== Introduction ==
 
The C++ examples takes into account two possible cases:
 
* One-to-one communication
* One-to-many in broadcast communication
 
The example binaries are compiled after building. If the build directory is <code>build</code>:


Example using Command Line Interface (CLI).
Remember the project structure necessary:
<pre>
<pre>
|- src
├── src
      |- examples
   └── examples
          |- one-to-one
        └── one-to-one
              - consumer
           ├── consumer
              - producer
           └── producer
</pre>
</pre>


So, move into one-to-one folder. Using the following command:
=== Executable options ===
<pre>
 
cd src/example/one-to-one
Both executables have the same CLI options. Please, take them into account:
</pre>


Execute in different terminals a producer and consumer. In both cases, you can change or use some arguments. If you want to know what options you can be used, execute:
<pre>
./producer -h
</pre>
Then, the arguments and information of use will be returned:
<pre>
<pre>
Usage:
Usage:
        producer [OPTION]...
consumer/producer [OPTION]...
Optional arguments:
Optional arguments:
        -h, --help: Display this message and exit
-h, --help: Display this message and exit
        --backend BACKEND: Use the specified inter-process shared memory
--backend BACKEND: Use the specified inter-process shared memory
                            backend; BACKEND can be 'shm' or 'nvsci'
                    backend; BACKEND can be 'shm' or 'nvsci'. Default: 'shm'
        --channel CHANNEL: Connect to the specified shared memory channel.
--channel CHANNEL: Connect to the specified shared memory channel.
                            CHANNEL preferably starts with a '/' character
                    CHANNEL preferably starts with a '/' character
                            followed by up to 255 characters, none of which
                    followed by up to 255 characters, none of which
                            are slashes
                    are slashes. Default: channel
        --num-buffers NUM_BUFFERS: Indicate how many shared memory buffers
--num-buffers NUM_BUFFERS: Indicate how many shared memory buffers
                                    to create; NUM_BUFFERS can be a positive
                            to create; NUM_BUFFERS can be a positive
                                    integer
                            integer. Default: 10
        --buffer-size BUFFER_SIZE: Indicate the size in bytes of a shared
--buffer-size BUFFER_SIZE: Indicate the size in bytes of a shared
                                    memory buffer; BUFFER_SIZE can be a
                            memory buffer; BUFFER_SIZE can be a
                                    positive integer
                            positive integer. Default 33 MB
        --exec-order ORDER: Follow execution order for buffer processing
--exec-order ORDER: Follow execution order for buffer processing
                            specified in ORDER; ORDER can be 'in-order' or
                    specified in ORDER; ORDER can be 'in-order' or
                            'out-of-order'
                    'out-of-order'. Default 'in-order'
        --process-size PROCESS_SIZE: Indicate the size in bytes of data to
--process-size PROCESS_SIZE: Indicate the size in bytes of data to
                                      write to/read from shared memory
                              write to/read from shared memory
                                      during execution; PROCESS_SIZE can be
                              during execution; PROCESS_SIZE can be
                                      a integer smaller than BUFFER_SIZE
                              a integer smaller than BUFFER_SIZE. Default:
        --timeout TIMEOUT: Indicate how long to wait for available buffers
                                      same as BUFFER_SIZE
                            before throwing a timeout error; TIMEOUT is
--timeout TIMEOUT: Indicate how long to wait for available buffers
                            measured in seconds and can be a positive
                    before throwing a timeout error; TIMEOUT is
                            integer
                    measured in seconds and can be a positive
        --num-iterations NUM-ITERATIONS: Indicate how long many buffer
                    integer. Default: 15 secs
                            processing iterations to run before exiting;
--num-iterations NUM-ITERATIONS: Indicate how long many buffer
                            NUM-ITERATIONS can be a positive integer
                    processing iterations to run before exiting;
                    NUM-ITERATIONS can be a positive integer. Default: 100
--logfile LOGFILE: Indicate name of file to log to. Default: consumer.log
                            or producer.log
</pre>
</pre>
You can use the defaults.
'''Note''': It is recommended to match the configurations in both executables except in the logfile.
== Running the examples ==
=== One-to-one example ===
1. Open two different terminals: one for producer and another for consumer.
2. In terminal 1, execute the producer:
<syntaxhighlight lang=bash>
./producer
</syntaxhighlight>
3. In terminal 2, execute the consumer:
<syntaxhighlight lang=bash>
./consumer
</syntaxhighlight>
=== One-to-many example ===
1. Open two different terminals: one for producer and another for consumer.
2. In terminal 1, execute the producer:
<syntaxhighlight lang=bash>
./producer
</syntaxhighlight>
3. In terminal 2, execute two consumers:
<syntaxhighlight lang=bash>
./consumer --logfile consumer1.log & ./consumer --logfile consumer2.log
</syntaxhighlight>
You can execute these two consumers in two different consoles as well.


<noinclude>
<noinclude>
{{BIPS/Foot||}}
{{BIPS/Foot||}}
</noinclude>
</noinclude>

Revision as of 20:00, 14 December 2022



  Index  





Introduction

The C++ examples takes into account two possible cases:

  • One-to-one communication
  • One-to-many in broadcast communication

The example binaries are compiled after building. If the build directory is build:

├── src
    └── examples
        └── one-to-one
            ├── consumer
            └── producer

Executable options

Both executables have the same CLI options. Please, take them into account:

Usage:
	 consumer/producer [OPTION]...
Optional arguments:
	 -h, --help: Display this message and exit
	 --backend BACKEND: Use the specified inter-process shared memory
	                    backend; BACKEND can be 'shm' or 'nvsci'. Default: 'shm'
	 --channel CHANNEL: Connect to the specified shared memory channel.
	                    CHANNEL preferably starts with a '/' character
	                    followed by up to 255 characters, none of which
	                    are slashes. Default: channel
	 --num-buffers NUM_BUFFERS: Indicate how many shared memory buffers
	                            to create; NUM_BUFFERS can be a positive
	                            integer. Default: 10
	 --buffer-size BUFFER_SIZE: Indicate the size in bytes of a shared
	                            memory buffer; BUFFER_SIZE can be a
	                            positive integer. Default 33 MB
	 --exec-order ORDER: Follow execution order for buffer processing
	                     specified in ORDER; ORDER can be 'in-order' or
	                     'out-of-order'. Default 'in-order'
	 --process-size PROCESS_SIZE: Indicate the size in bytes of data to
	                              write to/read from shared memory
	                              during execution; PROCESS_SIZE can be
	                              a integer smaller than BUFFER_SIZE. Default:
                                      same as BUFFER_SIZE
	 --timeout TIMEOUT: Indicate how long to wait for available buffers
	                    before throwing a timeout error; TIMEOUT is
	                    measured in seconds and can be a positive
	                    integer. Default: 15 secs
	 --num-iterations NUM-ITERATIONS: Indicate how long many buffer
	                    processing iterations to run before exiting;
	                    NUM-ITERATIONS can be a positive integer. Default: 100
	 --logfile LOGFILE: Indicate name of file to log to. Default: consumer.log
                            or producer.log

You can use the defaults.

Note: It is recommended to match the configurations in both executables except in the logfile.

Running the examples

One-to-one example

1. Open two different terminals: one for producer and another for consumer.

2. In terminal 1, execute the producer:

./producer

3. In terminal 2, execute the consumer:

./consumer

One-to-many example

1. Open two different terminals: one for producer and another for consumer.

2. In terminal 1, execute the producer:

./producer

3. In terminal 2, execute two consumers:

./consumer --logfile consumer1.log & ./consumer --logfile consumer2.log

You can execute these two consumers in two different consoles as well.



  Index