Back to the main page.

Bug 3099 - support multiple buffers in buffer.exe stand-alone application

Status CLOSED FIXED
Reported 2016-03-20 10:44:00 +0100
Modified 2016-06-14 16:14:55 +0200
Product: FieldTrip
Component: realtime
Version: unspecified
Hardware: PC
Operating System: Mac OS
Importance: P5 normal
Assigned to: Robert Oostenveld
URL:
Tags:
Depends on:
Blocks:
See also:

Robert Oostenveld - 2016-03-20 10:44:36 +0100

as discussed with Stephen, this is needed for https://github.com/eegsynth/eegsynth/issues/30


Robert Oostenveld - 2016-03-20 12:42:56 +0100

I wrote this --------------------------------------------------------------- /* * Copyright (C) 2016, Robert Oostenveld * Donders Centre for Cognitive Neuroimaging, Radboud University * Kapittelweg 29, 6525 EN Nijmegen, The Netherlands * * This application starts one or multiple FieldTrip buffers. * * Use as * ./buffer.exe * to start a buffer on the default port. * * Use as * ./buffer.exe 1972 * to start a buffer on the specific port. * * Use as * ./buffer.exe 1972,1973,1974 * to start multiple buffers on the specified ports * */ #include #include #include #include #include "buffer.h" #define COUNT_MAX 16 int main(int argc, char *argv[]) { int port[COUNT_MAX], count=0, rc, i; host_t host; pthread_t tid; check_datatypes(); if (argc>1) { /* parse the command line, it should contain a comma-separated list of ports */ char *bp; bp = strsep(&argv[1], ","); for (i=0; i<COUNT_MAX; i++) { if (bp) { port[count++] = atoi(bp); bp = strsep(&argv[1], ","); } else { break; } } } else { fprintf(stdout, "using defaults\n"); port[count++] = DEFAULT_PORT; } for (i=0; i<count; i++) { memcpy(host.name, DEFAULT_HOSTNAME, HOSTNAME_LENGTH); host.port = port[i]; fprintf(stdout, "starting buffer on %s:%d\n", host.name, host.port); /* start a separate thread for each buffer */ rc = pthread_create(&tid, NULL, tcpserver, (void *)(&host)); if (rc) { fprintf(stderr, "Error: return code from pthread_create() is %d\n", rc); exit(-1); } pthread_detach(tid); usleep(1000000); } while (1) { /* sleep until the process gets killed */ usleep(1000000); } return 0; } --------------------------------------------------------------- which works by itself. And then I realized that tcpserver and the code behind it (tcpsocket, dmarequest) are all working with the same memory pointers for the HDR, DAT and EVT memory segments. So the whole libbuffer is not written with multiple buffers in mind. Therefore I'll have to abandon this idea and look at something like http://stackoverflow.com/questions/356100/how-to-wait-in-bash-for-several-subprocesses-to-finish-and-return-exit-code-0 instead. </p>

Robert Oostenveld - 2016-03-20 15:15:11 +0100

The following bash script works to start jobs in parallel and to wait for them to finish. ----------------- #!/usr/bin/env bash # # Bash helper script to execute multiple instances of a program in parallel. # # This script is inspired by http://stackoverflow.com/questions/356100/how-to-wait-in-bash-for-several-subprocesses-to-finish-and-return-exit-code-0 # and by http://www.gnu.org/software/parallel/ # # Killing the child processes can be difficult if you only have the PID of the parent parallel script. Please see # http://stackoverflow.com/questions/392022/best-way-to-kill-all-child-processes/33556110#33556110 COMMAND=$1 ARGS=`echo $2 | tr ',' ' '` if [ -z "$COMMAND" ] ; then cat << EOF Use as: multiple <arg1,arg2,arg3> This will start in parallel command arg1 command arg2 command arg3 EOF exit fi if [ -z "$ARGS" ] ; then $COMMAND else echo $ARGS | xargs -IARG -n 1 -P 16 $COMMAND ARG fi


Robert Oostenveld - 2016-03-20 15:15:30 +0100

the bash script solves it


Robert Oostenveld - 2016-03-29 09:35:04 +0200

I have merged the various small changes to the buffer source code to the master branch and will delete the bug3099-buffer branch. mac011> git merge bug3099-buffer Updating 1b624e4..4851b0c Fast-forward realtime/bin/maci64/buffer | Bin 49580 -> 49580 bytes realtime/bin/maci64/buffer_rda | Bin 69716 -> 69716 bytes realtime/src/buffer/src/buffer.h | 5 +- realtime/src/buffer/src/dmarequest.c | 2 - realtime/src/buffer/src/tcprequest.c | 161 ++++++++++++------------ realtime/src/buffer/src/tcpserver.c | 401 ++++++++++++++++++++++++++++++------------------------------ realtime/src/buffer/src/tcpsocket.c | 7 +- realtime/src/buffer/src/util.c | 3 + realtime/src/buffer/test/demo_combined.c | 6 +- test/test_bug3089.m | 3 +- 10 files changed, 294 insertions(+), 294 deletions(-) mac011> git push upstream master X11 forwarding request failed on channel 0 You're about to push master, is that what you intended? [y|n] y Counting objects: 44, done. Delta compression using up to 4 threads. Compressing objects: 100% (24/24), done. Writing objects: 100% (24/24), 18.33 KiB | 0 bytes/s, done. Total 24 (delta 21), reused 0 (delta 0) To git@github.com:fieldtrip/fieldtrip.git 95dcd49..3cc3486 master -> master


Robert Oostenveld - 2016-06-14 16:14:55 +0200

Hereby I am closing multiple bugs that have been resolved for some time now. If you don't agree to the resolution, please reopen.