SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
Dmitri Nesteruk
dmitri@activemesa.com
http://activemesa.com
http://spbalt.net
http://devtalk.net
“Premature optimization is the root of all evil.”

                                                    Donald Knuth
              Structured Programming with go to Statements, ACM
         Journal Computing Surveys, Vol 6, No. 4, Dec. 1974. p.268.


“In practice, it is often necessary to keep performance goals in mind
when first designing software, but the programmer balances the goals
of design and optimization.”

                                                      Wikipedia
               http://en.wikipedia.org/wiki/Program_optimization
Brief intro
   Why unmanaged code?
   Why parallelize?
P/Invoke
SIMD
OpenMP
Intel stack: TBB, MKL, IPP
GPGPU: Cuda, Accelerator
Miscellanea
Today                                 Tomorrow

 Threads & ThreadPool                  Tasks and TaskManager
 Sync structures                         Task
   Monitor.(Try)Enter/Exit               Future
   ReaderWriterLock(Slim)
   Mutex                               Data-level parallelism
   Semaphore                             Parallel.For/ForEach
 Wait handles
   Manual/AutoResetEvent
                                       Parallel LINQ
                                         AsParallel()
 Pulse & wait
 Async delegates
 Async simplifications
   F# async workflow
   AsyncEnumerator (PowerThreading)
Performance               Managed interfaces for
Low-level (fine-tuning)   SIMD/MPI-optimized
framework                 libraries
Instruction-level         Threading tools
parallelism                 Debugging
GPU SIMD                    Profiling
                            Inferencing
General vectorization
                          Cross-machine
Simple cross-machine
                          debugging
framework
                          Task management UI
WTF?!? Isn’t C# 5% faster than C?
   It depends.
Why is there a difference?
   More safety (e.g., CLR array bound checking)
   JIT: No auto-parallelization
   JIT: No SIMD
   Lack of fine control
IL can be every bit as fast as C/C++
   But this is only true for simple problems
   The code is only as good as the JITter
Libraries (MKL, IPP)

  OpenMP

     Intel TBB, Microsoft PPL

        SIMD (CPU & GPGPU)
Part I
A way of calling unmanaged C++ from .Net
   Not the same as C++/CLI
For interaction with ‘legacy’ systems
Can pass data between managed and
unmanaged code
   Literals (int, string)
   Pointers (e.g., pointer to array)
   Structures
Marshalling is taken care of by the runtime
Make a Win32 C++ DLL
   MYLIB_API int Add(int first, int second)
   {
     return first + second;
   }
   Specify a post-build step to copy DLL to .Net assembly
     Important: default DLL location is solution root
   Build the DLL
Make a .Net application
   [DllImport("MyLib.dll")]
   public static extern int Add(
     int first, int second);
Call the method
Basic C# ↔ C++ Interop
DLL not found                      Entry point not found
  Make sure post-build step          Make sure method names and
  copies DLL to target folder        signatures are equivalent
  Or that DLL is in PATH             Make sure calling convention
An attempt was made to load          matches
                                        [DllImport(…,
DLL with incorrect format                 CallingConvention=))
  DLL relies on other DLLs which     On 64-bit systems, specify entry
  are not found                      name explicitly
    Open Visual Studio command          Use dumpbin /exports
    prompt
                                        [DllImport(…,
    Use dumpbin /dependents               EntryPoint = "?Add@@YAHHH@Z"
    mylib.dll to find out
                                        No, extern "C " does not help
    Copy files to target dir
    This is common in Debug mode   It all works
  32-bit/64-bit mismatch             Congratulations!
Special cases          Handling them
  String handling        Marshal
    Unicode vs. ANSI     MarshalAsAttribute
    LP(C)WSTR            [In] and [Out]
  Arrays                 StructLayout
    fixed
                         IntPtr
  Memory allocation
                         … and lots more
  Calling convention
  “Bitness” issues
                       Handle on a case-by-case
  … and lots more!
                       basis
Make sure signatures
match
  Including return types!
To debug
  If your OS is 64-bit, make
  sure .Net assemblies
  compile in 32-bit mode
  Make sure unmanaged
  code debugging is turned
  on
In 64-bit                       Visit the P/Invoke wiki @
  Launch target DLL with        http://pinvoke.net
  the .Net assembly as target
    Good luck! :)
Part II
An API for multi-platform
shared-memory parallel
programming in C/C++
and Fortran.
Uses #pragma statements
to decorate code
Easy!!!
  Syntax can be learned very
  quickly
  Can be turned off and on
  in project settings
Enable it (disabled by default)




Use it!
   No further action necessary

To use configuration API
   #include <omp.h>
   Call methods, e.g., omp_get_num_procs()
void MultiplyMatricesDoubleOMP(
  int size, double* m1[], double* m2[], double* result[])
{
  int i, j, k;
  #pragma omp parallel for shared(size,m1,m2,result) private (i,j,k)
  for (i = 0; i < size; i++)
  {                                              #pragma omp parallel for
    for (j = 0; j < size; j++)                   Hints to the compiler that it’s
    {                                            worth parallelizing loop
      result[i][j] = 0;
      for (k = 0; k < size; k++)                 shared(size,m1,m2,result)
      {                                          Variables shared between all
        result[i][j] += m1[i][k] * m2[k][j];     threads
      }
    }                                            private(i,j,k)
                                                 Variables which have differing
  }
                                                 values in different threads
}
Using OpenMP in your C++ app
Homepage
http://openmp.org
cOMPunity (community of OMP users)
http://www.compunity.org/
OpenMP debug/optimization article (Russian)
http://bit.ly/BJbPU
VivaMP (static analyzer for OpenMP code)
http://viva64.com/vivamp-tool
Part III
Libraries save you from reinventing the wheel
   Tested
   Optimized (e.g., for multi-core, SIMD)
These typically have C++ and Fortran
interfaces
   Some also have MPI support
   Of course, there are .Net libraries too :)
