Fedora Linux Support Community & Resources Center
  #1  
Old 27th January 2009, 06:01 AM
RupertPupkin's Avatar
RupertPupkin Offline
Registered User
 
Join Date: Nov 2006
Location: Detroit
Posts: 4,617
How fast does this run on your PC?

Save the following code in a file called mersenne.c:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
int main(int argc, char *argv[]) {
   char *endptr;
   unsigned long int p = strtoul(argv[1],&endptr,10);
   mpz_t M, powerof2, one, two;
   mpz_init(M); mpz_init(powerof2);
   mpz_init_set_str(one,"1",10);
   mpz_init_set_str(two,"2",10);
   mpz_pow_ui(powerof2,two,p);
   mpz_sub(M,powerof2,one);
   gmp_printf("%Zd",M);
   return 0;
}
Then compile and run it, like this:
Code:
$ gcc -o mersenne mersenne.c -lgmp
$ time ./mersenne 43112609 > M46

real    0m17.226s
user    0m16.874s
sys     0m0.163s
Note: You'll need the gmp-devel package installed to compile the code (at least version 4.2.x).
What this does is compute a really big number, namely 2^43112609 - 1. This is the 46th Mersenne prime, which is an integer with 12,978,189 digits.

The result above was on my 2.2GHz AMD64 3700+ (single-core) w/1GB PC3200 RAM, in Fedora 10 x86_64. I was wondering if 64-bit really would make a difference with this, and the answer seems to be yes. On my 32-bit Fedora system on the same machine it ran much slower. So I'm curious to see how fast it runs on other people's computers, whether in a 32-bit or 64-bit OS.

The calculation of the number itself is almost instantaneous (comment out the gmp_printf statement if you want to see that). It's the printing of the result to stdout (which I redirected to the file M46) that takes a while. If anyone wants to try it with other Mersenne primes, look here for a table of the known ones. For instance, to calculate the 37th Mersenne prime M37 = 2^3021377 - 1, do this:
Code:
time ./mersenne 3021377 > M37
In general, if you pass a positive integer N on the command line to the program, it will compute 2^N - 1. Since the numbers can be huge, I redirect the output to a file. You can see how many digits are in that file by running wc -c on it. By the way, to see the digits themselves, I don't recommend opening the output file M46 in a GUI editor like gedit. Either vi or emacs will open it much faster.
Reply With Quote
  #2  
Old 27th January 2009, 06:12 AM
Seve's Avatar
Seve Offline
Retired Community Manager
 
Join Date: Oct 2004
Location: The GTA, Ontario, Canada
Age: 54
Posts: 12,376
This is with F10 64bit, Intel Quad core 2.4

PHP Code:
time ./mersenne 43112609 M46

real    0m25.933s
user    0m25.786s
sys    0m0.125s 
Seve
__________________
Registered Linux User: #384977
.................................................. ............
See the Links below for more Help and those much wanted extras ... :)
Reply With Quote
  #3  
Old 27th January 2009, 06:37 AM
Lindy's Avatar
Lindy Offline
Registered User
 
Join Date: Feb 2004
Location: 45° 57' 9.43" N 86° 14' 39.55" W
Posts: 719
F10 32bit AMD64 x2 5200+
Code:
[lindy@lindys ~]$ time ./mersenne 43112609 > M46

real    0m32.966s
user    0m32.361s
sys     0m0.544s
__________________
Obscurum per obscurius
-the obscure (explained) by the more obscure.
Reply With Quote
  #4  
Old 27th January 2009, 10:02 AM
adrianx's Avatar
adrianx Offline
Registered User
 
Join Date: Jul 2007
Location: South Africa
Posts: 953
F10, x86_64

Code:
[adrian@amethyst Desktop]$ time ./mersenne 43112609 > M46

real	0m13.700s
user	0m13.383s
sys	0m0.166s
See specs below.

Edit: How can it be faster than a "F10 64bit, Intel Quad core 2.4"? Did I do something wrong/right?
__________________
Registered Linux User 460110

Last edited by adrianx; 27th January 2009 at 10:06 AM. Reason: confused
Reply With Quote
  #5  
Old 27th January 2009, 01:02 PM
bee Offline
Banned
 
Join Date: Jun 2008
Posts: 1,315
Quote:
Originally Posted by adrianx View Post
F10, x86_64

Code:
[adrian@amethyst Desktop]$ time ./mersenne 43112609 > M46

