How to use multiple threads in Julia 1.0? - multithreading

I have a script that uses the #threads macro. When I execute the script in terminal like
$ julia -p 4 my_script.jl
Where the file contains:
println("This program is using ", Threads.nthreads(), " threads")
prints than I'm using only one thread. What could I be doing wrong?

The switch -p 4 starts Julia with 4 processes not threads.
To start Julia with 4 threads use command:
$ export JULIA_NUM_THREADS=4
in Bash (under Windows use set JULIA_NUM_THREADS=4 in Command Prompt or $env:JULIA_NUM_THREADS=4 in Powershell).
Then you can start Julia just like:
$ julia
and it will see 4 threads.

Related

How to create a background process of Phoenix Shell in Cent OS?

so I know about creating named pipes using makefifo.
I use this:-
makefifo yourfifo
python sqlline.py < yourfifo &
cat "a.sql" > yourfifo
The problem is I have to do fg once, for the process to actually run. How can I truly make it run in background??

How to start 2 programs that need separate terminals from a bash script?

I have 2 programs that I want to run, programA.py and programB.py. When I run them manually, I have to open separate terminals and type the following commands:
terminal1
python programA.py
terminal2
python programB.py
Each of these programs then output some data on the command line. Lastly, programA.py has to be fully started and waiting before programB.py can start (takes ~2s for programA.py to start and be ready to accept data).
If I am running these programs in Ubuntu, how can I write a bash script that accomplishes that? Right now, I have the following:
#!/bin/bash
python programA.py
python programB.py
This starts programA.py, but because programA.py then waits for input, programB.py doesn't start until you close out of programA.py. How can I change my script to run the two programs simultaneously?
Edit:
Using the advice given by Andreas Neumann below, changing the script to the following successfully launches the two programs:
#!/bin/bash
python programA.py &
sleep 5
python programB.py &
However, when both programs are launched, the code then doesn't work properly. Basically, programA.py is setting up a listening socket, and then creates an interface that the user works with. programB.py then starts afterwards, and runs a process, talking to programA.py over the sockets. When running the above script, programA starts, waits, programB starts, and then programA and B connect, form the interface, but then programB isn't running its background processes correctly.
Updated Answer
If you find my original answer below doesn't work, yet you still want to solve your question with a single script, you could do something like this:
#!/bin/bash
xterm -e "python ProgramA.py" &
sleep 5
python ProgramB.py
Original Answer
If programA is creating a user interface, you probably need that to be in the foreground, so start programB in the background:
{ sleep 5; python programB.py; } &
python ProgramA.py
#!/bin/bash
python programA.py &
sleep 5 # give enough time to start
python programB.py &

Bash Switch Statement and Executing Multiple Programs

I'm trying to use a Bash switch statement to execute a set of programs. The programs are run through the terminal via a script. The simple idea is ::
In the terminal : ./shell.sh
Program asks : "What number?"
I input : 1
Program processes as:
prog="1"
case $prog in
1) exec gimp && exec mirage ;;
esac
I've tried it several ways yet nothing will run the second program and free the terminal. The first program runs fine and frees the terminal after closing. What am I to put after executing the first program that will allow the second to run in tandem with the first and also free the terminal?
To run two commands in the background, use & after each of them:
case $prog in
1)
gimp &
mirage &
;;
esac
exec basically means "start running this program instead of continuing with this script"

How to Run Unix command in Matlab in Windows?

In this MATLAB code, command is identified for UNIX platforms. However, I am using Win7. How can I run that command in Matlab in Windows?
command = ['Code/ExternalCode/kmeans/./kmeans_clustering.sh -i ' 'TemporaryResults/Features_ForKmeans' ' -p 2 -d -n ' num2str(k)];
system(command);
labels_kmeans = dlmread('TemporaryResults/Features_ForKmeans.membership');
labels_kmeans(:,1) = [];
You have at least two options, both assume the commands which are executed within the script are runnable on Windows, i.e. the programs that are executed exist and are compiled for Windows.
1.) Try to run the unmodified shell/bash script on Windows:
You need to install an interpreter which can run your script on windows, have a look at this SO question: Is there a way to run Bash scripts on Windows?
2.) Re-write the script to Windows batch format
This depends on the actual script you are running and involves finding the batch equivalent commands which correspond to the ones contained in your .sh script.

how to automate timed running of 2 programs?

I'm working in linux. I have two programs that run for infinite time ( that is , wont stop unless i kill the process ).i want to run program 1 first and then run program 2 after 20 seconds ( both will have to run simultaneously as one reads a file written by the other ).Currently , i am running the 2 programs by manually keeping track of time.. Is there a way to automate this ? i.e. is there any command or can any program be written to do this..
prog1 &
sleep 20
prog2
Using the shell:
$ program1 & sleep 20 ; program2
If one program reads from the file output by the other you should consider using a pipe to pass output from one to the input of the other:
$> program1 | program2
I'm assuming that you have control over these two programs and can get them to write to stdout and read from stdin.

Resources