17
$\begingroup$

Description

For the built-in programming language(or called Wolfram Language) of Wolfram Mathematica, I think it is much easier and simpler to learn than other computer language(such as C/C++ or java) according to my learning experience. However, in some cases, the performance/efficiency of user-defined is very critical. For instance, I have been learning the NURBS theory for two years with the help of the classical textbook "The NURBS Book" written by Les Piegl and Wayne Tiller. In this process, I also developed a package CAGD via the pure Wolfram Language.

About the performance turning of some functions that in my package, I believe Compile[] and CompilationTarget -> "C" are very useful tricks, here is an example that using Compile[] and CompilationTarget -> "C":

enter image description here

Nevertheless, when I added the option SplineWeights in CAGDBSplineFunction[], its performance was much slower(about $10$ times) than built-in BSplineFunction[], please see the below screenshots:

enter image description here

Here, BSplineFunction[] was a compiled version to C code. In addition, I'm not surprised at the high performance of built-in BSplineFunction[] because I know it was implemented in low level language(maybe C++/C) rather than its own Wolfram Language.

Learning about LibraryLink

To improve the performace/efficiency of my packege CAGD, I recently decided to rewrite some critical/key functions in C, then I would like to utilize the Library Link technique to link the C code to Mathematica.

Firstly, I read the documentation about the that technique via Wolfram LibraryLink User Guide, however, I discovered that it was not a easy thing to learn that tutorial. For me, I only learned C and Visual Basic when I was a freshman seven years ago.

Question

  • Is there some simple mehtods to learn the Library Link for the newcomer?

  • What other knowledge(about the computuer language) need to be learned?


Related threads that applied/about LibraryLink

$\endgroup$
19
+500
$\begingroup$

First of all, you must be relatively comfortable with the C language. That is absolutely a prerequisite. If you are not comfortable with C, brush up your C skills first.

Next, look at concrete examples while reading the LibraryLink user guide. The examples are described in the last section. Start with the simplest ones. The user guide is meant more as a complete description of all LibraryLink features rather than a tutorial. It's going to be easier to start with a tutorial instead. Luckily Arnoud has written up a very nice series of detailed tutorials for getting started with LibraryLink.

  1. Doing nothing with LibraryLink
  2. Saying hello with LibraryLink
  3. Sending greetings from LibraryLink
  4. Squaring integers with LibraryLink
  5. Writing a boolean function with LibraryLink
  6. Calculating the mean value of a list with LibraryLink
  7. Creating a matrix with LibraryLink
  8. Transposing an integer matrix with LibraryLink
  9. Working with complex numbers in LibraryLink
  10. Working with multiple functions in LibraryLink

Work through these in order. There may be some posts I missed, so this table of contents may not be complete. Update: Here's the official table of contents with additional links.

If you find these too basic or two slow, take a look at an answer he wrote on this site:

It uses plain C, not C++, so don't be discouraged by the title.


Regarding the thread you linked (How to simplify writing LibraryLink code?), I do not recommend that you use LTemplate before you are comfortable with plain LibraryLink. It is meant to make day-to-day work with LibraryLink easy once you already know how to use it. It won't be easier to learn LibraryLink with it (quite the opposite). At this moment it is not meant for beginners. Someday I'll try to write up a basic tutorial for LTemplate too, but we're not there yet.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.