Running code using XCode vs Terminal

  • Context:
  • Thread starter Thread starter TheCanadian
  • Start date Start date
  • Tags Tags
    Code Running
Click For Summary

Discussion Overview

The discussion revolves around running C++ code using OpenMPI in XCode versus the Terminal. Participants explore issues related to setting environment variables, specifically TMPDIR, and the differences in execution between the two environments. The conversation includes troubleshooting steps and configuration settings within XCode.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant notes that the code runs successfully in the Terminal but fails in XCode due to an inability to access or execute the executable, suggesting that TMPDIR may be the issue.
  • Another participant emphasizes that XCode operates as an IDE and does not run executables directly, which may lead to confusion regarding the execution process.
  • There is mention of mpirun being the debugger for OpenMPI, with questions about the role of orterun in this context.
  • A participant shares that they successfully compiled and ran the code using mpic++ with debugging flags, indicating that G++ works fine.
  • Some participants discuss the configuration settings in XCode, particularly regarding how to set arguments and environment variables for running the executable.
  • Links to external resources are shared, suggesting configurations for XCode and MPI, although some links are noted to be outdated or broken.
  • One participant expresses frustration that a previously working setup in XCode has stopped functioning, raising concerns about potential issues with project configurations.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best way to configure XCode for OpenMPI, as multiple approaches and configurations are discussed, with some participants experiencing success while others continue to face issues.

Contextual Notes

There are limitations regarding the compatibility of shared resources with different versions of XCode, and some participants mention difficulties in finding specific libraries or settings. The discussion reflects a variety of experiences with configuration and execution in XCode.

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   Reactions: 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?
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
4K
Replies
3
Views
2K
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 14 ·
Replies
14
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 22 ·
Replies
22
Views
4K
Replies
1
Views
6K