digitalmars.D.learn - Different Output after each execution
- Vino.B (110/110) Aug 18 2017 Hi All,
- ikod (3/8) Aug 18 2017 Do you expect some strict execution order when you run 'parallel'
- Vino (3/13) Aug 18 2017 Yes, the order of execution should be the same as the order of
- Moritz Maxeiner (13/27) Aug 18 2017 Then you cannot parallelize the work[1], use:
- Moritz Maxeiner (5/34) Aug 18 2017 Small correction: You *could* parallelize the conversion to
- Vino.B (8/46) Aug 18 2017 Hi,
- Moritz Maxeiner (13/62) Aug 18 2017 Negating the filtering rule should yield you the inverse set:
- Vino.B (3/17) Aug 19 2017 Thank you very much, it resolved the issue and also update my
Hi All,
I have written a small program to just list the directories, but
when i run the program each time i am getting different output,
hence request you help, below is the code
Program:
import std.file: dirEntries, isFile, SpanMode, remove;
import std.stdio: writefln;
import std.algorithm: filter;
import std.parallelism: parallel;
import std.array: array;
import std.datetime;
auto AgedDirlst = [ "C:\\Temp\\TEAM", "C:\\Temp\\PROD_TEAM",
"C:\\Temp\\BACKUP", "C:\\Temp\\EXPORT",
"C:\\Temp\\sapnas3\\BACKUP", "C:\\Temp\\EXPORT"];
void AgedDir (string[] Dirlist)
{
for (auto i = 0; i < Dirlist.length; ++i)
{
auto dFiles = dirEntries(Dirlist[i],
SpanMode.shallow).filter!(a => a.isDir);
foreach (d; parallel(dFiles , 1))
{
writefln("%-63s %.20s", d, d.timeCreated().toSimpleString);
}
}
}
void main ()
{
AgedDir(AgedDirlst);
}
If i replace the line(.isDir to .isFile) "auto dFiles =
dirEntries(Dirlist[i], SpanMode.shallow).filter!(a => a.isDir)"
to auto dFiles = dirEntries(Dirlist[i],
SpanMode.shallow).filter!(a => a.isFile), then is it working
perfectly.
From,
Vino.B
Output
C:\Users\Admin\Desktop\Script\D>rdmd AgedDir.d
C:\Temp\TEAM\DIR1
2017-Aug-16 18:49:21
C:\Temp\TEAM\DIR1
2017-Aug-16 18:49:21
C:\Temp\TEAM\DND1
2017-Jun-30 21:02:09
C:\Temp\TEAM\DIR2
2017-Jun-29 23:21:36
C:\Temp\TEAM\DND5
2017-Jun-30 23:49:24
C:\Temp\PROD_TEAM\dir1
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\dir1
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\dir2
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\DND1
2017-Jun-30 21:08:32
C:\Users\Admin\Desktop\Script\D>rdmd AgedDir.d
C:\Temp\TEAM\DIR1
2017-Aug-16 18:49:21
C:\Temp\TEAM\DIR2
2017-Jun-29 23:21:36
C:\Temp\TEAM\DND1
2017-Jun-30 21:02:09
C:\Temp\TEAM\DND5
2017-Jun-30 23:49:24
C:\Temp\PROD_TEAM\dir1
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\dir1
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\dir2
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\DND1
2017-Jun-30 21:08:32
C:\Users\Admin\Desktop\Script\D>rdmd AgedDir.d
C:\Temp\TEAM\DND1
2017-Jun-30 21:02:09
C:\Temp\TEAM\DIR1
2017-Aug-16 18:49:21
C:\Temp\TEAM\DIR2
2017-Jun-29 23:21:36
C:\Temp\TEAM\DND5
2017-Jun-30 23:49:24
C:\Temp\PROD_TEAM\dir1
2017-Jun-30 05:38:05_TEAM\dir2
C:\Temp\PROD_TEAM\dir1
2017-Jun-30 05:38:05_TEAM\dir2
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\DND1
2017-Jun-30 21:08:32
C:\Users\Admin\Desktop\Script\D>rdmd AgedDir.d
C:\Temp\TEAM\DIR1
2017-Aug-16 18:49:21
C:\Temp\TEAM\DIR1
2017-Aug-16 18:49:21
C:\Temp\TEAM\DND1
2017-Jun-30 21:02:09
C:\Temp\TEAM\DIR2 C:\Temp\TEAM\DND5
2017-Jun-30 23:49:24
C:\Temp\TEAM\DIR2 C:\Temp\TEAM\DND5
2017-Jun-30 23:49:24
2017-Jun-29 23:21:36
C:\Temp\PROD_TEAM\dir1
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\dir1
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\dir2
2017-Jun-30 05:38:05
C:\Temp\PROD_TEAM\DND1
2017-Jun-30 21:08:32
Aug 18 2017
On Friday, 18 August 2017 at 08:00:26 UTC, Vino.B wrote:Hi All, I have written a small program to just list the directories, but when i run the program each time i am getting different output, hence request you help, below is the code [...]Do you expect some strict execution order when you run 'parallel' foreach?
Aug 18 2017
On Friday, 18 August 2017 at 08:34:39 UTC, ikod wrote:On Friday, 18 August 2017 at 08:00:26 UTC, Vino.B wrote:Yes, the order of execution should be the same as the order of the directory provided to scan.Hi All, I have written a small program to just list the directories, but when i run the program each time i am getting different output, hence request you help, below is the code [...]Do you expect some strict execution order when you run 'parallel' foreach?
Aug 18 2017
On Friday, 18 August 2017 at 10:06:04 UTC, Vino wrote:On Friday, 18 August 2017 at 08:34:39 UTC, ikod wrote:Then you cannot parallelize the work[1], use: --- auto dFiles = dirEntries(Dirlist[i], SpanMode.shallow).filter!(a => a.isDir); foreach (d; dFiles) { writefln("%-63s %.20s", d, d.timeCreated().toSimpleString); } --- [1] You cannot parallelize computations that depend on each other, which you make yours do by requiring a specific order of execution.On Friday, 18 August 2017 at 08:00:26 UTC, Vino.B wrote:Yes, the order of execution should be the same as the order of the directory provided to scan.Hi All, I have written a small program to just list the directories, but when i run the program each time i am getting different output, hence request you help, below is the code [...]Do you expect some strict execution order when you run 'parallel' foreach?
Aug 18 2017
On Friday, 18 August 2017 at 10:50:28 UTC, Moritz Maxeiner wrote:On Friday, 18 August 2017 at 10:06:04 UTC, Vino wrote:Small correction: You *could* parallelize the conversion to string `d.timeCreated().toSimpleString`, but then you'd need to merge the resulting sets of strings generated in each work unit to regain the original order.On Friday, 18 August 2017 at 08:34:39 UTC, ikod wrote:Then you cannot parallelize the work[1], use: --- auto dFiles = dirEntries(Dirlist[i], SpanMode.shallow).filter!(a => a.isDir); foreach (d; dFiles) { writefln("%-63s %.20s", d, d.timeCreated().toSimpleString); } --- [1] You cannot parallelize computations that depend on each other, which you make yours do by requiring a specific order of execution.On Friday, 18 August 2017 at 08:00:26 UTC, Vino.B wrote:Yes, the order of execution should be the same as the order of the directory provided to scan.Hi All, I have written a small program to just list the directories, but when i run the program each time i am getting different output, hence request you help, below is the code [...]Do you expect some strict execution order when you run 'parallel' foreach?
Aug 18 2017
On Friday, 18 August 2017 at 11:24:24 UTC, Moritz Maxeiner wrote:On Friday, 18 August 2017 at 10:50:28 UTC, Moritz Maxeiner wrote:Hi, Thank you very much, it worked and need one more help, with the below line i am able to list all directories which contains the pattern *DND*, now i need the revers, list all the directories expect those containing the pattern *DND*. dirEntries(i, SpanMode.shallow).filter!(a => a.isDir).filter!(a => globMatch(a.baseName, "*DND*"))On Friday, 18 August 2017 at 10:06:04 UTC, Vino wrote:Small correction: You *could* parallelize the conversion to string `d.timeCreated().toSimpleString`, but then you'd need to merge the resulting sets of strings generated in each work unit to regain the original order.On Friday, 18 August 2017 at 08:34:39 UTC, ikod wrote:Then you cannot parallelize the work[1], use: --- auto dFiles = dirEntries(Dirlist[i], SpanMode.shallow).filter!(a => a.isDir); foreach (d; dFiles) { writefln("%-63s %.20s", d, d.timeCreated().toSimpleString); } --- [1] You cannot parallelize computations that depend on each other, which you make yours do by requiring a specific order of execution.On Friday, 18 August 2017 at 08:00:26 UTC, Vino.B wrote:Yes, the order of execution should be the same as the order of the directory provided to scan.Hi All, I have written a small program to just list the directories, but when i run the program each time i am getting different output, hence request you help, below is the code [...]Do you expect some strict execution order when you run 'parallel' foreach?
Aug 18 2017
On Friday, 18 August 2017 at 15:46:13 UTC, Vino.B wrote:On Friday, 18 August 2017 at 11:24:24 UTC, Moritz Maxeiner wrote:Negating the filtering rule should yield you the inverse set: --- dirEntries(i, SpanMode.shallow).filter!(a => a.isDir).filter!(a => !globMatch(a.baseName, "*DND*")) --- Also I don't see a reason to use two filter invocations here, you can join the conditions to a single filter (same for the unnegated one): --- dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")) ---On Friday, 18 August 2017 at 10:50:28 UTC, Moritz Maxeiner wrote:Hi, Thank you very much, it worked and need one more help, with the below line i am able to list all directories which contains the pattern *DND*, now i need the revers, list all the directories expect those containing the pattern *DND*. dirEntries(i, SpanMode.shallow).filter!(a => a.isDir).filter!(a => globMatch(a.baseName, "*DND*"))On Friday, 18 August 2017 at 10:06:04 UTC, Vino wrote:Small correction: You *could* parallelize the conversion to string `d.timeCreated().toSimpleString`, but then you'd need to merge the resulting sets of strings generated in each work unit to regain the original order.On Friday, 18 August 2017 at 08:34:39 UTC, ikod wrote:Then you cannot parallelize the work[1], use: --- auto dFiles = dirEntries(Dirlist[i], SpanMode.shallow).filter!(a => a.isDir); foreach (d; dFiles) { writefln("%-63s %.20s", d, d.timeCreated().toSimpleString); } --- [1] You cannot parallelize computations that depend on each other, which you make yours do by requiring a specific order of execution.On Friday, 18 August 2017 at 08:00:26 UTC, Vino.B wrote:Yes, the order of execution should be the same as the order of the directory provided to scan.Hi All, I have written a small program to just list the directories, but when i run the program each time i am getting different output, hence request you help, below is the code [...]Do you expect some strict execution order when you run 'parallel' foreach?
Aug 18 2017
On Friday, 18 August 2017 at 16:53:46 UTC, Moritz Maxeiner wrote:On Friday, 18 August 2017 at 15:46:13 UTC, Vino.B wrote:Thank you very much, it resolved the issue and also update my code as advised.[...]Negating the filtering rule should yield you the inverse set: --- dirEntries(i, SpanMode.shallow).filter!(a => a.isDir).filter!(a => !globMatch(a.baseName, "*DND*")) --- Also I don't see a reason to use two filter invocations here, you can join the conditions to a single filter (same for the unnegated one): --- dirEntries(i, SpanMode.shallow).filter!(a => a.isDir && !globMatch(a.baseName, "*DND*")) ---
Aug 19 2017








Vino.B <vino.bheeman hotmail.com>