The ‘trick’ is to use these libraries from C#
   Fortran-compatible API is tricky!
   Data structure passing can be quite arcane!
Intel makes multi-core processors
                        Multi-core know-how
                           Parallel Composer
                             C++ Compiler (autoparallelization, OpenMP 3.0)
Intel Parallel Studio




                             Libraries (Math Kernel Library, Integrated Performance
                             Primitives, Threading Building Blocks)
                             Parallel debugger extension
                           Parallel inspector (memory/threading errors)
                           Parallel amplifier (hotspots, concurrency, locks and
                           waits)
                           Parallel Advisor Lite
Low-level parallelization
framework from Intel
Lets you fine-tune code
for multi-core
Is a library
  Uses a set of primitives
Has OSS license
#include "tbb/parallel_for.h"
#include "tbb/blocked_range.h"
using namespace tbb;                         Functor
struct Average {
    float* input;
    float* output;
    void operator()( const blocked_range<int>& range ) const {
        for( int i=range.begin(); i!=range.end( ); ++i )
            output[i] = (input[i-1]+input[i]+input[i+1])*(1/3.0f);
    }
};
// Note: The input must be padded such that input[-1] and input[n]
// can be used to calculate the first and last output values.
void ParallelAverage( float* output, float* input, size_t n ) {
    Average avg;
    avg.input = input;
    avg.output = output;
                                                                 Library
    parallel_for(blocked_range<int>( 0, n, 1000 ), avg);
}                                                                  call
Integrated Performance            Math Kernel Library
Primitives
 High-performance libraries for     Optimized, multithreaded
   Signal processing                library for math
   Image processing                 Support for
   Computer vision                    BLAS
   Speech recognition                 LAPACK
   Data compression                   ScaLAPACK
   Cryptography                       Sparse Solvers
   String manipulation                Fast Fourier Transforms
   Audio processing                   Vector Math
   Video coding                       … and lots more
   Realistic rendering
 Also support codec
 construction
Part IV
CPU support for performing operations on
large registers
Normal-size data is loaded into 128-bit
registers
Operation on multiple elements with a single
instruction
   E.g., add 4 numbers at once
Requires special CPU instructions
   Less portable
Supported in C++ via ‘intrinsics’
SSE is an instruction set
   Initially called MMX (n/a on 64-bit CPUs)
   Now SSE and SSE2
Compiler intrinsics
   C++ functions that map to one or more SSE
   assembly instructions
Determining support
   Use cpuid
   Non-issue if you are
     A systems integrator
     Run your own servers (e.g., Asp.Net)
128-bit data types
   __m128
   __m128i (integer intrinsics)
   __m128d (double intrinsics)     } sse2
Operations for load and set
   __m128 a = _mm_set_ps(1,2,3,4);
   To get at data, dereference and choose type
     E.g., myValue.m128_f32[0] gets first float
Perform operations (add, multiply, etc.)
   E.g., _mm_mul_ps(first, second) multiplies two
   values yielding a third
Make or get data
   Either create with initialized values
   static __m128 factor =
      _mm_set_ps(1.0f, 0.3f, 0.59f, 0.11f);
   Or load it into a SIMD-sized memory location
   __m128 pixel;
   pixel.m128_f32[0] = s->m128i_u8[(p<<2)];
   Or convert an existing pointer
   __m128* pixel = (__m128*)(&my_array + p);
