Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C/++/# Running code using XCode vs Terminal

  1. Jan 19, 2017 #1
    I have a C++ code, test.cpp, and am using OpenMPI when running it. I followed the instructions here and it appears to have called OpenMPI correctly. I can compile and run the code perfectly fine from the command line but I just have to specify "TMPDIR=/tmp" before running it, i.e.:

    $ mpic++ -std=c++11 test.cpp
    $ TMPDIR=/tmp mpirun -np 4 a.out

    But when I try to run the code in XCode (based on the above instructions), it tells me that there are no build issue but then comes up with the error:

    orterun was unable to launch the specified application as it could not access
    or execute an executable:

    Thus I am simply wondering how I can ensure that XCode uses the directory "TMPDIR=/tmp" when executing the file (I believe that's where the problem is arising). I have tried specifying it in the "Edit Schemes" options although perhaps I am making an error.
  2. jcsd
  3. Jan 19, 2017 #2
    It would be in the settings for whatever runs your compiled executable. You have to remember that XCode isn't going to act like a terminal, it's going to act like an IDE. When you create an executable called a.out, XCode does not run a.out. It runs gbd with a.out as it's parameter. What is the debugger for OpenMPI? I assume that's where your settings will be. This is not an XCode issue. Is there a reason you aren't using G++, which should have come with Xcode?

    EDIT: okay, so mpirun seems to be your debugger (what is orterun?) When you installed it into XCode, do settings come up for it when you right click on the project and go to settings? It should be close to where you select compiler settings for each release type. (Sorry I don't have a Mac right now so I can't check.)
  4. Jan 22, 2017 #3
    Thank you for the response. The code works with

    mpic++ -g test.cpp
    time TMPDIR=/tmp mpirun -np 4 a.out

    as well, so I believe G++ works fine. I am quite new to OpenMPI and have not been using any particular debugger besides printf statements. I have come across a few resources I am planning to learn but are there any in particular you would recommend? XCode has its own debugger if I'm not mistaken, but it does work with parallel processes. Based on this reference: "mpirun, mpiexec, and orterun are all synonyms for each other."

    When I go to Product > Scheme > Edit Scheme, there is a column for "Run (debug)" in which there is a section called "Arguments". And under "Arguments Passed on Launch", I wrote:

    -n 4



    Under the column once again for "Run (debug)", there is a section called "Info", and it is here that I set the executable as orterun.

    I tried adding more arguments to pass on launch, but it was unsuccessful (perhaps due to how my message was written. Nevertheless, any ideas you have would be greatly appreciated.
  5. Jan 25, 2017 #4
    Orterun is an alias for the executable which is mpiexec. This is most certainly an internal issue as the code works on the command line yet fails only when I try to run it on XCode. It seems to actually build successfully, and mpi.h is properly linked, but simply executing the file is the part that appears problematic. When I run the command in terminal, it works. But if I don't include "TMPDIR=/tmp" when running it from the command line, then I actually get the same error as I currently am receiving in XCode (i.e. . I have tried adding "TMPDIR=/tmp" to the arguments passed on launch and environment variables, but it doesn't seem to be implemented properly. Any thoughts?
  6. Jan 26, 2017 #5
  7. Jan 26, 2017 #6
    When following the second version in your link, it appears only valid for XCode 3.2 (I am on version 8.2) and a few of the links are broken in the second version. I tried the first suggested method of simply taking "/libmpi.dylib" (could not oddly find /libmpi_cc.dylib, perhaps it is a different name now) and dragging it under main.cpp in my sidebar on XCode. Although this does not appear to fix the issue. A lot of the instructions are nearly identical to the one I posted above, and it appears only valid for older versions of XCode.
  8. Jan 26, 2017 #7
  9. Jan 27, 2017 #8
    And just as I said it worked on XCode, it now no longer works. It appears there is something going on as it once was and now when I follow the identical steps (to my knowledge) in setting it up, it no longer works. I'm wondering if running separate projects at once may be causing an issue or if the linker (or other) settings are changing since everything works perfectly well from the command line as long as I include "TMPDIR=/tmp", but when I do not, I get an error. This same error is now popping up in XCode.
  10. Jan 27, 2017 #9
    Are you using the TMPDIR environment variable in your program? Try printing it out and seeing if it's set properly.
  11. Jan 27, 2017 #10
    I did go to Edit Scheme and did try adding /tmp to the Environment Variables but this did not appear to fix the problem. Is this what you mean?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted