© 2011 autodesk single job 1 processor 1 single job 2 single job 3 processor 2 processor 3 big job...

14
© 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single Job 6 Processor 2 Processor 3 Parallel programming in an AutoCAD application Gopinath Taget Senior Developer Consultant

Upload: allison-maxwell

Post on 11-Jan-2016

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

Parallel programming in an AutoCAD application

Gopinath TagetSenior Developer Consultant

Page 2: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Gopinath TagetAutodesk Developer NetworkAmericasAutodesk, Inc.

Gopinath Taget is a member of the Autodesk Developer Technical Services Team. He has more than 7 years of experience developing and supporting AutoCAD APIs, including ObjectARX, .NET, VBA and LISP.

Gopinath also has several years of experience in software development on other CAD platforms, including Microstation, Solidworks, and CATIA -- mainly using C++ and technologies such as MFC and COM. Gopinath was also involved in the development of Web-based applications for MapGuide and AutoCAD Map 3D. Gopinath has Master degrees in Civil Engineering and Software Systems.

About Me

Page 3: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

Class Summary

In this class you will learn about Problems implementing parallelism in an AutoCAD application Which portions of an application can be safely parallelized Latest .NET and C++ libraries for parallelism Synchronizing parallel execution in AutoCAD application

Page 4: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

Learning Objectives

At the end of this class, you will be able to: Implement parallelism in an AutoCAD application Understand safe methods for parallelism in an AutoCAD application Understand technologies and APIs available to implement parallelism

Page 5: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Issues with Parallel Programming in AutoCAD

Page 6: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

AutoCAD is an MFC Application

AutoCAD UI accessible only from UI thread AutoCAD Objects accessible only from UI thread Only one UI thread Only one message loop

Page 7: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

AutoCAD is not Thread Safe

No way to lock AutoCAD objects AutoCAD idle state can be complex to determine Idle state can be broken in unexpected ways Only message queue determines what gets executed Message queue too fine grained Lots of scope for race conditions

Page 8: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

“Safe” Parallel Programming in AutoCAD

Page 9: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

Best Practices

Asynchronous programming is your friend IsQuiescent is your friend Always use the AutoCAD message loop Use ActiveX API if you can Only perform non-Acad operations in threads

Page 10: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

Separate Executables

Poor man’s parallelism Send Messages to AutoCAD instance Use COM to communicate and control AutoCAD Other IPC technologies to exchange data

Page 11: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Useful Technologies for Parallel Programming

Page 12: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

.NET Task Parallel Library

Available with .NET 4.0 Concurrency made easy Integrated with LINQ to make PLINQ Optimizes based on CPU architecture

Page 13: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

Microsoft C++ Concurrency Runtime

High level of abstraction Two programming models

Asynchronous Agents Library (Actor based library) Parallel Pattern Library (Imperative Programming)

Allows customization of scheduler Resource manager as abstraction of hardware

Page 14: © 2011 Autodesk Single Job 1 Processor 1 Single Job 2 Single Job 3 Processor 2 Processor 3 Big Job 1 Big Job 2 Single Job 4 Processor 1 Single Job 5 Single

© 2011 Autodesk

Single Job 1 Processor 1

Single Job 2

Single Job 3

Processor 2

Processor 3

Big Job 1

Big Job 2Single Job 4 Processor 1

Single Job 5

Single Job 6

Processor 2

Processor 3

Autodesk, AutoCAD* [*if/when mentioned in the pertinent material, followed by an alphabetical list of all other trademarks mentioned in the material] are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and/or other countries. All other brand names, product names, or trademarks belong to their respective holders. Autodesk reserves the right to alter product and services offerings, and specifications and pricing at any time without notice, and is not responsible for typographical or graphical errors that may appear in this document. © 2011 Autodesk, Inc. All rights reserved.