Sublime Text 3 intel oneAPI Fortran build system - fortran

Has anyone figured out how to write the build system for the oneAPI Fortran compiler?
Previously, i was using Parallel Studio XE ifort, and i managed to get it working using the solution here:
{
"cmd": ["cmd", "/e:on", "/v:on", "/k", "ipsxe-comp-vars intel64 vs2013 && ifort ${file}"],
"file_regex": "^.*\\\\([0-9A-Za-z_]+\\.[A-Za-z0-9]+)\\(([0-9]+)\\):[ ]+error[ ]+#([0-9]+):[ ]+(.*)$",
"working_dir":"${file_path}",
"selector":"source.f ,source.for ,source.ftn ,source.f90 ,source.fpp ,source.i ,source.i90",
"encoding":"cp936",
"path":"C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2017.4.210\\windows\\bin;${path}",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/e:on", "/v:on", "/c", "ipsxe-comp-vars intel64 vs2013 && ifort ${file} && ${file_base_name}"]
}
]
}
I tried changing the paths to the new ones but it doesn't work. I get the following error:
"ipsxe-comp-vars" is not recognized as an internal or external command,
program o executable.

I found the answer. Explanation below. Posting the working build system here for visibility.
This should be the build system:
{
"cmd": ["cmd", "/e:on", "/v:on", "/S", "/k", "C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat intel64 vs2022 && ifort ${file}"],
"file_regex": "^.*\\\\([0-9A-Za-z_]+\\.[A-Za-z0-9]+)\\(([0-9]+)\\):[ ]+error[ ]+#([0-9]+):[ ]+(.*)$",
"working_dir":"${file_path}",
"selector":"source.f ,source.for ,source.ftn ,source.f90 ,source.fpp ,source.i ,source.i90",
"encoding":"cp936",
"path":"C:\\Program Files (x86)\\Intel\\oneAPI\\compiler\\latest\\windows\\bin\\intel64;${path}",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/e:on", "/v:on", "/s", "/c", "C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat intel64 vs2022 && ifort ${file} && ${file_base_name}"]
}
]
}
Why the problem happens
For starters, ipsxe-comp-vars is a batch file which when run, sets up environment variables required to execute the intel compilers. This file is specific to Intel Parallel Studio XE (IPSXE). Now, when installing IPSXE, it would add this batch file to your PATH, meaning you could simply call ipsxe-comp-vars from any directory to set up the required environment variables.
Intel oneAPI has a differently named file, that essentially does the same thing, called setvars.bat. This file is stored in:
C:\Program Files (x86)\Intel\oneAPI\setvars.bat
So, at first it seems that calling ipsxe-comp-vars fails because the file is named differently. However, unlike IPSXE did with ipsxe-comp-vars, oneAPI does not add setvars to PATH, so you cannot simply call setvars, you have to usethe full path.
How to solve it
With IPSXE, you could call ipsxe-comp-vars and it would run the batch file that sets up environment variables, but with oneAPI either you add the file to PATH (not reccomended because it has a generic name), or you use the full path when calling it (same as above):
C:\Program Files (x86)\Intel\oneAPI\setvars.bat
Now, because you have to plug this in into the build system config, you need to format it correctly. ST runs the commands in a cmd.exe, so you have to use the correct options and format the path in a way that cmd can understand it:
options (you can get a full list by opening a cmd prompt, typing cmd /? and hitting return):
- /e:on Enables command extensions
- /v:on Enables extension of environment variables
- /s Modifies how the string following a /c or /k is read
- /k Executes the string command and continues
The path to the setvars.bat file must be formatted as follows:
C:\\\"Program Files (x86)\"\\Intel\\oneAPI\\setvars.bat
Each \ separating dirs needs to be escaped (using \ as well)
needs to be enclosed in double quotes, since it contains a whitespace. Each double quote needs to escaped as well (once again with )
The following options are specific to the setvars.bat file:
- intel64 specifies 64-bit configuration
- vs2022 specifies Visual Studio 2022 as the developer cmd or
powershell version to use
Finally, ifort is called on the current file with ifort ${file}
Additionally, the build system is completed with a variant "Run". This variant runs the output file once it has been compiled(&& ${file_base_name}), and will show the output in the Sublime Text 3 console (does not accept inputs, if anyone knows how to setup up sublimeREPL for Fortran please tell me)

Related

Link with Intel MKL library when compiling Fortran in Sublime Text 3?

