# First attempt at a multithread app



## Solaris17 (Nov 25, 2011)

this one is used to process prime numbers using the Fibonacci sequence. their is no output (console app) other then telling you it is testing. Try to be a tad kind but im open to ideas and im eager for your results.

Updated. After about 16 hours I think I have it about were i want it.

999999999 iterations
Supports 24 core processors.
Now displays start time 
Displays run time in 1 second intervals so you know if it hangs.
keeps a log file Prime Gen.txt in C:\ That displays when each thread was started.
Log file now appends so it will continue the log every time you start the program.
Added Warnings and other misc info.


----------



## Kreij (Nov 25, 2011)

The little app started up fine, pegged all four of my CPUs at 100% and ran for several minutes before I stopped it because I got impatient. 

I'm not sure what kind of ideas you are asking for, Sol.


----------



## Athlon2K15 (Nov 25, 2011)

works


----------



## fullinfusion (Nov 25, 2011)

works fine on my 8150 but not sure how long its to run. anyways pegs all 8


----------



## Solaris17 (Nov 25, 2011)

honestly im not entirely sure what im looking for I just wanted it to work.


----------



## Kreij (Nov 25, 2011)

If you want us to take a look at the source to give you ideas, post it up.
If not, that's fine too.

What launguage did you write it in?


----------



## cheesy999 (Nov 25, 2011)

seems to work

is it supposed to use close to 900MB of ram though?


----------



## Solaris17 (Nov 25, 2011)

Kreij said:


> If you want us to take a look at the source to give you ideas, post it up.
> If not, that's fine too.
> 
> What launguage did you write it in?


C# im using loops. Ill probably post up the source when im close to getting what I want but I dont want the help yet i want to get better on my own. When I post it up then ill take all the help I can get but im waiting till im about out of ideas.



cheesy999 said:


> seems to work
> 
> is it supposed to use close to 900MB of ram though?



yes Its loading alot of into because its checking millions of numbers.


----------



## Chicken Patty (Nov 25, 2011)

I'll try it when I get home dude. Give you some feedback.


----------



## Solaris17 (Nov 25, 2011)

Added an updated Version.


----------



## Solaris17 (Nov 26, 2011)

Updated. After about 16 hours I think I have it about were i want it.

999999999 iterations
Supports 24 core processors.
Now displays start time 
Displays run time in 1 second intervals so you know if it hangs.
keeps a log file Prime Gen.txt in C:\ That displays when each thread was started.
Log file now appends so it will continue the log every time you start the program.
Added Warnings and other misc info.

I know the program is nothing fancy but it doesnt require an installer its 10kb and loads even the most powerful systems. Now with the ability (via time stamp) to tell you when it hangs.

I know theirs prime 95 etc but I dont think its bad for my first multithread app and i mean lets be real you can carry it on a floppy drive.


----------



## de.das.dude (Nov 26, 2011)

hmm i needs to update my .net


----------



## Chicken Patty (Nov 26, 2011)

Seems to work fine for me...


----------



## pantherx12 (Nov 26, 2011)

This a good stress tester?


----------



## Solaris17 (Nov 26, 2011)

pantherx12 said:


> This a good stress tester?



100% CPU load. ~1GB ram usage


Chicken Patty said:


> Seems to work fine for me...
> 
> http://img.techpowerup.org/111126/Capture025.jpg



im in miami bitch


----------



## pantherx12 (Nov 26, 2011)

Solaris17 said:


> 100% CPU load. ~1GB ram usage
> 
> 
> im in miami bitch



I suspect I shall insta crash then


----------



## Solaris17 (Nov 26, 2011)

pantherx12 said:


> I suspect I shall insta crash then



then it does what it was made to do


----------



## pantherx12 (Nov 26, 2011)

Solaris17 said:


> then it does what it was made to do




No insta crash  will leave it running though.

