- Notifications
You must be signed in to change notification settings - Fork5
Porting meshing tools and solvers that deal with unstructured meshes on GPUs
License
LoicMarechal/GMlib
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The purpose of theGMlib is to provide programmers of solvers or automated meshers in the field of scientific computing with an easy, fast and transparent way to port their codes onGPUs (Graphic Processing Units).
This library is based on theOpenCL language standard, thus taking advantage of almost every architectures supported by most platforms (Linux,macOS,Windows).
It is a simple loop parallelization scheme (known as kernels in the realm of GPU computing).
Provides the programer with pre defined mesh data structures.
Automatically vectorizes unstructured data like the ball of points or the edge shells.
It requires some knowledge on OpenCL programing, which akin to C and C++.
Handles transparently the transfer and vectorization of mesh data structures.
- InstallCMake
- A valid C99 compiler
- Open a shell window
- You first need to installCMake. Do not forget to choose "add cmake to the path for all users", from the install panel.
- Then you need a valid C compiler like the freeVisual Studio Community 2019
- Open the x64 Native Tools Command Prompt for VS (or x86 if you need to build a 32-bit version)
You need the right OpenCL development environment specific to your GPU:
- unarchive the ZIP file
cd GMlib-master
mkdir build
cd build
cmake ..
cmake --build . --target install
Optionally, you may download libMeshb to run the examples:
- you need to install thelibMeshb from GitHub
- cd to /usr/local/GMlib/sample_meshes/
- uncompress them with
lzip -d *.meshb.lz
(lzip) - you may now enter /usr/local/GMlib/examples directory and run the various examples
And the Hilbert renumbering command that is necessary to preprocess meshes before processing them with the GMlib
- download it fromLPlib
- use the command: "hilbert -in raw.meshb -out renum.meshb -gmlib"
TheGMlib is written inANSI C with some parts inOpenCL.
It is made of a single C file and a header file to be compiled and linked alongside the calling program.
It may be used in C and C++ programs (Fortran 77 and 90 APIs are under way).
Tested onLinux,macOS,Windows 7-10.
Here is a basic example that computes some triangles' barycenters on a GPU:
First the "C" part executed by the host CPU:
// Init the GMLIB with the first available GPU on the systemLibIdx = GmlInit(1);// Create a vertex and a triangle datatypeVerIdx = GmlNewMeshData(LibIdx, GmlVertices, NmbVer);TriIdx = GmlNewMeshData(LibIdx, GmlTriangles, NmbTri);// Fill the vertices with your mesh coordinatesfor(i=0;i<NmbVer;i++)GmlSetDataLine(LibIdx, VerIdx, i, coords[i][0], coords[i][1], coords[i][2], VerRef[i]);// Do the same with the elementsfor(i=0;i<NmbTri;i++)GmlSetDataLine(LibIdx, TriIdx, i, TriVer[i][0], TriVer[i][1], TriVer[i][2], TriRef[i]);// Create a raw datatype to store the calculated elements' centersMidIdx = GmlNewSolutionData(LibIdx, GmlTriangles,1, GmlFlt4,"TriMid");// Compile the OpenCL source code with the two needed datatypes:// the vertex coordinates (read) and the triangles centers (write)CalMid = GmlCompileKernel( LibIdx, TriangleCenter,"CalMid", GmlTriangles,2, VerIdx, GmlReadMode,NULL, MidIdx, GmlWriteMode,NULL );// Launch the kernel on the GPUGmlLaunchKernel(LibIdx, CalMid);// Get the results back from the GPU and print itfor(i=0;i<NmbTri;i++){GmlGetDataLine(LibIdx, MidIdx, i, MidTab[i]);printf("triangle %d center = %g %g %g\n", i, MidTab[i][0], MidTab[i][1], MidTab[i][2]);}
Then the "OpenCL" part executed by the GPU device:
TriMid = (TriCrd[0] + TriCrd[1] + TriCrd[2]) /3.;
About
Porting meshing tools and solvers that deal with unstructured meshes on GPUs