Perform a SIMD operation and get data
   pixel = _mm_mul_ps(pixel, factor);
Get the data
   const BYTE sum = (BYTE)(pixel.m128_f32[0]);
Image processing with SIMD
Part IV
Graphics cards have GPUs
These are highly parallelized
   Pipelining
   Useful for graphics
GPUs are programmable
   We can do math ops on vectors
   Mainly float, with double support emerging
GPUs have programmable parts
   Vertex shader (vertex position)
   Pixel shader (pixel colour)
Treat data as texture (render target)
   Load inputs as texture
   Use pixel shader
   Get data from result texture
Special languages used to program them
   HLSL (DirectX)
   GLSL (OpenGL)
High-level wrappers (CUDA, Accelerator)
A Microsoft Research project
   Not for commercial use
Uses a managed API
Employs data-parallel arrays
   Int
   Float
   Bool
   Bitmap-aware
Requires PS 2.0
Sorry! No demo.
Accelerator does not work on 64-bit :(
If a library already exists, use it
If C# is fast enough, use it
To speed things up, try
   TPL/PLINQ
   Manual Parallelization
   unsafe (can be combined with TPL)
If you are unhappy, then
   Write in C++
   Speculatively add OpenMP directives
   Fine-tune with TBB as needed
System.Drawing.Bitmap is slow
  Has very slow GetPixel()/SetPixel()
  methods
Can fix bitmap in memory and manipulate it in
unmanaged code
What we need to pass in
  Pointer to bitmap image data
  Bitmap width and height
  Bitmap stride (horizontal memory space)
Image-rendered headings with subpixel
postprocessing (http://bit.ly/10x0G8)
  WPF FlowDocument for initial generation
  C++/OpenMP for postprocessing
  Asp.Net for serving the result
Freeform rendered text with OpenType
features (http://bit.ly/1cCP50)
  Bitmap rendering in Direct2D (C++/lightweight
  COM API)
  OpenType markup language
a   l   b   v   o   b   q   l   l   k   u   t   m   y   w   m   w   r   e   e   r   q   q   m   q   i   q   d   n   w   g   s   s   w   d   a
v   p   d   v   n   u   x   j   l   s   y   t   u   b   n   b   y   c   t   h   r   r   y   u   v   a   s   t   a   d   t   n   z   f   f   x
g   q   h   b   j   j   p   y   o   w   s   i   g   i   c   i   i   g   s   o   f   n   f   r   j   f   d   c   f   g   m   k   w   u   y   j
v   b   v   e   m   i   t   i   j   x   u   v   w   s   j   u   g   u   y   l   b   o   c   m   y   k   u   b   w   s   w   n   p   x   i   o
k   a   y   c   q   o   s   u   n   k   s   c   g   x   j   x   j   e   q   p   h   j   i   a   c   m   j   z   h   c   k   v   x   k   a   k
f   e   c   r   u   u   x   q   p   p   k   o   f   w   g   x   b   v   j   m   b   e   l   e   e   w   k   s   c   v   n   n   o   g   c   z
w   w   f   w   i   n   e   h   j   q   l   h   x   u   v   j   o   m   h   g   s   x   a   j   z   b   d   n   u   a   s   c   n   a   j   i
x   w   i   n   w   z   j   d   s   p   n   w   i   p   c   n   d   s   r   m   j   h   z   q   j   g   b   w   j   m   e   z   k   j   v   a
z   o   u   q   w   d   c   j   c   f   o   x   w   t   h   v   s   r   h   o   m   j   y   n   a   u   p   p   u   p   h   z   n   s   j   r
m   b   z   o   w   k   i   n   t   h   l   i   k   z   w   m   z   m   f   x   c   h   o   m   w   x   b   s   m   x   u   c   j   x   o   s
h   x   u   e   t   p   u   x   e   o   v   l   h   a   y   p   f   f   v   a   x   z   x   l   z   u   l   c   l   n   q   g   e   g   m   x
y   k   k   k   q   j   n   h   p   i   j   w   i   p   d   d   a   x   z   s   z   e   m   p   c   l   i   m   s   u   g   e   i   z   o   m
q   p   r   p   d   w   m   y   q   t   o   v   m   p   T   H   E   y   E   N   D   v   z   d   c   z   x   m   g   q   q   r   h   n   b   j
i   b   q   i   p   x   n   h   w   i   d   o   h   m   a   w   c   x   m   g   h   c   y   r   i   k   n   p   n   d   m   c   x   l   z   e
h   h   s   c   l   f   s   y   l   k   j   s   p   t   d   q   e   b   k   v   u   x   k   m   k   z   p   g   k   e   n   a   f   h   h   r
o   x   v   w   k   u   j   u   t   n   e   u   q   f   a   d   n   e   d   y   y   y   f   c   z   c   a   p   x   y   f   b   r   w   e   y
o   f   a   v   f   h   z   r   y   a   n   z   u   q   r   o   g   n   f   p   x   l   j   y   l   u   a   n   r   d   o   r   v   k   m   f
j   y   n   h   p   c   c   t   k   x   y   t   b   f   j   r   n   x   g   c   z   h   s   p   c   e   i   q   g   x   k   p   f   g   r   n
l   y   i   i   f   t   i   s   b   i   f   c   k   c   h   e   s   l   w   y   s   u   p   d   v   x   b   r   l   q   l   k   i   z   d   z
w   s   a   w   r   i   i   u   m   n   i   x   r   c   j   n   d   h   n   w   g   s   f   s   i   l   h   a   b   h   l   h   x   m   v   p
t   e   g   k   n   o   i   s   g   s   x   v   b   o   k   e   c   i   j   y   b   e   d   r   t   p   e   x   v   r   c   w   u   v   d   s
d   o   a   z   t   t   m   u   i   u   v   u   b   p   l   w   c   p   x   n   k   k   v   a   a   v   b   b   s   e   e   f   d   b   f   y
i   v   c   j   k   r   g   r   y   t   j   a   m   f   v   h   b   f   s   b   z   l   i   n   a   x   c   l   r   l   z   i   v   l   c   b
n   u   d   l   l   g   u   y   r   t   t   u   q   t   l   y   j   l   q   u   h   a   o   u   o   p   t   g   v   l   q   q   r   k   r   q
y   p   l   z   d   x   n   q   n   q   v   t   f   b   u   h   r   y   n   k   f   q   i   t   h   i   u   w   i   n   m   l   o   c   c   c

Más contenido relacionado

La actualidad más candente

Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Sumant Tambe
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - englishJen Yee Hong
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Geeks Anonymes
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 FeaturesJan Rüegg
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersJen Yee Hong
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumlercorehard_by
 
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrencyxu liwei
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsStephane Gleizes
 
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++Mihai Todor
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewMarkus Schneider
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming languageSlawomir Dorzak
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Sumant Tambe
 

La actualidad más candente (20)

Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)Fun with Lambdas: C++14 Style (part 1)
Fun with Lambdas: C++14 Style (part 1)
 
Summary of C++17 features
Summary of C++17 featuresSummary of C++17 features
Summary of C++17 features
 
2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english2018 cosup-delete unused python code safely - english
2018 cosup-delete unused python code safely - english
 
C++11
C++11C++11
C++11
 
Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)Modern c++ (C++ 11/14)
Modern c++ (C++ 11/14)
 
C++ Presentation
C++ PresentationC++ Presentation
C++ Presentation
 
C++11 & C++14
C++11 & C++14C++11 & C++14
C++11 & C++14
 
C++ 11 Features
C++ 11 FeaturesC++ 11 Features
C++ 11 Features
 
Modern C++
Modern C++Modern C++
Modern C++
 
Basic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmersBasic c++ 11/14 for python programmers
Basic c++ 11/14 for python programmers
 
C++11
C++11C++11
C++11
 
C++20 the small things - Timur Doumler
C++20 the small things - Timur DoumlerC++20 the small things - Timur Doumler
C++20 the small things - Timur Doumler
 
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java scriptCodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
CodiLime Tech Talk - Grzegorz Rozdzialik: What the java script
 
C++11 concurrency
C++11 concurrencyC++11 concurrency
C++11 concurrency
 
C++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabsC++17 introduction - Meetup @EtixLabs
C++17 introduction - Meetup @EtixLabs
 
Gentle introduction to modern C++
Gentle introduction to modern C++Gentle introduction to modern C++
Gentle introduction to modern C++
 
Golang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / OverviewGolang and Eco-System Introduction / Overview
Golang and Eco-System Introduction / Overview
 
Introduction to Go programming language
Introduction to Go programming languageIntroduction to Go programming language
Introduction to Go programming language
 
Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)Fun with Lambdas: C++14 Style (part 2)
Fun with Lambdas: C++14 Style (part 2)
 
