OpenCL syntax highlighting in CLion - opencl

Does anyone have a solution for syntax highlighting of OpenCL code for CLion?
I am placing the OpenCL source code in a file with the extension .cl and would like to have syntax highlighting for such files.

In CLion you can add .cl files as custom file types and manually provide the list of OpenCL C keywords for syntax highlighting.
There is an alternative to loading the OpenCL C code from a .cl file at runtime: Embedding it right within C++, such as used in this OpenCL-Wrapper. While naive string literals would destroy syntax highlighting, there is a way to retain syntax highlighting with the
#define R(...) std::string(" "#__VA_ARGS__" ")
stringification macro and by using #defines for all the OpenCL C functions and keywords.

Related

How to write special characters in Julia code

Recently I have seen Julia code like this with special characters:
How can I write Julia code like this? Do I need to have a special editor or can I do this also with e.g. Notepad++?
Julia allows you to use various Unicode symbols for variable and function names, and it makes sense in a lot of the scientific domains Julia is used in, making the code be more alike the scientific notation. (It's sometimes called "executable math" for this reason, though at this point it's more like "executable scientific notation".)
However, in any new code you write, it's not generally necessary to use these symbols, and you can write the code with the basic ASCII characters. Julia language and its standard libraries always provide ASCII equivalents for the Unicode functions they use.
For eg., ⊻ is the XOR character, and you can write 2 ⊻ 11 to get the XOR of the two numbers. But you can also instead write xor(2, 11) to get the same result, and they're exactly equivalent to the language. It's considered good practice for external packages as well, to provide their interface in terms of ASCII-typable names to the extent possible, even if internally Unicode-only names are used.
With that said, if you find you do need to work with code that uses such Unicode symbols, there are a few options:
Option 1: Autohotkey-script for converting LaTeX-like input to unicode characters.
Usually, the way to enter these character in Julia is using LaTeX-like syntax, for eg. \epsilon for ϵ. The AutoHotKey script provided here gives somewhat similar functionality, allowing you to type LaTeX-like input and converting it automatically into the corresponding symbols.
Option 2: A copy-paste list of symbols
This is pretty ad-hoc, but can work for situations where you just need to edit some existing code. You can use a clipboard manager like ClipX, or Win10's inbuilt one, to keep a copy of all the symbols the script uses. At any point, you can choose and insert the particular symbol you need.
Option 2a: Copy-paste from the REPL/Jupyter/Pluto
I'll put this option too here since it uses the clipboard as well. This makes use of the usual workflow for writing Julia code - you'll probably want to try out the code in the REPL or in a notebook anyway, so you can use the tab-completion features there, and then copy that code into your editor. Julia has a clipboard function too, so after trying out median(sin.(-ℯ:0.01:π)) in the REPL, you can surround that in triple quotes and pass it to clipboard like this: """median(sin.(-ℯ:0.01:π))""" |> clipbaord from the REPL itself.
Option 3: Use JuliaEditorSupport/julia-NotepadPlusPlus
This is sort of the "official" option, but only the syntax highlighting file has been updated recently, and the quality and reliability of the Autohotkey script here isn't clear. I'd be hesitant to recommend this option.
Option 4: Use a better supported editor
It's hard to let go of familiar tools, but in this case, this is probably the most reliable option long term. Julia for VSCode is probably the best supported editor right now, but the plugins for Vim and Emacs are also pretty good. If VS Code is too heavy (and Vim and Emacs unfamiliar), you can also try the plugin for Sublime Text which should be both easy to use and light.

Combine R, C++ and Fortran

