Running code using XCode vs Terminal

  • Thread starter Thread starter TheCanadian
  • Start date Start date
  • Tags Tags
    Code Running
AI Thread Summary
The discussion focuses on running a C++ program using OpenMPI in XCode versus the terminal. The user successfully compiles and runs the code in the terminal by setting the TMPDIR environment variable but encounters errors in XCode, where it fails to execute the application. Suggestions include checking the settings for the executable and ensuring the correct debugger is configured, as XCode operates differently from a terminal. The user has attempted to set TMPDIR in XCode's scheme settings but continues to face issues, indicating a potential misconfiguration or misunderstanding of how XCode handles MPI applications. Ultimately, the problem appears to stem from linking and executing the application correctly within the XCode environment.
TheCanadian
Messages
361
Reaction score
13
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.
 
Technology news on Phys.org
TheCanadian said:
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.
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.)
 
  • Like
Likes TheCanadian
newjerseyrunner said:
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.)

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

and

$BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH

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.
 
newjerseyrunner said:
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.)

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?
 
JorisL said:
Maybe this can help http://people.clarkson.edu/~bhelenbr/Research_Pages/Xcode_&_MPI.html
It should describe how to configure your xcode to run with mpi.

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.
 
TheCanadian said:
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.

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.
 
Are you using the TMPDIR environment variable in your program? Try printing it out and seeing if it's set properly.
 
  • #10
newjerseyrunner said:
Are you using the TMPDIR environment variable in your program? Try printing it out and seeing if it's set properly.

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?
 
Back
Top