C
CC
C
 

Similar a Unmanaged Parallelization via P/Invoke

Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DMithun Hunsur
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsZvi Avraham
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futureTakayuki Muranushi
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSkills Matter
 
Virtual platform
Virtual platformVirtual platform
Virtual platformsean chen
 
Use C++ and Intel® Threading Building Blocks (Intel® TBB) for Hardware Progra...
Use C++ and Intel® Threading Building Blocks (Intel® TBB) for Hardware Progra...Use C++ and Intel® Threading Building Blocks (Intel® TBB) for Hardware Progra...
Use C++ and Intel® Threading Building Blocks (Intel® TBB) for Hardware Progra...Intel® Software
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++Ngeam Soly
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthingtonoscon2007
 
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...Maarten Balliauw
 
Parallel Programming on the ANDC cluster
Parallel Programming on the ANDC clusterParallel Programming on the ANDC cluster
Parallel Programming on the ANDC clusterSudhang Shankar
 

Similar a Unmanaged Parallelization via P/Invoke (20)

25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx25-MPI-OpenMP.pptx
25-MPI-OpenMP.pptx
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in D
 
Migration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming ModelsMigration To Multi Core - Parallel Programming Models
Migration To Multi Core - Parallel Programming Models
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Virtual platform
Virtual platformVirtual platform
Virtual platform
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
parallel-computation.pdf
parallel-computation.pdfparallel-computation.pdf
parallel-computation.pdf
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
Parallel computation
Parallel computationParallel computation
Parallel computation
 
