MV-7001: Building User Subroutines in MotionSolve
In this tutorial, you will learn how to compile and build a MotionSolve user subroutine.
The user subroutine can be implemented as C/C++ or FORTRAN source code, C/C++ or FORTRAN object files, or a combination of these.
For your convenience, MotionSolve contains a subroutine build tool for Windows and Linux that can build the subroutine for you. Using this subroutine requires no programming knowledge.
Windows | Linux |
---|---|
Microsoft Visual Studio version 2005, both Express and Professional | GCC, version 4.1.2 |
Intel Visual FORTRAN Compiler 10 |
Use the MotionSolve Subroutine Build Tool to Create Shared Libraries
The Altair Subroutine Builder is included in the MotionSolve installation for both Windows and Linux.
Follow these steps to build a MotionSolve-compatible shared library using available source code.
Specify Source Code or Object Files
- C/C++ source code (*.c, *.cpp, *.cxx)
- FORTRAN source code (*.f, *.f90)
- FORTRAN or C/C++ object files (*.obj in Windows, *.o in Linux)
- A combination of the above.Note: The remainder of this section demonstrates using the build tool on Windows. The steps for using the tool on Linux are identical.Important: The source code or object files must all be located in the same directory. You must have write-to-disk permissions for this directory. If you do not have write-to-disk permissions for this directory, please copy the source code to a location where you do have write-to-disk permissions.
Also, if your source/object code is located in different folders on your disk, please copy all source/object code, along with any relevant files (like headers, for example) to one common directory. Use this as your working directory in the following steps.
Specify the Output Directory
Next, you will specify the output directory where you would like the shared library to be built. Again, you must have write-to-disk permissions for this directory.
Build the Shared Library
Frequently Asked Questions
Can the tool build a shared library when both Fortran and C/C++ source code is specified?
Yes, the tool can handle mixed source code as well as object files.
What platform does the tool build my library for?
The supported platforms are 64-bit Windows and 64-bit Linux.
Is my shared library a debug or release version?
The shared library created is a release version library.
Where can I get sample templates for the syntax of the C/C++/Fortran code?
- For C/C++ source code: <install>\Altair\<version>\hwsolvers\motionsolve\usersub\c_src
- For Fortran source code: <install>\Altair\<version>\hwsolvers\motionsolve\usersub\f_src
- C/C++
- Include the header file msolvsub_c_include.h
(located in
<install>\Altair\<version>\hwsolvers\motionsolve\usersub\c_src\include)
in your code. To export a function, use the keywords
CLINKAGE, DLLFUNC, and
STDCALL.
#include " msolvsub_c_include.h" #include "stdlib.h" CLINKAGE DLLFUNC void STDCALL ARYSUB (int *id, double *time, double *par,int *npar, int *dflag, int *iflag, int *nvalue, double *value) { }
- Fortran
- In Fortran syntax, the same function
above can be exported as shown
below:
SUBROUTINE ARYSUB (ID, TIME, PAR, NPAR, DFLAG, & IFLAG, NVALUE, VALUE) !DEC$ ATTRIBUTES DLLEXPORT :: ARYSUB
Does the order in which I choose the source files matter?
Yes, this can matter in certain cases. For example, when building Fortran source code and defining MODULES, you may want to include the source file that contains the definition of any defined modules before the source files that refer to these modules.
I am not able to compile Fortran files even though I have a supported Intel Fortran compiler installed. What's wrong?
The build tool relies on an environment variable to detect the version of the Intel Fortran compiler and its location on your machine. Make sure you have the environment variable IFORT_COMPILERxx (where xx is the version of the compiler - 10, 11 or 12) defined correctly on your system and pointing to the installed version.
Use the Microsoft® Developer Studio to Build a Shared Library
To successfully build a shared library using the steps below, you will need to have write-to-disk permissions for your HyperWorks installation directory.
Building a C++ User Subroutine DLL using Microsoft® Visual Studio®
To successfully build a shared library using the steps below, you will need to have write-to-disk permissions for your HyperWorks installation directory.
Building a FORTRAN User Subroutine DLL using Microsoft® Visual Studio®
The same steps can be repeated to build a FORTRAN user subroutine DLL for MotionSolve. The only difference is that the Visual Studio project file to be opened is ms_fsubdll.vfproj. All the other steps remain the same.