Prime 95 large ffts causes my cpu to insta crash with the 4th core enabled : [


----------



## Chicken Patty (Nov 26, 2011)

Solaris17 said:


> 100% CPU load. ~1GB ram usage
> 
> 
> im in miami bitch



Are you?   or you just singing the song...


----------



## Solaris17 (Nov 26, 2011)

Chicken Patty said:


> Are you?   or you just singing the song...



the song though id take a trip to meet you (always worked when easy rhino passed by me) and im scheduled to visit sneeky and athlon (same state) im more of a tampa guy born and raised like the west coast atleast before it was an oil filter.


----------



## Chicken Patty (Nov 26, 2011)

Solaris17 said:


> the song though id take a trip to meet you (always worked when easy rhino passed by me) and im scheduled to visit sneeky and athlon (same state) im more of a tampa guy born and raised like the west coast atleast before it was an oil filter.



 Where you stay at now again?


----------



## Solaris17 (Nov 26, 2011)

Chicken Patty said:


> Where you stay at now again?



current server is a tad north of concord NH


----------



## Chicken Patty (Nov 26, 2011)

Solaris17 said:


> current server is a tad north of concord NH



Too far for me ATM.


----------



## Kreij (Nov 26, 2011)

WE WANT CODE! WE WANT CODE!
#OccupySolaris


----------



## Athlon2K15 (Nov 26, 2011)

Solaris17 said:


> the song though id take a trip to meet you (always worked when easy rhino passed by me) *and im scheduled to visit sneeky and athlon* (same state) im more of a tampa guy born and raised like the west coast atleast before it was an oil filter.



That was three years ago before you went AWOL i dont know what kind of STD's your carrying now


----------



## Solaris17 (Nov 26, 2011)

Kreij said:


> WE WANT CODE! WE WANT CODE!
> #OccupySolaris




```
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.Threading;

namespace Prime_Gen
{
    class Program
    {
        static bool[] ThreadsFinished;
        static bool[] nums;

        static bool AllThreadsFinished()
        {
            bool allThreadsFinished = true;
            foreach (var threadFinished in ThreadsFinished)
            {
                allThreadsFinished = threadFinished;
            }
            return allThreadsFinished;
        }

        static bool isPrime(int n)
        {
            Console.WriteLine("Run Time {0}", DateTime.Now);
            if (n < 2) { return false; }
            if (n == 2) { return true; }
            if (n % 2 == 0) { return false; }
            int d = 3;
            while (d * d <= n)
            {
                if (n % d == 0) { return false; }
                d += 2;
            }
            return true;
        }

        static void MarkPrimes(int startNumber, int stopNumber, int ThreadNr)
        {
            for (int j = startNumber; j < stopNumber; j++)
                nums[j] = isPrime(j);
            lock (typeof(Program))
            {
                ThreadsFinished[ThreadNr] = true;
            }
        }

        static void Main(string[] args)
        {
            StreamWriter Logline;
            Logline = File.AppendText("c:\\Prime Gen.txt");
            Logline.WriteLine("Threads Started (1-24) at:");
            Logline.Close();
            Console.WriteLine("This program is intended to Stress test a CPU upto 24 cores. At 100% load.");
            Console.WriteLine("Warning This program uses ALOT of RAM! (~1GB)");
            Console.WriteLine("This program will write a log file to C:/.");
            Console.WriteLine("Processing 999999999 Iterations of the Fibonacci Sequence.");
            Console.WriteLine("==========================================================================");
            Console.WriteLine("Start Time {0}", DateTime.Now);
            Console.WriteLine("==========================================================================");
            int nrNums = 999999999;
            int nrThreads = 24;
            ThreadsFinished = new bool[nrThreads];
            nums = new bool[nrNums];
            nums[0] = false;
            nums[1] = false;
            for (int i = 2; i < nrNums; i++)
                nums[i] = true;
            int interval = (int)(nrNums / nrThreads);
            int startNum = 0;
            var threads = new List<Thread>();
            for (int i = 0; i < nrThreads; i++)

            {
                var localStartNum = startNum;
                var localIndex = i;
                                var _thread = new System.Threading.Thread(() =>
                                     MarkPrimes(localStartNum,
                                                Math.Min(localStartNum + interval, nrNums),
                                                localIndex));
                                StreamWriter OurStream;
                                OurStream = File.AppendText("c:\\Prime Gen.txt");
                                OurStream.WriteLine("Log Time {0}", DateTime.Now);
                                OurStream.Close();
                startNum = startNum + interval;
                _thread.IsBackground = true;
                _thread.Start();
                threads.Add(_thread);
                            }

            foreach (var thread in threads)
            {
                thread.Join();
            }
        }
    }
}
```

Have fun. And jeez way to wait. I have to look semi competent before I give it to you (im self taught I know the code is dirty but their are big gaps in my education) but Im all about the sharing of knowledge full source distribution all the way. Bad Kreij for thinking any different! Way to make me embarrass myself.


----------



## Kreij (Nov 27, 2011)

Don't be silly, Sol ... there is nothing embarrasing about your code.
I haven't made extensive use of multi-threaded code either, and wanted to see what you were doing.
FordGT is better suited to critique MT code than I am. 

You motivated me to try a MT project. It's got a few bugs and not working correctly at all.


----------



## Kreij (Nov 29, 2011)

Hey Sol, have you looked into the Task Parallel Library that is built into .Net 4 ?
I have not tried anything with it yet.

My little program works !! LOL
It's just a little UI that starts another thread to monitor CPU usage on your various cores. 
Basically a really dumbed down Task Manager.


----------



## Solaris17 (Nov 29, 2011)

Kreij said:


> Hey Sol, have you looked into the Task Parallel Library that is built into .Net 4 ?
> I have not tried anything with it yet.
> 
> My little program works !! LOL
> ...



I haven't but I'll play with it thanks!


----------



## Kreij (Nov 29, 2011)

My program does something odd.
If I start it and check "Monitor processor usage", it shows the cpu usage okay, but if grab another window and move it around wildly my app minimizes. 
It doesn't crash, it just minimizes to the task bar.


----------