Use C++ and Intel® Threading Building Blocks (Intel® TBB) for Hardware Progra...
Use C++ and Intel® Threading Building Blocks (Intel® TBB) for Hardware Progra...Use C++ and Intel® Threading Building Blocks (Intel® TBB) for Hardware Progra...
Use C++ and Intel® Threading Building Blocks (Intel® TBB) for Hardware Progra...
 
Multicore
MulticoreMulticore
Multicore
 
មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++មេរៀនៈ Data Structure and Algorithm in C/C++
មេរៀនៈ Data Structure and Algorithm in C/C++
 
Os Worthington
Os WorthingtonOs Worthington
Os Worthington
 
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
ConFoo Montreal - Microservices for building an IDE - The innards of JetBrain...
 
Parallel Programming on the ANDC cluster
Parallel Programming on the ANDC clusterParallel Programming on the ANDC cluster
Parallel Programming on the ANDC cluster
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 

Más de Dmitri Nesteruk

Good Ideas in Programming Languages
Good Ideas in Programming LanguagesGood Ideas in Programming Languages
Good Ideas in Programming LanguagesDmitri Nesteruk
 
Design Pattern Observations
Design Pattern ObservationsDesign Pattern Observations
Design Pattern ObservationsDmitri Nesteruk
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETDmitri Nesteruk
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++Dmitri Nesteruk
 
Introduction to Programming Bots
Introduction to Programming BotsIntroduction to Programming Bots
Introduction to Programming BotsDmitri Nesteruk
 
Converting Managed Languages to C++
Converting Managed Languages to C++Converting Managed Languages to C++
Converting Managed Languages to C++Dmitri Nesteruk
 
YouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue TrackerYouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue TrackerDmitri Nesteruk
 
Victor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UIVictor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UIDmitri Nesteruk
 
Dynamics CRM Data Integration
Dynamics CRM Data IntegrationDynamics CRM Data Integration
Dynamics CRM Data IntegrationDmitri Nesteruk
 
ReSharper Presentation for NUGs
ReSharper Presentation for NUGsReSharper Presentation for NUGs
ReSharper Presentation for NUGsDmitri Nesteruk
 
ReSharper Architecture & Extensions
ReSharper Architecture & ExtensionsReSharper Architecture & Extensions
ReSharper Architecture & ExtensionsDmitri Nesteruk
 

Más de Dmitri Nesteruk (20)

Good Ideas in Programming Languages
Good Ideas in Programming LanguagesGood Ideas in Programming Languages
Good Ideas in Programming Languages
 
Design Pattern Observations
Design Pattern ObservationsDesign Pattern Observations
Design Pattern Observations
 
CallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NETCallSharp: Automatic Input/Output Matching in .NET
CallSharp: Automatic Input/Output Matching in .NET
 
Design Patterns in Modern C++
Design Patterns in Modern C++Design Patterns in Modern C++
Design Patterns in Modern C++
 
C# Tricks
C# TricksC# Tricks
C# Tricks
 
Introduction to Programming Bots
Introduction to Programming BotsIntroduction to Programming Bots
Introduction to Programming Bots
 
Converting Managed Languages to C++
Converting Managed Languages to C++Converting Managed Languages to C++
Converting Managed Languages to C++
 
