i have a little program that searches for perfect numbers.
now it took it 36 minutes to get to the 5th number(and last one for longint) which is 33550336. as it worked i noticed in the task manager that it only used 25% of cpu the whole time and the memory usage was really low..
i was wondering if its possible to force it to use more? and find the 5th number in less time?

Recommended Answers

All 5 Replies

Use TThread.

It seems you aren't quite specifying your problem adequately.

First off, most CPU monitors are aggregate monitors, which means if you have multiple cores/processors it will only show what is utilized by the process thread. Which means, you likely have a 4-core system.

While TThread is far from your answer, it can be useful. You need to think seriously about how you are doing this program and see if you can simplify things or remove some steps. Also, look for opportunities for parallelism whereby you can design your algorithm to use multiple threads and therefore multiple cores.

The only solution to make this faster is to rethink what you are doing. Seems you have a lot of thought, experimentation, and testing ahead.

i do have a 4-core system.
i already have 3 different conditions in order to minimize the search(only search for even numbers for example).
maybe my knowledge in not so great in pascal/programming but i still wondered if i can make the program use more of the computer resources.
i'm not familiar with TThread , i did a search on it and it seems its not so simple to use it and if i understand correctly i can only use it if i have a way to split the program to parallel calculations right ?
i guess i can split the main loop as one will go from 2 to 36000000 with jumps of 4(2,6,10,14...) and another will go from 4 to 36000002(4,8,12,16...)
the jumps are of 4 because as i said i'm already ignoring the odd numbers.

Yes, you can't multi-thread a process unless you have a design that needs parallelism. I don't know precisely what you are doing, but what you describe should work as long as the threads don't touch any of the same resources in the system (excepting synchronization). TThread is the tool you want for using the other processors, but you need to be able to use it for the task at hand.

That said, the best thing to do for speed is more to look at how you are approaching the problem and simplify it. If you can find it, the GIMPS source would be educational for you in this regard.

maybe when i'll have some time i'll try to learn more about how to use TThread ..
i was hoping there is a simpler way to use more calculation power out of the cpu..
meanwhile with another improvement i made i was able to get to the 7th number
(137,438,691,328) in less than half an hour.. but from here its a very long way to the next one
thanks anyway for the help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.