clyde23
Posts: 2
Joined: Sat Nov 17, 2018 8:02 pm

Dynamic file path name including arch type

Sat Nov 17, 2018 8:29 pm

Hi Fellow Raspberries,
I have a Bramble consisting of 5 Raspberry Pi's running Raspbian , and 1 Windows virtual machine running Raspbian. I'm currently using this cluster of computers to learn about something called MPI, and how to write code for it.
One of the things that I'd like to do is to pass a string from one computer to another, that includes 'something' that would get translated on each machine to reflect that machines underlying architecture. For example, if I invoke "uname -m" on my pi's, armv71 is returned. If I execute "uname -m" on my virtual pi I get x86_64. I'd like to end up with file path names something like /mnt/cifs/armv71/mpi_test1 and /mnt/cifs/x86_64/mpi_test1 . Any suggestions on how to do this? Thanks.

mfa298
Posts: 1355
Joined: Tue Apr 22, 2014 11:18 am

Re: Dynamic file path name including arch type

Mon Nov 19, 2018 1:43 pm

In some shells (certainly the normal default of bash) there are ways to include the results of some command in another.

In this particular case you might be able to use something like:

Code: Select all

PATH=/mnt/cifs/$(uname -m)/mpi_test1:$PATH
As well as the $() notation you might also see backticks used to do the same thing:

Code: Select all

PATH=/mnt/cifs/`uname -m`/mpi_test1:$PATH
in the most part the $() notation seems to be preferred as it's usually more readable.

clyde23
Posts: 2
Joined: Sat Nov 17, 2018 8:02 pm

Re: Dynamic file path name including arch type

Mon Nov 26, 2018 5:31 pm

I ended up going with plan "B". I took my cifs directory and added subdirectories named x86_64, armv71, and source, (..../cifs/x86_64 , ...../cifs/armv71 , and a ..../cifs/source). On the Pi's I mounted ..../cifs/armv71 as /mnt/cifs. On the Raspbian VM I mounted ..../cifs/x86_64 as /mnt/cifs. And on both I mounted ..../cifs/source as /mnt/cifs/source - so I could share source code on both types of machines. I compile the source natively once for the Pi and copy the arm executable to /mnt/cifs, (which is ..../cifs/armv71), so all the Pi's can access it. On the Raspbian VM I also compile the code natively, (meaning I copy the code from source to a temporary directory), then copy that x86 executable to /mnt/cifs, (which on the VM is really ..../cifs/x86_64)
So when I execute mpiexec /mnt/cifs/mpi_test1 , each machine automatically gets the correct executable.

Thank you for the help.

Return to “Other programming languages”