Running code using XCode vs Terminal

In summary, when trying to run the code in XCode, the compiler and linker are working, but the debugger is not. I am not sure what I am missing, but I would appreciate any help.
  • #1
TheCanadian
367
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
  • #2
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
  • #3
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.
 
  • #4
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?
 
  • #6
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.
 
  • #8
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.
 
  • #9
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?
 

Related to Running code using XCode vs Terminal

1. What is the difference between running code using Xcode and Terminal?

Xcode is an integrated development environment (IDE) specifically designed for developing software for Apple's products, while Terminal is a command-line interface used to interact with the operating system. Xcode provides a graphical user interface and various tools for coding, debugging, and testing, while Terminal requires users to type in commands to execute tasks.

2. Which one should I use for coding and running my projects?

It depends on your preference and the type of project you are working on. If you are developing a software for Apple products, Xcode would be a better choice as it provides all the necessary tools and features. However, if you prefer using command-line tools or are working on a project that does not require Xcode's specific features, Terminal can be a more lightweight and efficient option.

3. Can I use both Xcode and Terminal for the same project?

Yes, you can. In fact, Xcode uses Terminal in the background to execute some tasks. You can also use Terminal to compile and run your Xcode project by navigating to the project's directory and using the "xcodebuild" command.

4. Is there any performance difference between using Xcode and Terminal?

Both Xcode and Terminal use the same compiler and tools to build and run code, so there is no significant performance difference. However, Xcode may provide a more user-friendly and streamlined experience for coding and debugging, which can improve productivity.

5. Do I need to install Xcode to use Terminal for coding?

No, you do not need to install Xcode to use Terminal for coding. However, some tools and features that require Xcode may not be available. Additionally, if you want to use Xcode's specific features, you will need to install it separately.

Similar threads

  • Programming and Computer Science
Replies
1
Views
3K
  • Programming and Computer Science
Replies
7
Views
512
  • Programming and Computer Science
Replies
1
Views
627
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
2
Views
864
  • Programming and Computer Science
Replies
1
Views
868
  • Programming and Computer Science
Replies
0
Views
292
  • Programming and Computer Science
Replies
0
Views
571
  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
14
Views
1K
Back
Top