I am trying to reimplement an R function using C++ and RCpp to speed up the computation. And in the C++ implementation, I need to use a Fortran function mvtdst found in link.
#include <Rcpp.h>
#include "mvtnorm.h"
using namespace Rcpp;
// [[Rcpp::export]]
NumericVector pmvnorm_rcpp(NumericVector upper, NumericMatrix corr)
{
double error;
double mvnP = pmvnorm_P(2, upper, corr, &error) ;
return mvnP ;
}
/*** R
pmvnorm_rcpp(c(1.5,1.5),c(0.0))
*/
Here, pmvnorm_P is defined in the mvtnorm.cpp file.
All the files found in link are kept in the working directory along with the RcppWrapper.cpp file.
When I compile my RcppWrapper.cpp file using sourceCpp() function in RCpp package, it gives the following error.
mvtnorm.o:mvtnorm.cpp:(.text+0x7c): undefined reference to `mvtdst_'
collect2.exe: error: ld returned 1 exit status
Error in Rcpp::sourceCpp("RcppWrapper.cpp") :
Error occurred building shared library.
Does anyone know how to resolve this error?
When you have code in two sources files
mvtnorm.cpp calling your backend function pmvnorm_P()
another file providing it
then you also must provide link instructions. Simply put, sourceCpp() is only intentended and working for one-file solutions (unless you give link instructions).
Simplest fix: just create a package assembling all your files in src/.
Fortran and C++ mangle the names of functions differently. It looks like mvtdst is the name of your Fotran function. (Right?) You need to "mangle" that by hand when called from C++. So instead of calling mvtdst, call mvtdst_ with the trailing underscore.
Unfortunately, compilers are not consistent in the mangling, so this will not be portable. (To make it portable, you'll need some sort of preprocessing that matched the mangling to the compiler.)

Using CMakes qt_wrap_ui command

I'm currently trying to change the build system used for a QT project from Visual Studio to CMake and I'm having trouble figuring out the correct usage of the qt_wrap_ui command. Currently, I'm using it like this:
macro(addQtForProject argLibraryName argSourceList)
...
qt_wrap_ui(${argLibraryName} ${argSourceList} ${argSourceList} ${varUiList})
endmacro()
As I handle the source and headers as a single list, I of course want the generated files to end up in the same list. varUiList contains the four .ui files used by the project.
When using CMakes visual studio 2005 generator with this macro, it adds four .h files, one for each .ui file, to the Visual Studio project file but the files themselves does to seem to exist at all so I must be doing something wrong. CMakes documentation is unfortunatly fairly sparse on this subject. This has been tested with CMake 2.8.10.
You probably want to use the more recent FindQt4 module which has much more documentation.
Specifically, it provides the QT4_WRAP_UI macro:
QT4_WRAP_UI(outfiles inputfile ... OPTIONS ...)
create code from a list of Qt designer ui files.
Options may be given to uic, such as those found
when executing "uic -help"

Error When Compiling Spec files

I'm a bit of an newb' to Ada. I see the following error when compiling a spec file on its own:
gcc -c shapes.ads
cannot generate code for file shapes.ads (package spec)
gnatmake: "shapes.ads" compilation error
The code works when it's build with the body and I can run a program that uses the package.
So what's the problem?
This isn't really an error. (Yeah, I know it looks like one :-)
The way GNAT works is that the object code for a unit (package spec and body, and any "is separates") is placed in a single, ".o", object code file. So you get the object code file when you compile the body--the compilation of which automatically brings in the spec--but not the spec alone.
An exception is when the spec doesn't require a body, i.e., it contains no declarations, such as subprograms or tasks, that require bodies.
The .ads file only contains the specification of a package. If it requires a body, you can't compile it that way. You have to compile the .adb file.
Think of it like a C header (.h) file. You don't compile them either, only the .c files.
PS: you can use gnatmake, it should automatically resolve dependencies and compile what's needed.

How to get unix executable form of .a library?

I have a library which i want to use in my iphone project which uses cpp files as well ... in order to do so i need the unix executable form of .a file..>?
You need to write a program of your own with a main function which uses the functions in the library you want to use. The library doesn't contain any code to exercise its own functions (I won't reiterate what #Steve-o already wrote in the comment -- took the words out of my mouth). It is fairly common for the source code of a library to include a simple demo program, but this is rarely distributed with the binary library.

Resources