Prolog uses only 13% of CPU and takes an hour to complete

Thank you all for your help. I now have concurrent_forall working and am using 98% of the CPU. Unfortunately, the fan in my little laptop is not nearly as powerful as the chip, so it screams at me and throttles back the CPU speed, so I don’t get as much reduction in processing time as I had hoped. And, it did take me a while to realize that forall, never meant that “for all X from the generator, the action has been performed”, but rather “for all X from the generator, the test succeeds.” And that does make more sense in a Prologish sort of way. But I had to completely rewrite my test/action so that it always succeeded, but also instantiated a variable to tell me whether it succeeded successfully or failingly. Well, anyway it all works now. And thanks, again.

As I stated last time, multithreading is working now, at least in the original trials. However, I have added a new predicate in the concurrent section, and am observing behavior I do not understand.
In the editor, the new predicate is shown in bold red, which should indicate that it is never called. However, I know that it actually is called and does in fact produce correct answers. Although my program is only a few hundred lines long, I have searched through it to verify that the predicate is not defined somewhere else, and the part in bold red is indeed the only spot.
When I run the program now, it does use all 8 LPUs, but not at 98%. It varies from about 20 to 80%. Also, the CPU slows down drastically. Sometimes running at less than 1 GHz. With the original sequential version, it ran at 3.3 and when loaded with the first version of concurrent, it slowed to about 2.2, which I attributed to thermal throttling.
Does this make any sense to any of you? Would it help to upload a copy of the program?

Welcome to the fun world of concurrent programming, which I’ve been in for many years. One of the fundamental things to remember is Amdahl’s Law — roughly speaking: you can’t go faster than the slowest part of the system.

So, my guess is that your new predicate is the bottleneck, and other concurrent tasks are waiting for it to finish. You might try using profile/1 to see where the time is being used, and also to verify that your new predicate is being called. (There might, of course, be a glitch in the IDE or cross-referencer.)

As to the CPU performance — the obvious thing is try it on a desktop, which will probably have better thermal performance than a laptop.

You can upload your program, but I don’t know if I’ll have time to look at it. :wink:

I rearranged my new predicate so that it didn’t run the same other predicate twice, in parallel with itself. Now it seems to be working correctly. Of course, it still can’t overcome the limitations of the fan in my laptop.
I do still wonder what was going on when the system was using very little of the available CPU. It only has to write out 256 lines to a file, so it certainly wasn’t I/O bound. For now I don’t need to know that.
I still have that funny bold red display on one predicate that is definitely called (it’s the test in the forall part.), but I am not too worried about that.