mersenneforum.org  

Go Back   mersenneforum.org > Great Internet Mersenne Prime Search > Software

Reply
 
Thread Tools
Old 2019-12-11, 00:58   #1
danc2
 
Dec 2019

2×17 Posts
Lightbulb Functional Programming Version

Hi all,

I am a MS student (soon to be a graduated one) who just finished a programming course that centered around functional programming (FP). My interest is somewhat piqued and my professor informed me that some are using FP in distributed computing projects.

I wondered if anyone had any thoughts on if FP could be faster than the current C implementation. I've read recursion is optimized more so than an imperative language such as C and the speed of parallel computation is also pretty great. No state, but there are "ways around that" my professor told me (perhaps moving things over a network?).

It may be a side project I attempt as I am interested in learning more about FP and like the work that GIMPS does.
Thanks!
Daniel
danc2 is offline   Reply With Quote
Old 2019-12-11, 01:22   #2
paulunderwood
 
paulunderwood's Avatar
 
Sep 2002
Database er0rr

376110 Posts
Default

Quote:
Originally Posted by danc2 View Post
Hi all,

I am a MS student (soon to be a graduated one) who just finished a programming course that centered around functional programming (FP). My interest is somewhat piqued and my professor informed me that some are using FP in distributed computing projects.

I wondered if anyone had any thoughts on if FP could be faster than the current C implementation. I've read recursion is optimized more so than an imperative language such as C and the speed of parallel computation is also pretty great. No state, but there are "ways around that" my professor told me (perhaps moving things over a network?).

It may be a side project I attempt as I am interested in learning more about FP and like the work that GIMPS does.
Thanks!
Daniel
The meat of the coding is done in assembly which close to metal. C/C++ is used for non-critical loops etc. Having direct control over CPU registers is going to be much quicker than trying to address them with a FP language.

Last fiddled with by paulunderwood on 2019-12-11 at 01:25
paulunderwood is offline   Reply With Quote
Old 2019-12-11, 02:24   #3
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3·1,993 Posts
Default

The idea is that a well-designed functional programming language could let you program in a functional style without a performance penalty compared to a close-to-the-metal language. It's not going to outperform them unless the other coder is doing something wrong.
CRGreathouse is offline   Reply With Quote
Old 2019-12-11, 03:17   #4
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
Jun 2011
Thailand

72×197 Posts
Default

During our Uni we really loved Lisp, and we really did nice things in it (like some playing-gomoku "brain") unfortunately it wasn't much of an opportunity to use it after. For a while we coquetted with it during the time it was supported by AutoDesk (their AutoLisp actually was nice and quite powerful, we use it to write a program that designed our LCD modules for us in AutoCad, given the dimensions and some other characteristics, then it was piece of cake to retouch here and there, much better and a million times faster than starting the design from scratch). Then our company switched to SolidWorks, which we still don't know how to handle properly... (well, much better price, aggressive marketing, etc). (In)fortunately, we don't do much of mechanical design now, being busy writing firmware (blind C and ARM assembler)...
LaurV is offline   Reply With Quote
Old 2019-12-11, 03:53   #5
danc2
 
Dec 2019

2·17 Posts
Default

Cool, thanks for the quick replys all! I had heard about Prime95 being written in assembly, but was unsure about the rest (probably should have made that clear) and what, if any performance tuning could occur. Looks like whoever made this software are wizards already .
danc2 is offline   Reply With Quote
Old 2019-12-11, 04:08   #6
CRGreathouse
 
CRGreathouse's Avatar
 
Aug 2006

3×1,993 Posts
Default

Quote:
Originally Posted by danc2 View Post
Cool, thanks for the quick replys all! I had heard about Prime95 being written in assembly, but was unsure about the rest (probably should have made that clear) and what, if any performance tuning could occur. Looks like whoever made this software are wizards already .
They are true wizards. But FP has real advantages, especially in multicore programming: it makes it much easier to avoid mistakes that can be hard to avoid in other languages, because of their lack of state. So we're not knocking FP by any means, just pointing out that it's not a hammer for every nail.
CRGreathouse is offline   Reply With Quote
Old 2019-12-11, 08:13   #7
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