Monte Carlo C++
Monte Carlo C++Monte Carlo C++
Monte Carlo C++
 
Tpl DataFlow
Tpl DataFlowTpl DataFlow
Tpl DataFlow
 
YouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue TrackerYouTrack: Not Just an Issue Tracker
YouTrack: Not Just an Issue Tracker
 
Проект X2C
Проект X2CПроект X2C
Проект X2C
 
Domain Transformations
Domain TransformationsDomain Transformations
Domain Transformations
 
Victor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UIVictor CG Erofeev - Metro UI
Victor CG Erofeev - Metro UI
 
Developer Efficiency
Developer EfficiencyDeveloper Efficiency
Developer Efficiency
 
Distributed Development
Distributed DevelopmentDistributed Development
Distributed Development
 
Dynamics CRM Data Integration
Dynamics CRM Data IntegrationDynamics CRM Data Integration
Dynamics CRM Data Integration
 
ReSharper Presentation for NUGs
ReSharper Presentation for NUGsReSharper Presentation for NUGs
ReSharper Presentation for NUGs
 
ReSharper Architecture & Extensions
ReSharper Architecture & ExtensionsReSharper Architecture & Extensions
ReSharper Architecture & Extensions
 
Web mining
Web miningWeb mining
Web mining
 
Data mapping tutorial
Data mapping tutorialData mapping tutorial
Data mapping tutorial
 

Último

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdflior mazor
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdfChristopherTHyatt
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 

Último (20)

Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

