# Parallel Sweep Loop?

**URL:** <https://forum.opentap.io/t/parallel-sweep-loop/307>\
**Category:** Technical\
**Created:** [May 10, 2021, 9:27pm UTC](https://forum.opentap.io/t/parallel-sweep-loop/307 "2021-05-10T21:27:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pythonized](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@pythonized](https://forum.opentap.io/u/pythonized)\
**Post date:** [May 10, 2021, 9:27pm UTC](https://forum.opentap.io/t/parallel-sweep-loop/307/1 "2021-05-10T21:27:51Z")

</div>

Hi! I’m currently exploring OpenTAP and I was wondering if there’s a way to achieve parallel execution on an array of sweep values. That’s something I would call “Parallel Sweep Loop”.

As an example:

```
PARENT -- Parallel Sweep Loop: Sweep Values = [DUT1, DUT2, DUT3 ...]
  CHILD 1
  ...
  CHILD N

```

That should result in sequential execution of CHILD steps on each DUT from the list, in parallel.

Is there a way to fabricate something like that using a magic combination of existing basic steps?

Thanks!

---

<div class="post-metadata">

**Author:** ![brennen\_direnzo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/brennen_direnzo/32/6_2.png) [@brennen\_direnzo](https://forum.opentap.io/u/brennen_direnzo)\
**Post date:** [May 10, 2021, 10:15pm UTC](https://forum.opentap.io/t/parallel-sweep-loop/307/2 "2021-05-10T22:15:12Z")

</div>

@pythonized first welcome to the community!

I would say today, we don’t have the concept of a Parallel Sweep. This is a really interesting idea though, and I encourage you to submit a feature request here:  
[https://gitlab.com/OpenTAP/opentap/-/issues/new?issue[assignee\_id]=&issue[milestone\_id]=](https://gitlab.com/OpenTAP/opentap/-/issues/new?issue%5Bassignee_id%5D=&issue%5Bmilestone_id%5D=)

You can see the code for the SweepLoop here, and it is explicitly blocking, but you can see what is being done here:

> <https://gitlab.com/OpenTAP/opentap/-/blob/master/BasicSteps/SweepLoop.cs#L430>

The closest we have would be leveraging the Parallel Step, the Sequence Step, and the “Parameterize on Parent” feature. So your test plan would be:

```auto
Parallel   
    Sequence - DUT1   
        Child 1...N   
    Sequence - DUT2  
        Child 1...N   
    Sequence - DUT3
        Child 1... N
    ...

```

So, not a perfect solution, but you can copy/paste the sequence block when adding new steps. Attached is a test plan and bench settings using the Demo plugin to give you a better idea:  
[ParallelSequences.TapPlan](https://forum.opentap.io/uploads/short-url/5HiYfRgfYI6lCOlh0iYnGZCiOz9.TapPlan) (4.8 KB)  
[DUTs.xml](https://forum.opentap.io/uploads/short-url/iViivzK4VtK4uPRoSTxWAtSY4ML.xml) (1.1 KB)  
[Instruments.xml](https://forum.opentap.io/uploads/short-url/pdo0hKB5xeff2OVaqABwYtdVWCx.xml) (1 KB)

Also, since you seem to be a fan of Python, be sure to look at our Python Plugin:  
[https://opentap.gitlab.io/Plugins/python/TAP%20Python%20Help/](https://opentap.gitlab.io/Plugins/python/TAP%20Python%20Help/)

---

<div class="post-metadata">

**Author:** ![pythonized](https://avatars.discourse-cdn.com/v4/letter/p/85f322/32.png) [@pythonized](https://forum.opentap.io/u/pythonized)\
**Post date:** [May 11, 2021, 9:12am UTC](https://forum.opentap.io/t/parallel-sweep-loop/307/3 "2021-05-11T09:12:22Z")

</div>

Thanks for a warm welcome and a swift reply @brennen_direnzo!

The workaround you suggested works indeed, I’ve actually came up with the identical one but didn’t like it as it was not dynamic enough. It was not very clear from my example but I would like to have a variable number of DUTs, and 3 is not the maximum. So you can expect a feature request 🙂

Also, thanks for the heads-up regarding the Python plugin. I’m already using it although I see some limitations. Which leads me to another question: if I want to implement something like Parallel Sweep myself, do you think it would be feasible to make it in Python or it’s more reasonable to do it natively in C#?

---

<div class="post-metadata">

**Author:** ![brennen\_direnzo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/brennen_direnzo/32/6_2.png) [@brennen\_direnzo](https://forum.opentap.io/u/brennen_direnzo)\
**Post date:** [May 11, 2021, 2:52pm UTC](https://forum.opentap.io/t/parallel-sweep-loop/307/4 "2021-05-11T14:52:53Z")

</div>

Great! Yes, I figured that may be the case. That is why I pointed out the copy/paste aspects but fully recognized that is ideal.

Sounds like you have made quite some progress already. As for implementing something in Python vs natively in C#, in general, our Python Plugin is an interface on top of the native C# (built using [Python.NET](http://pythonnet.github.io/) ) so, everything that existing in Python, exists in C#. In general we tend to implement generic features natively in C#, so that they can benefit all other interfaces, and not just one specific.

If you are interested there is a lightweight CLA for OpenTAP that you can find here, and then we can add you to the project: [CONTRIBUTING.md · master · OpenTAP / OpenTAP · GitLab](https://gitlab.com/OpenTAP/opentap/-/blob/master/CONTRIBUTING.md)

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [May 11, 2021, 6:59pm UTC](https://forum.opentap.io/t/parallel-sweep-loop/307/5 "2021-05-11T18:59:16Z")

</div>

> [@brennen\_direnzo](#):
>
> You can see the code for the SweepLoop here, and it is explicitly blocking

Does that mean that parallel sweep loops like below wouldn’t actually run in parallel?

```
Parallel   
    Sweep Loop - DUT1
    Sweep Loop - DUT2
    ...
    Sweep Loop - DUTN

```

---

<div class="post-metadata">

**Author:** ![brennen\_direnzo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/brennen_direnzo/32/6_2.png) [@brennen\_direnzo](https://forum.opentap.io/u/brennen_direnzo)\
**Post date:** [May 11, 2021, 7:05pm UTC](https://forum.opentap.io/t/parallel-sweep-loop/307/6 "2021-05-11T19:05:58Z")

</div>

In that case, each individual Sweep Loop will run in parallel. No issues there. But what is not possible (as things are today) is having each iteration of the Loop executing on its own thread/in parallel.

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [May 12, 2021, 1:54pm UTC](https://forum.opentap.io/t/parallel-sweep-loop/307/7 "2021-05-12T13:54:16Z")

</div>

Ah, I see what the OP is trying to do now. Thanks @brennen_direnzo
