Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7447583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:39:20+00:00 2026-05-29T12:39:20+00:00

This is quite an interesting question so let me set the scene. I work

  • 0

This is quite an interesting question so let me set the scene. I work at The National Museum of Computing, and we have just managed to get a Cray Y-MP EL super computer from 1992 running, and we really want to see how fast it can go!

We decided the best way to do this was to write a simple C program that would calculate prime numbers and show how long it took to do so, then run the program on a fast modern desktop PC and compare the results.

We quickly came up with this code to count prime numbers:

#include <stdio.h>
#include <time.h>

void main() {
    clock_t start, end;
    double runTime;
    start = clock();
    int i, num = 1, primes = 0;

    while (num <= 1000) { 
        i = 2; 
        while (i <= num) { 
            if(num % i == 0)
                break;
            i++; 
        }
        if (i == num)
            primes++;

        system("clear");
        printf("%d prime numbers calculated\n",primes);
        num++;
    }

    end = clock();
    runTime = (end - start) / (double) CLOCKS_PER_SEC;
    printf("This machine calculated all %d prime numbers under 1000 in %g seconds\n", primes, runTime);
}

Which on our dual core laptop running Ubuntu (The Cray runs UNICOS), worked perfectly, getting 100% CPU usage and taking about 10 minutes or so. When I got home I decided to try it on my hex-core modern gaming PC, and this is where we get our first issues.

I first adapted the code to run on Windows since that is what the gaming PC was using, but was saddened to find that the process was only getting about 15% of the CPU’s power. I figured that must be Windows being Windows, so I booted into a Live CD of Ubuntu thinking that Ubuntu would allow the process to run with its full potential as it had done earlier on my laptop.

However I only got 5% usage! So my question is, how can I adapt the program to run on my gaming machine in either Windows 7 or live Linux at 100% CPU utilisation? Another thing that would be great but not necessary is if the end product can be one .exe that could be easily distributed and ran on Windows machines.

Thanks a lot!

P.S. Of course this program didn’t really work with the Crays 8 specialist processors, and that is a whole other issue… If you know anything about optimising code to work on 90’s Cray super computers give us a shout too!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T12:39:21+00:00Added an answer on May 29, 2026 at 12:39 pm

    If you want 100% CPU, you need to use more than 1 core. To do that, you need multiple threads.

    Here’s a parallel version using OpenMP:

    I had to increase the limit to 1000000 to make it take more than 1 second on my machine.

    #include <stdio.h>
    #include <time.h>
    #include <omp.h>
    
    int main() {
        double start, end;
        double runTime;
        start = omp_get_wtime();
        int num = 1,primes = 0;
    
        int limit = 1000000;
    
    #pragma omp parallel for schedule(dynamic) reduction(+ : primes)
        for (num = 1; num <= limit; num++) { 
            int i = 2; 
            while(i <= num) { 
                if(num % i == 0)
                    break;
                i++; 
            }
            if(i == num)
                primes++;
    //      printf("%d prime numbers calculated\n",primes);
        }
    
        end = omp_get_wtime();
        runTime = end - start;
        printf("This machine calculated all %d prime numbers under %d in %g seconds\n",primes,limit,runTime);
    
        return 0;
    }
    

    Output:

    This machine calculated all 78498 prime numbers under 1000000 in 29.753 seconds

    Here’s your 100% CPU:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a quite interesting question, in my opinion. I have a strongly typed
I am learning Computer Networking this semester, on which I find it quite interesting
I have this quite popular problem, but have failed to find a solution that
I've edited this quite a bit and bolded my question at this point. I
This could quite possibly be the dumbest question ever asked. Our client wants us
This question is kind of anecdotical but still interesting to me; I was wondering
Just read this interesting article by Omar on his blog Linq to SQL solve
I am intentionally leaving this quite vague at first. I'm looking for discussion and
I run into this quite often where a new page is supposedly tested and
I've seen this quite a few times while using Office Interop classes this.CustomXMLParts.Add(MyResources.Data, new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.