250348 Posts
Default

Challenge for you: write a useful program in C which is also purely functional in the FP sense.

It can be done, and I've faced and passed this challenge in the past, but it's not entirely easy to do.

And I do not mean something as trivial as main(){printf("Hello world\n")}.
xilman is offline   Reply With Quote
Old 2019-12-11, 08:16   #8
LaurV
Romulan Interpreter
 
LaurV's Avatar
 
Jun 2011
Thailand

72×197 Posts
Default

is the "factorial" good enough and functional enough?

or "hanoi towers" something?
LaurV is offline   Reply With Quote
Old 2019-12-11, 10:41   #9
xilman
Bamboozled!
 
xilman's Avatar
 
"π’‰Ίπ’ŒŒπ’‡·π’†·π’€­"
May 2003
Down not across

101010000111002 Posts
Default

Quote:
Originally Posted by LaurV View Post
is the "factorial" good enough and functional enough?

or "hanoi towers" something?
Yes, if you don't think you are a good enough programmer to implement anything less trivial.

If you do think you are any good, try implementing this rather simple function, given here in imperative pseudocode.
Code:
INTEGER FUNCTION sum_func (INTEGER FUNCTION (INTEGER x) fun,
                           INTEGER from,
                           INTEGER step,
                           INTEGER to)
BEGIN
    INTEGER temp;
    INTEGER i;
    temp := 0;
    FOR i := from STEP step TO to DO temp := temp + fun (i) OD;
    RETURN temp;
END
Wrap a purely functional program round it to prove it works. fun can be hard-coded if you wish but from, step and to should be taken from user input.

Last fiddled with by xilman on 2019-12-11 at 10:51
xilman is offline   Reply With Quote
Old 2019-12-12, 16:42   #10
kriesel
 
kriesel's Avatar
 
"TF79LL86GIMPS96gpu17"
Mar 2017
US midwest

2×32×7×43 Posts
Default

Quote:
Originally Posted by CRGreathouse View Post
They are true wizards. But FP has real advantages, especially in multicore programming: it makes it much easier to avoid mistakes that can be hard to avoid in other languages, because of their lack of state. So we're not knocking FP by any means, just pointing out that it's not a hammer for every nail.
not the right hammer for every fastener/fastening technique. Sometimes you need a gravity-compensated power screwdriver, sometimes a MIG welder or adhesive dispensing robot or fastener-free snap fit.
kriesel is online now   Reply With Quote
Old 2019-12-12, 20:42   #11
Uncwilly
6809 > 6502
 
Uncwilly's Avatar
 
"""""""""""""""""""
Aug 2003
101Γ—103 Posts

100110010110102 Posts
Default

Quote:
Originally Posted by kriesel View Post
not the right hammer for every fastener/fastening technique. Sometimes you need a gravity-compensated power screwdriver, sometimes a MIG welder or adhesive dispensing robot or fastener-free snap fit.
Friction stir welding is good for somethings. Also, as a side note: Oxy-acetylene torches don't cut scrap dirt plywood the way it does steel (someone I know had this one pulled on them.)
Uncwilly is offline   Reply With Quote
Reply

Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need some help on php programming pinhodecarlos Programming 2 2012-07-23 18:17
New to programming. What to do? lorgix Miscellaneous Math 9 2010-12-08 22:22
anyone know haskell or functional lang. at all? jjoshua2 Homework Help 7 2010-01-27 08:21
plz, help me in c programming alaa Homework Help 12 2007-06-12 22:17
programming challenge Fusion_power Puzzles 25 2003-08-21 15:56

All times are UTC. The time now is 18:33.


Sun Aug 1 18:33:44 UTC 2021 up 9 days, 13:02, 0 users, load averages: 1.28, 1.84, 2.26

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.

This forum has received and complied with 0 (zero) government requests for information.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation.
A copy of the license is included in the FAQ.