I am having 8 powershell scripts. Few of them having dependencies. It means they can’t be executed in parallel. They should be executed on after another.
Some of the Powershell scripts has no dependency and it can be executed in parallel.
Following is the dependency explained in detail
Powershell scripts 1, 2, and 3 depend on nothing else Powershell script 4 depends on Powershell script 1 Powershell script 5 depends on Powershell scripts 1, 2, and 3 Powershell script 6 depends on Powershell scripts 3 and 4 Powershell script 7 depends on Powershell scripts 5 and 6 Powershell script 8 depends on Powershell script 5
I knew that by manually hard coding the dependency is possible. But 10 more powershell scripting may be added and dependency among them may added.
Has any one acheived parallelism by finding dependency? If so please share me how to proceed.
How familiar with parallel programming in general are you? Have you heard of and used the concept of mutual exclusion? The concept in general is to use some kind of messaging/locking mechanism to protect a shared resource among different parallel threads.
In your case, you’re making the dividing lines be the scripts themselves – which I think may make this much simpler than most of the techniques outlined in that wikipedia article. Would this simple template work for what you’re looking for?
The good news is that this would allow for flexible changing of dependencies. Every script writes a file, making no assumption about whether someone else is waiting for them or not. Changing the dependency of a particular script would be a simple one-line change or change of input parameter.
This is definitely not a perfect solution though. For instance what would happen if a script fails (or your script can exit in multiple different code paths but you forget to write the file in one of them)? This could cause a deadlock situation where no dependent scripts will get kicked off. The other bad thing is the busy wait of sleeping or spinning while waiting for the right files to get created – this could be corrected by implementing an Event-based approach where you have the OS watch the directory for changed.
Hope this helps and isn’t all garbage.