real	0m13.700s
user	0m13.383s
sys	0m0.166s
See specs below.

Edit: How can it be faster than a "F10 64bit, Intel Quad core 2.4"? Did I do something wrong/right?
it's faster because that script works only on one core/CPU while saving the file. So having 2 or 4 core/CPUs is the same as only one thread is working for this software on one CPU and the other CPU is handling the rest of the system,... is it right?

bye!!!!
Reply With Quote
  #6  
Old 27th January 2009, 10:18 AM
leigh123linux's Avatar
leigh123linux Offline
Retired Administrator
 
Join Date: Oct 2006
Posts: 21,509
F11 ( Rawhide ) x86_64 with a AMD 3800 X2


Code:
[leigh@localhost Desktop]$ time ./mersenne 43112609 > M46

real	0m20.110s
user	0m19.518s
sys	0m0.456s
[leigh@localhost Desktop]$


F10 x86_64 same machine


Code:
[leigh@localhost Desktop]$ time ./mersenne 43112609 > M46

real	0m19.403s
user	0m18.943s
sys	0m0.396s
[leigh@localhost Desktop]$
__________________
My Hardware
- CPU: AMD Phenom II X6 Hex Core 1055T 95W Edition @3.5Ghz
- Motherboard: Gigabyte GA-880GM-UD2H
- Cooler: Corsair H50 CPU Cooler
- RAM: Corsair Dominator 8GB (4x2GB) DDR3 1600MHz
- Graphics: Gigabyte GeForce GTS 450 OC 1024MB GDDR5
Reply With Quote
  #7  
Old 26th February 2010, 09:09 PM
leigh123linux's Avatar
leigh123linux Offline
Retired Administrator
 
Join Date: Oct 2006
Posts: 21,509
linuxfedorafirefox
Quote:
Originally Posted by leigh123linux View Post
F11 ( Rawhide ) x86_64 with a AMD 3800 X2


Code:
[leigh@localhost Desktop]$ time ./mersenne 43112609 > M46

real    0m20.110s
user    0m19.518s
sys    0m0.456s
[leigh@localhost Desktop]$
F10 x86_64 same machine


Code:
[leigh@localhost Desktop]$ time ./mersenne 43112609 > M46

real    0m19.403s
user    0m18.943s
sys    0m0.396s
[leigh@localhost Desktop]$

F13 Rawhide with the same proc


Code:
[leigh@localhost Desktop]$ gcc -o mersenne mersenne.c -lgmp
[leigh@localhost Desktop]$ time ./mersenne 43112609 > M46

real    0m11.003s
user    0m10.182s
sys    0m0.527s
[leigh@localhost Desktop]$ uname -r
2.6.33-1.fc13.x86_64
[leigh@localhost Desktop]$ cat /etc/fedora-release 
Fedora release 13 (Rawhide)
[leigh@localhost Desktop]$
Reply With Quote
  #8  
Old 27th January 2009, 10:34 AM
aleph's Avatar
aleph Offline
Banned (for/from) behaving just like everybody else!
 
Join Date: Jul 2007
Location: Beijing, China
Posts: 1,307
F10 on an Intel Pentium M 1.73GHz (32-bit)

I tried redirecting the huge output to a disk file and /dev/null respectively but there's no actual difference.
Code:
real	1m13.870s
user	1m12.818s
sys	0m0.388s
Slow machine compared with yours..
__________________
I believe in nerditarianism. I read FedoraForum for the Fedora-related posts.
Reply With Quote
  #9  
Old 27th January 2009, 10:41 AM
aleph's Avatar
aleph Offline
Banned (for/from) behaving just like everybody else!
 
Join Date: Jul 2007
Location: Beijing, China
Posts: 1,307
Quote:
Originally Posted by RupertPupkin View Post
Either vi or emacs will open it much faster.
Even Vim chokes on such a large piece of bytes..
__________________
I believe in nerditarianism. I read FedoraForum for the Fedora-related posts.
Reply With Quote
  #10  
Old 27th January 2009, 12:19 PM
johno12345's Avatar
johno12345 Offline
Registered User
 
Join Date: Jun 2004
Location: Lancashire, UK
Posts: 332
Tried this on my virtual box
Host is a Core 2 Duo E4600 @ 2.4ghz with 2gb ram but the guest only has 256 mb ram... not sure if the ram makes any difference.
Code:
real    0m39.053s
user    0m36.079s
sys     0m2.804s
Will try it on my shiny new AMD Phenom 9750 Quad when i get home tonight.