Unmanaged Parallelization via P/Invoke

  • 2. “Premature optimization is the root of all evil.” Donald Knuth Structured Programming with go to Statements, ACM Journal Computing Surveys, Vol 6, No. 4, Dec. 1974. p.268. “In practice, it is often necessary to keep performance goals in mind when first designing software, but the programmer balances the goals of design and optimization.” Wikipedia http://en.wikipedia.org/wiki/Program_optimization
  • 3. Brief intro Why unmanaged code? Why parallelize? P/Invoke SIMD OpenMP Intel stack: TBB, MKL, IPP GPGPU: Cuda, Accelerator Miscellanea
  • 4. Today Tomorrow Threads & ThreadPool Tasks and TaskManager Sync structures Task Monitor.(Try)Enter/Exit Future ReaderWriterLock(Slim) Mutex Data-level parallelism Semaphore Parallel.For/ForEach Wait handles Manual/AutoResetEvent Parallel LINQ AsParallel() Pulse & wait Async delegates Async simplifications F# async workflow AsyncEnumerator (PowerThreading)
  • 5. Performance Managed interfaces for Low-level (fine-tuning) SIMD/MPI-optimized framework libraries Instruction-level Threading tools parallelism Debugging GPU SIMD Profiling Inferencing General vectorization Cross-machine Simple cross-machine debugging framework Task management UI
  • 6. WTF?!? Isn’t C# 5% faster than C? It depends. Why is there a difference? More safety (e.g., CLR array bound checking) JIT: No auto-parallelization JIT: No SIMD Lack of fine control IL can be every bit as fast as C/C++ But this is only true for simple problems The code is only as good as the JITter
  • 7. Libraries (MKL, IPP) OpenMP Intel TBB, Microsoft PPL SIMD (CPU & GPGPU)
  • 9. A way of calling unmanaged C++ from .Net Not the same as C++/CLI For interaction with ‘legacy’ systems Can pass data between managed and unmanaged code Literals (int, string) Pointers (e.g., pointer to array) Structures Marshalling is taken care of by the runtime
  • 10. Make a Win32 C++ DLL MYLIB_API int Add(int first, int second) { return first + second; } Specify a post-build step to copy DLL to .Net assembly Important: default DLL location is solution root Build the DLL Make a .Net application [DllImport("MyLib.dll")] public static extern int Add( int first, int second); Call the method
  • 11. Basic C# ↔ C++ Interop
  • 12. DLL not found Entry point not found Make sure post-build step Make sure method names and copies DLL to target folder signatures are equivalent Or that DLL is in PATH Make sure calling convention An attempt was made to load matches [DllImport(…, DLL with incorrect format CallingConvention=)) DLL relies on other DLLs which On 64-bit systems, specify entry are not found name explicitly Open Visual Studio command Use dumpbin /exports prompt [DllImport(…, Use dumpbin /dependents EntryPoint = "?Add@@YAHHH@Z" mylib.dll to find out No, extern "C " does not help Copy files to target dir This is common in Debug mode It all works 32-bit/64-bit mismatch Congratulations!
  • 13. Special cases Handling them String handling Marshal Unicode vs. ANSI MarshalAsAttribute LP(C)WSTR [In] and [Out] Arrays StructLayout fixed IntPtr Memory allocation … and lots more Calling convention “Bitness” issues Handle on a case-by-case … and lots more! basis
  • 14. Make sure signatures match Including return types! To debug If your OS is 64-bit, make sure .Net assemblies compile in 32-bit mode Make sure unmanaged code debugging is turned on In 64-bit Visit the P/Invoke wiki @ Launch target DLL with http://pinvoke.net the .Net assembly as target Good luck! :)
  • 16. An API for multi-platform shared-memory parallel programming in C/C++ and Fortran. Uses #pragma statements to decorate code Easy!!! Syntax can be learned very quickly Can be turned off and on in project settings
  • 17. Enable it (disabled by default) Use it! No further action necessary To use configuration API #include <omp.h> Call methods, e.g., omp_get_num_procs()
  • 18. void MultiplyMatricesDoubleOMP( int size, double* m1[], double* m2[], double* result[]) { int i, j, k; #pragma omp parallel for shared(size,m1,m2,result) private (i,j,k) for (i = 0; i < size; i++) { #pragma omp parallel for for (j = 0; j < size; j++) Hints to the compiler that it’s { worth parallelizing loop result[i][j] = 0; for (k = 0; k < size; k++) shared(size,m1,m2,result) { Variables shared between all result[i][j] += m1[i][k] * m2[k][j]; threads } } private(i,j,k) Variables which have differing } values in different threads }
  • 19. Using OpenMP in your C++ app
  • 20. Homepage http://openmp.org cOMPunity (community of OMP users) http://www.compunity.org/ OpenMP debug/optimization article (Russian) http://bit.ly/BJbPU VivaMP (static analyzer for OpenMP code) http://viva64.com/vivamp-tool
  • 22. Libraries save you from reinventing the wheel Tested Optimized (e.g., for multi-core, SIMD) These typically have C++ and Fortran interfaces Some also have MPI support Of course, there are .Net libraries too :) The ‘trick’ is to use these libraries from C# Fortran-compatible API is tricky! Data structure passing can be quite arcane!
  • 23. Intel makes multi-core processors Multi-core know-how Parallel Composer C++ Compiler (autoparallelization, OpenMP 3.0) Intel Parallel Studio Libraries (Math Kernel Library, Integrated Performance Primitives, Threading Building Blocks) Parallel debugger extension Parallel inspector (memory/threading errors) Parallel amplifier (hotspots, concurrency, locks and waits) Parallel Advisor Lite
  • 24. Low-level parallelization framework from Intel Lets you fine-tune code for multi-core Is a library Uses a set of primitives Has OSS license
  • 25. #include "tbb/parallel_for.h" #include "tbb/blocked_range.h" using namespace tbb; Functor struct Average { float* input; float* output; void operator()( const blocked_range<int>& range ) const { for( int i=range.begin(); i!=range.end( ); ++i ) output[i] = (input[i-1]+input[i]+input[i+1])*(1/3.0f); } }; // Note: The input must be padded such that input[-1] and input[n] // can be used to calculate the first and last output values. void ParallelAverage( float* output, float* input, size_t n ) { Average avg; avg.input = input; avg.output = output; Library parallel_for(blocked_range<int>( 0, n, 1000 ), avg); } call
  • 26. Integrated Performance Math Kernel Library Primitives High-performance libraries for Optimized, multithreaded Signal processing library for math Image processing Support for Computer vision BLAS Speech recognition LAPACK Data compression ScaLAPACK Cryptography Sparse Solvers String manipulation Fast Fourier Transforms Audio processing Vector Math Video coding … and lots more Realistic rendering Also support codec construction
  • 28. CPU support for performing operations on large registers Normal-size data is loaded into 128-bit registers Operation on multiple elements with a single instruction E.g., add 4 numbers at once Requires special CPU instructions Less portable Supported in C++ via ‘intrinsics’
  • 29. SSE is an instruction set Initially called MMX (n/a on 64-bit CPUs) Now SSE and SSE2 Compiler intrinsics C++ functions that map to one or more SSE assembly instructions Determining support Use cpuid Non-issue if you are A systems integrator Run your own servers (e.g., Asp.Net)
  • 30. 128-bit data types __m128 __m128i (integer intrinsics) __m128d (double intrinsics) } sse2 Operations for load and set __m128 a = _mm_set_ps(1,2,3,4); To get at data, dereference and choose type E.g., myValue.m128_f32[0] gets first float Perform operations (add, multiply, etc.) E.g., _mm_mul_ps(first, second) multiplies two values yielding a third
  • 31. Make or get data Either create with initialized values static __m128 factor = _mm_set_ps(1.0f, 0.3f, 0.59f, 0.11f); Or load it into a SIMD-sized memory location __m128 pixel; pixel.m128_f32[0] = s->m128i_u8[(p<<2)]; Or convert an existing pointer __m128* pixel = (__m128*)(&my_array + p); Perform a SIMD operation and get data pixel = _mm_mul_ps(pixel, factor); Get the data const BYTE sum = (BYTE)(pixel.m128_f32[0]);
  • 34. Graphics cards have GPUs These are highly parallelized Pipelining Useful for graphics GPUs are programmable We can do math ops on vectors Mainly float, with double support emerging
  • 35. GPUs have programmable parts Vertex shader (vertex position) Pixel shader (pixel colour) Treat data as texture (render target) Load inputs as texture Use pixel shader Get data from result texture Special languages used to program them HLSL (DirectX) GLSL (OpenGL) High-level wrappers (CUDA, Accelerator)
  • 36. A Microsoft Research project Not for commercial use Uses a managed API Employs data-parallel arrays Int Float Bool Bitmap-aware Requires PS 2.0
  • 37. Sorry! No demo. Accelerator does not work on 64-bit :(
  • 38.
  • 39. If a library already exists, use it If C# is fast enough, use it To speed things up, try TPL/PLINQ Manual Parallelization unsafe (can be combined with TPL) If you are unhappy, then Write in C++ Speculatively add OpenMP directives Fine-tune with TBB as needed
  • 40. System.Drawing.Bitmap is slow Has very slow GetPixel()/SetPixel() methods Can fix bitmap in memory and manipulate it in unmanaged code What we need to pass in Pointer to bitmap image data Bitmap width and height Bitmap stride (horizontal memory space)
  • 41. Image-rendered headings with subpixel postprocessing (http://bit.ly/10x0G8) WPF FlowDocument for initial generation C++/OpenMP for postprocessing Asp.Net for serving the result Freeform rendered text with OpenType features (http://bit.ly/1cCP50) Bitmap rendering in Direct2D (C++/lightweight COM API) OpenType markup language
  • 42. a l b v o b q l l k u t m y w m w r e e r q q m q i q d n w g s s w d a v p d v n u x j l s y t u b n b y c t h r r y u v a s t a d t n z f f x g q h b j j p y o w s i g i c i i g s o f n f r j f d c f g m k w u y j v b v e m i t i j x u v w s j u g u y l b o c m y k u b w s w n p x i o k a y c q o s u n k s c g x j x j e q p h j i a c m j z h c k v x k a k f e c r u u x q p p k o f w g x b v j m b e l e e w k s c v n n o g c z w w f w i n e h j q l h x u v j o m h g s x a j z b d n u a s c n a j i x w i n w z j d s p n w i p c n d s r m j h z q j g b w j m e z k j v a z o u q w d c j c f o x w t h v s r h o m j y n a u p p u p h z n s j r m b z o w k i n t h l i k z w m z m f x c h o m w x b s m x u c j x o s h x u e t p u x e o v l h a y p f f v a x z x l z u l c l n q g e g m x y k k k q j n h p i j w i p d d a x z s z e m p c l i m s u g e i z o m q p r p d w m y q t o v m p T H E y E N D v z d c z x m g q q r h n b j i b q i p x n h w i d o h m a w c x m g h c y r i k n p n d m c x l z e h h s c l f s y l k j s p t d q e b k v u x k m k z p g k e n a f h h r o x v w k u j u t n e u q f a d n e d y y y f c z c a p x y f b r w e y o f a v f h z r y a n z u q r o g n f p x l j y l u a n r d o r v k m f j y n h p c c t k x y t b f j r n x g c z h s p c e i q g x k p f g r n l y i i f t i s b i f c k c h e s l w y s u p d v x b r l q l k i z d z w s a w r i i u m n i x r c j n d h n w g s f s i l h a b h l h x m v p t e g k n o i s g s x v b o k e c i j y b e d r t p e x v r c w u v d s d o a z t t m u i u v u b p l w c p x n k k v a a v b b s e e f d b f y i v c j k r g r y t j a m f v h b f s b z l i n a x c l r l z i v l c b n u d l l g u y r t t u q t l y j l q u h a o u o p t g v l q q r k r q y p l z d x n q n q v t f b u h r y n k f q i t h i u w i n m l o c c c