With the help of this great site, I was able to compile my Fortran code in Sublime Text 3 using a "new build system" as suggested in this answer like this.
{
"cmd": ["cmd", "/e:on", "/v:on", "/k", "ipsxe-comp-vars intel64 vs2013 && ifort ${file}"],
"file_regex": "^.*\\\\([0-9A-Za-z_]+\\.[A-Za-z0-9]+)\\(([0-9]+)\\):[ ]+error[ ]+#([0-9]+):[ ]+(.*)$",
"working_dir":"${file_path}",
"selector":"source.f ,source.for ,source.ftn ,source.f90 ,source.fpp ,source.i ,source.i90",
"encoding":"cp936",
"path":"C:\\Program Files (x86)\\IntelSWTools\\compilers_and_libraries_2017.2.187\\windows\\bin;${path}",
"variants":
[
{
"name": "Run",
"cmd": ["cmd", "/e:on", "/v:on", "/c", "ipsxe-comp-vars intel64 vs2013 && ifort ${file} && ${file_base_name}"]
}
]
}
Now, I want to link against the MKL library to benefit from its highly optimized routines. I want to include LAPACK routines, FFTs from mkl_dfti, random numbers from mkl_vsl, etc. I tried to add these libraries to the compile command as follows without success.
"cmd": ["cmd", "/e:on", "/v:on", "/c", "ipsxe-comp-vars intel64 vs2013 &&
ifort ${file} && ${file_base_name} mkl_lapack95_lp64.lib mkl_intel_lp64.lib
mkl_intel_thread.lib mkl_core.lib libiomp5md.lib"]
I use Windows 10 and can access these libraries in Visual Studio 2013. I need help configuring Sublime Text to use the same libraries.
Intel Fortran compiler flag /Qmkl adds MKL libraries.
Changing "ifort ${file}" to "ifort /Qmkl ${file}" should work for you.

How to compile and run c++ programs with sublime text 3?

I want to compile and run a c++ program in cmd every time I hit CTRL+B in Sublime Text 3. Also I need to keep the window alive after the program is fully executed. I particularly love the build system which code-block uses. Can I implement the same system in Sublime?
So far, I have following build system:
{
"cmd": ["mingw32-g++", "-o", "$file_base_name", "$file"],
"path": "C:\\MinGW\\bin\\",
"variants": [
{
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
The only problem here is that I have to compile first and then run it. I want to have it compiled and run in a single operation.
Edit:
I have solved this problem by the following build system:
{
"cmd": ["g++.exe", "-std=c++11", "-o", "$file_base_name", "$file", "&&", "start", "cmd", "/c", "$file_base_name & echo. & echo. & pause"],
"shell": true,
"selector": "source.c++"
}
Sublime Text is a text editor wherein you can use different languages under the same hood.
Regarding your c++ program you have to install some packages for the version of c++ you are using. I recommend to watch some tutorials to get a step by step procedure and better understanding.
{
"shell_cmd": "g++ -std=c++11 -Wall \"${file}\" -o \"${file_path}/${file_base_name}\" && start cmd /k \"$file_base_name\"",
"working_dir": "${file_path}",
"selector": "source.cpp, source.cxx, source.cc, source.c++"
}
go to Tools -> build system -> new build system -> Paste It -> save it as "C++", then close it.
now save your C++/C code with .cpp extention (important .c extention is not supported) then to compile it go to tools -> build with Select "C++"
file download link:https://github.com/mahirx/configurations/blob/master/sublime_text/c_and_c%2B%2Bv2/C%2B%2B.sublime-build
please notify me if you found any mistakes.
Configure your editor to run make (or ninja ...) for CTRL B and use a Makefile, a build.ninja, or some other build automation tool. So you could add the appropriate rule (to your Makefile etc....) to run something else.
(both GNU make and ninja have good documentation and tutorials, and you could ask questions about them on SO, with some MCVE)
Source code editors are tools to edit source code. Configure them to run the external programs (compilers, debuggers, your own thing, ... or make or ninja) appropriately.
The only problem here is that I have to compile first and then run it. I want to have it compiled and run in a single operation.
So build with a good enough build automation tool. Configure your editor to run make, and edit your Makefile to make "compile then run" the default target (and likewise with ninja and its build.ninja file). Remember that compilers like GCC (even started from IDEs) are command line programs (and your mingw32-g++ is a GCC compiler).
Take also the good habit to compile with all warnings and debug info, so pass -Wall -Wextra -g to your GCC that is your mingw32-g++ (hence, edit appropriately your Makefile or build.ninja file).
In other words, an IDE - that is just a buzzword - is a source code editor suitably configured to run other programs. My preference is emacs

How to define the task.json to compile C/C++ code in vscode by using the cl.exe on windows?

I have installed the Microsoft Visual C++ Build Tools 2015 on my 64bit win10 , and can use the cl.exe to compile and link the C/C++ program in a plain Command Prompt window by the following steps (some instructions from Setting the Path and Environment Variables for Command-Line Builds):
1. cd "\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
2. vcvarsall amd64
3. cl helloworld.c
The helloworld.c is just a simple C source file to print "Hello world!". I aslo try to congfigure the task.json to directly compile and link C/C++ programs in the vs code. Here is my task.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "vcvarsall amd64 && cl",
"isShellCommand": true,
"args": ["${file}"],
"showOutput": "always"
}
And the path of vsvarsall and cl have been added in the PATH. But it still doesn't work (the output is put at the end of the post). So my question is that: how can I to define the task.json which can first run the vcvarsall amd64 to set system variables and then execute the cl command to compile and link programs.
As Rudolfs Bundulis said, make a batch file and just call it, inside it do everything you need to do.
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "build.bat",
"isShellCommand": true,
"args": [],
"showOutput": "always"
}
And in your project have the build.bat goodness.
build.bat:
#echo off
call "E:\programs\VS2015\VC\vcvarsall.bat" x64 <----- update your path to vcvarsall.bat
..
cl %YourCompilerFlags% main.cpp %YourLinkerFlags%
..
I would mention that you'd like to have another visual studio code bootstraper batch that would set the vcvars environment and then starts up the editor so you don't set the vcvars for every build. Like so:
#echo off
call "E:\programs\VS2015\VC\vcvarsall.bat" x64 <----- update your path to vcvarsall.bat
code
This way you can omit setting the vcvarsall.bat every time you compile the code. Minimal rebuild flag will also help you a lot so you only compile changed files.

Cannot open shared GCC library

This question should be simple for those familiar with GCC. I'm hoping to be soon.
/usr/lib/gcc/i686-pc-cygwin/4.5.3/cc1plus.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory
I'm launching this GCC doohickey from Sublime Text 2, directly calling g++-4.exe instead of the g++.exe (which wasn't recognised as a program).
Apparently the recommended fix is to add the folder that contains whatever library is missing to the LD_LIBRARY_PATH variable using export LD_LIBRARY_PATH=somefolder. However, no library is being specified, just a '?' in its place.
I'm following instructions to install clang, and I'm using Windows 7 Pro, 64-bit. The code being compiled is a single C++ file.
Cheers...
Hah, I met the same problem when I am trying to use the g++ of my cygwin as a compiler in sublime. Eventually I found this simple solution: Insert the following line to C++.sublime-build.
"path": "D:/Tools/Cygwin/bin/",
After this edition, my C++.sublime-build has the following content:
{
"cmd": ["g++","${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++, source.cpp",
"path": "D:/Tools/Cygwin/bin/",
"variants":
[
{
"name": "Run",
"cmd": ["bash", "-c", "g++ '${file}' -o '${file_path}/${file_base_name}' && '${file_path}/${file_base_name}'"]
}
]
}
At least this works for me!
How to find C++.sublime-build?
Preferences > Browse Packages > C++ > C++.sublime-build
Cygwin applications are built in a shell that renders the Windows files system as a virtual Unix style file system. In Windows the "C:\" drive maps to /cygdrive/c in cygwin. I'm not aware of any way to emulate this mapping within a Windows command shell, or any Windows application.
All of the paths embedded in gcc and g++ have references to the path in the virtual file system. For simple apps with no external dependencies this isn't a problem. But for g++ and others they must be run from a Cygwin shell. It might be possible to run 'bash -c g++ ...' from a Windows command, but I don't have access to a setup to try it.

Sublime Build System for Gradle

I want to have a custom build system but am really not able to make one. I have Gradle 1.2 installed and even the GRADLE_HOME is set correctly now I have the following commend in the build system file
{
"cmd": ["gradle","build.gradle"],
"path": "$project"
}
And the error I get is as follows (when I try to build my project):
[Errno 2] No such file or directory
[cmd: [u'gradle', u'build.gradle']]
[dir: /home/roger/Project/Visage/HelloWorld/src/main/visage/visage/javafx]
[path: $project]
[Finished]
Actually my Project Base directory is HelloWorld and I have my build.gradle there itself. Please help me to write the correct build system or give the correct commands to avoid error and execute successfully. I am currently using UBUNTU 12.04
I think you have to use a shell for your build system. and instead of path I guess you mean "working_dir". can you try this:
{
"cmd": ["gradle"],
"shell": "true",
"working_dir": "${project_path}"
}
cheers,
René
Even shorter Gradle configuration in Sublime Text 3:
{
"shell_cmd": "gradle",
"working_dir": "${project_path}"
}
Go to menu 'Tools > Build System > New Build System...' and paste this text. Then save the configuration file as 'Gradle.sublime-build'.