Oh its running in 32bit mode too
__________________
Running Fedora since FC1, running Redhat since 5(not EL).
Registered Linux user number 485853
Rossendale and East Lancashire (UK) LUG http://www.rosslug.org.uk
Reply With Quote
  #11  
Old 27th January 2009, 02:20 PM
notageek's Avatar
notageek Offline
Registered User
 
Join Date: Jan 2008
Location: New Delhi, India
Posts: 2,068
AMD64 2800+ Gentoo 2.6.26-gentoo-r4-2 x86_64: Results below

Code:
real	0m21.570s
user	0m21.315s
sys	0m0.250s
AMD64 X2 4800+ Gentoo 2.6.27-gentoo-r7-1 x86_64: Results below

Code:
real	0m15.644s
user	0m15.416s
sys	0m0.210s
and BTW did I mention AMD rules!!
Reply With Quote
  #12  
Old 27th January 2009, 02:23 PM
johno12345's Avatar
johno12345 Offline
Registered User
 
Join Date: Jun 2004
Location: Lancashire, UK
Posts: 332
Quote:
Originally Posted by notageek View Post

and BTW did I mention AMD rules!!
Just switched and i'm impressed already
__________________
Running Fedora since FC1, running Redhat since 5(not EL).
Registered Linux user number 485853
Rossendale and East Lancashire (UK) LUG http://www.rosslug.org.uk
Reply With Quote
  #13  
Old 27th January 2009, 02:42 PM
PabloTwo's Avatar
PabloTwo Offline
"Registered User" T-Shirt Winner
 
Join Date: Mar 2007
Location: Seville, FL
Posts: 5,126
F8 x86: AMD Athlon(tm) 64 Processor 3700+ (San Diego 1MB L2 cache); 1GB PC3200
PHP Code:
 time ./mersenne 43112609 M46

real    0m40.290s
user    0m37.671s
sys     0m0.438s 
Open web browser downloading info in the background, but your x86_64 with otherwise near identical specs beat my x86.
Reply With Quote
  #14  
Old 27th January 2009, 03:04 PM
brunson Offline
Registered User
 
Join Date: Jun 2005
Location: Westminster, Colorado
Posts: 2,304
Removing the filesystem from the mix doesn't change the results appreciably.
Code:
foxtrot(~)$ time ./mersenne 43112609 >&-

real	0m39.469s
user	0m38.801s
sys	0m0.478s
foxtrot(~)$ time ./mersenne 43112609 > M46

real	0m39.372s
user	0m38.720s
sys	0m0.567s
foxtrot(~)$ grep -e model -e cache -e MHz -e bogo /proc/cpuinfo | head -5
model		: 35
model name	: AMD Athlon(tm) 64 X2 Dual Core Processor 4400+
cpu MHz		: 1000.000
cache size	: 1024 KB
bogomips	: 2009.09
__________________
Registered Linux User #4837
411th in line to get sued by Micro$oft
Quote:
Basically, to learn Unix you learn to understand and apply a small set of key ideas and achieve expertise by expanding both the set of ideas and your ability to apply them - Paul Murphy
Reply With Quote
  #15  
Old 27th January 2009, 03:37 PM
wathek Offline
Registered User
 
Join Date: Jan 2009
Posts: 49
I get this with my Intel Core 2 Duo 2Ghz with 2Go RAM :
Code:
wathek@Wathek:~$ time ./mersenne 43112609 > M46


real    0m46.280s
user    0m44.891s
sys     0m0.696s
wathek@Wathek:~$
wathek@Wathek:~$ time ./mersenne 43112609 > M46

real    0m45.760s
user    0m44.455s
sys     0m0.752s
Linux Archive

Last edited by wathek; 9th February 2009 at 03:10 PM.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Help Fast!!!! invisible-MK Using Fedora 5 14th November 2006 12:15 AM
too fast sjoerd222 Using Fedora 19 25th October 2006 11:35 AM
Need help fast fedorafan2 Using Fedora 3 13th August 2006 06:16 PM
This ****'s getting old fast Nickmorgan19457 Using Fedora 3 21st April 2006 06:55 PM
Sagem Fast 800 on FC4 gsouf Hardware & Laptops 2 28th February 2006 08:27 PM


Current GMT-time: 15:07 (Wednesday, 22-05-2013)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat