0

Month ago I installed Open MPI 4.0.1 on macOS Mojave following this Stack Overflow answer.

Back then everything worked and I managed to compile and run hello.c and few other programs.

But when I tried today to compile any program using $HOME/opt/usr/local/bin/mpicc -o program_name ./program_name.c I get error clang: error: no such file or directory: './program_name.c', even though these files are in that directory. It doesn't even work for hello.c.

But when I try to run existing programs, for example hello, using $HOME/opt/usr/local/bin/mpirun -np 4 hello, it works.

So I don't understand how can I get error no such file or directory if mpi can find and run existing programs, but can't compile files that are in the same directory.

I also tried to position in that directory using cd $HOME/opt/usr/local/bin and then execute mpicc -o hello ./hello.c, but then I get error -bash: mpicc: command not found.

Does anyone know where is the problem and how to solve it?

user3566569
  • 109
  • 2
  • 9
  • Does `$HOME/opt/usr/local/bin/mpicc -o /my_full_path/program_name /my_full_path/program_name.c` work better? It's _not_ complaining about not finding the compiler, but rather, it can't find the `.c` file. – Craig Estey May 26 '19 at 00:12
  • The usual method is to add `mpicc` to `$PATH` (e.g. `export PATH=$HOME/opt/usr/local/bin:$PATH`) and then do `mpicc -o program_name program_name.c` When you start up, are you sure your current directory has `program_name.c` in it (e.g. `ls` should list it)? – Craig Estey May 26 '19 at 00:15
  • Command `$HOME/opt/usr/local/bin/mpicc -o $HOME/opt/usr/local/bin/program_name ./$HOME/opt/usr/local/bin/program_name.c` didn't helped, but I tried to copy the file to Desktop and then run command `$HOME/opt/usr/local/bin/mpicc -o Desktop/program_name ./Desktop/program_name.c` and it works! – user3566569 May 26 '19 at 00:27
  • I didn't added `mpicc` to `$PATH`, I could try that. Yes, current directory has `program_name.c` and it is listed with `ls`. – user3566569 May 26 '19 at 00:30
  • 1
    In your full path command, the `.c` is listed as `./$HOME/...` (vs. `$HOME/...`). Is that what you did, or just a typo here? My second example _should_ work. If it doesn't, it may be some macOS specific issue (i.e. it's changing the current directory when it shouldn't). You could run `mpicc` under `strace` to follow `chdir`, `open`, etc. that the compiler is doing to see if it does anything strange. – Craig Estey May 26 '19 at 00:36

1 Answers1

0

In case of issues like this, it's good to run mpicc with option -v. This way, you can take a look at all the commands that are executed behind your back

> mpicc -v -o main ./main.c
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-darwin17.7.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.13.0 -Wdeprecated-objc-isa-usage -Werror=deprecated-objc-isa-usage -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -fno-strict-return -masm-verbose -munwind-tables -target-cpu penryn -target-linker-version 305 -v -dwarf-column-info -debugger-tuning=lldb -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0 -I ... -fdebug-compilation-dir /Users/... -ferror-limit 19 -fmessage-length 173 -stack-protector 1 -fblocks -fobjc-runtime=macosx-10.13.0 -fencode-extended-block-signature -fmax-type-align=16 -fdiagnostics-show-option -fcolor-diagnostics -o /var/folders/cx/76hd7pcs41g_vdj4qjfx0d4h0000gn/T/main-29e74d.o -x c ./main.c
clang -cc1 version 9.0.0 (clang-900.0.39.2) default target x86_64-apple-darwin17.7.0
...
...

This way, you can spot issues related to compiler. Also, make sure your Toolchain hasn't changed after system/XCode upgrade. If you have compiled MPI from sources, it might be you have some discrepancies between what was used during compilation time and what you have now.

Oo.oO
  • 12,464
  • 3
  • 23
  • 45