Parallelism

Disadvantages of Execution Policies

  • May not have any effect

    • Not supported on some compilers
    • Not fully implemented on all compilers
    • May fall back to non policy version
  • Extra overhead

    • The algorithm may start up new threads
    • The algorithm must manage these threads

When to Use an Execution Policy?

  • Do not use an execution policy if

    • Your code has to be portable to other compilers
    • The task is essentially sequential
    • Operation order is important
    • The algorithm call throws exceptions
    • Unless immediate termination is acceptable
    • Preventing data races costs more than not using an execution policy
  • Consider using an execution policy if

    • Measurement shows a worthwhile improvement in performance
    • It can be done safely and correctly

Which Execution Policy to Use?

  • Sequenced execution is mainly used for debugging

    • Same as non-policy, but
    • Allows out of order execution
    • Terminates on exceptions
  • Parallel unsequenced execution

    • Has the most potential to improve performance
    • Also has the strictest requirements. Use when
    • Data races cannot occur
    • Code does not modify shared state
  • Parallel execution

    • Use when vectorization is not safe
    • Data races cannot occur, but code modifies shared state
  • Unsequenced execution (C++ 20)

    • Can be used with single threading
    • If code does not modify shared state