I'm trying to make build-system runs unit-test automatically.
The problem is that test output was duplicated when i use -j option.
have possible solution...?
Parallel build + consistent output
similar to
function()
synchronized {
add_custom_command("...run test...")
}
endfunction()
which is no cmake syntax
src - https://github.com/dearblanc/cmake_practice
< first build >
< second build > - make failure by intention
< wow >
Running module_a_test
Running module_b_test
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set[-=u=p=.=
=[=-=-=-=-=-]- -R-u-n-n]i n1g t2e stte sftrso mf rMoOmD U2L Et_eAs
t[ sRuUiNt e s .
[ -]- -M-O-D-U-L-E-_-A]. GGElTo
bCa:l\ Utseesrts \ednevairrbo\nvmsecnotd es_ewto-rukps.p
a[c-e-\-c-m-a-k-e-_-p-r]a c1t itcee\smto dfurloem_ aM\OsDrUcL\Em_oBd2u
l[e _RaU_Nt e s t . c c]: 7M:O DFUaLiEl_uBr2e.G
EETx
p[e c t e d e qOuKa l]i tMyO DoUfL Et_hBe2s.eG EvTa l(u0e sm:s
)
["-A-A-"-
- - -a-.-g-e]t (1)
t e s t Wfhriocmh MiOsD:U L"EA_"B
2 ([8 mFsA ItLoEtDal)
][ -M-O-D-U-L-E-_-A-.-G]E T1 (t4e5s tm sf)r
o[m- -M-O-D-U-L-E-_-B-1]
[1 RtUeNs t f r o m] MMOODDUULLEE__AB 1(.1G0E1T
mCs: \tUostearls)\
d
e[a-r-b-\-v-s-c-o-d-e-_]w oGrlkosbpaalc et\ecsmta keen_vpirraocntmiecnet\ mtoedaurl-ed_obw\ns
r[c=\=m=o=d=u=l=e=_=b=1]_ t1e stte.sctc :f6r:o mF a1i ltuerset
Esxupietcet erda ne.q u(a1l5i5t ym so ft otthaels)e
[v a lPuAeSsS:E
D "]B B01 "t
e s tbs1..
g[e t (F)A
I L E D W h]i c1h tiess:t ," Bl1"i
s[t e dF AbIeLlEoDw :
][ M OFDAUILLEE_DB 1 .]G ETM O(D3U9L Em_sA).
[G-E-T-
-
- -1- -F-A-I]L E1D tTeEsStT
from MODULE_B1 (96 ms total)
Related
I'm inconsistently getting this error in a first experiment with OCaml 5.0.0~beta1:
Fatal error: exception Stdlib.Effect.Unhandled(Domainslib__Task.Wait(_, _))
My setup:
Processor: Intel(R) Core(TM) i7-8750H CPU # 2.20GHz
Debian 10 (buster)
opam version 2.1.3 installed as binary from this script
opam switch: "→ 5.0.0~beta1 ocaml-base-compiler.5.0.0~beta1 5.0.0~beta1"
After a quick read of this tutorial, I copied the parallel_matrix_multiply function and added some code in the end just to use it:
open Domainslib
let parallel_matrix_multiply pool a b =
let i_n = Array.length a in
let j_n = Array.length b.(0) in
let k_n = Array.length b in
let res = Array.make_matrix i_n j_n 0 in
Task.parallel_for pool ~start:0 ~finish:(i_n - 1) ~body:(fun i ->
for j = 0 to j_n - 1 do
for k = 0 to k_n - 1 do
res.(i).(j) <- res.(i).(j) + a.(i).(k) * b.(k).(j)
done
done);
res ;;
let pool = Task.setup_pool ~num_domains:3 () in
let a = Array.make_matrix 2 2 1 in
let b = Array.make_matrix 2 2 2 in
let c = parallel_matrix_multiply pool a b in
for i = 0 to 1 do
for j = 0 to 1 do
Printf.printf "%d " c.(i).(j)
done;
print_char '\n'
done;;
I then compile it with no errors with
ocamlfind ocamlopt -linkpkg -package domainslib parallel_for.ml
and then comes the problem: executing the generated a.out file sometimes (rarely) prints the expected output
4 4
4 4
but usually ends with the error mentioned earlier:
Fatal error: exception Stdlib.Effect.Unhandled(Domainslib__Task.Wait(_, _))
Sorry if I am making some trivial mistake, but I can't understand what is going on, especially given that the error happens inconsistently.
The parallel_matrix_multiply computation is running outside of the Domainslib scheduler, thus whenever a task yields to the scheduler, the Wait effect is unhandled and transformed into a Effect.Unhandled exception.
The solution is to run the parallel computation within Task.run:
...
let c = Task.run pool (fun () -> parallel_matrix_multiply pool a b) in
...
I noticed, while playing with Pharo, that regardless of the way I type the code in playground, if I try to run it, but there is some problem, when the debugger opens it shows your code nicely indented.
For example, if I have this not particullary well indented program in playground:
| banditA banditB testBandits multiRun results |
banditA := [ 1.0 random <= 0.6 ifTrue: [ 1.0 ] ifFalse: [ 0.0 ] ].
banditB := [ 1.0 random > 0.6 ifTrue: [ 1.0 ] ifFalse: [ 0.0 ] ].
"Tests banditA and banditB n times each, to see which one is better."
testBandits := [ :n |
| A B |.
A := 0.0.
B := 0.0.
n timesRepeat: [ A := A + banditA value ].
n timesRepeat: [ B := B + banditB value ].
A > B
ifTrue: [ { A + B . banditA} ]
ifFalse: [ A < B
ifTrue: [ { A + B . banditB} ]
ifFalse: [ { A + B . { banditA. banditB } atRandom } ] ] ].
"Accumulate the results of size - 2 * nTests number of trials of winning
bandits, each preceded with a explore phase with 2 * nTests (half to each
bandit."
multiRun := [ :nTests :size |
| testResults sum |
sum := 0.0.
testResults := (testBandits value: nTests).
2 * nTests negated + size timesRepeat: [ sum := sum + (testResults at: 2) value ].
sum ].
"Average the returns of a thousand runs, to each even number of tests between 1 and
size = 1000."
results := (1 to: 500) collect:
[ :n | { 2*n. ((1 to: 1000) collect: [ :each | multiRun value: n value: 1000]) average}].
Transcript clear; show: 'Number of tests;Return'; cr.
results do: [ :each | Transcript show: (each at: 1); show: ';'; show: (each at: 2); cr ].
results sorted: [ :first :second | (first at: 2) > (second at: 2) ]
If I open the debugger in this code sample with Ctrl+Shift+D, the debugger shows me a nicely formated DoIt object, minus the comments:
DoIt
| banditA banditB testBandits multiRun results |
banditA := [ 1.0 random <= 0.6
ifTrue: [ 1.0 ]
ifFalse: [ 0.0 ] ].
banditB := [ 1.0 random > 0.6
ifTrue: [ 1.0 ]
ifFalse: [ 0.0 ] ].
testBandits := [ :n |
| A B |
A := 0.0.
B := 0.0.
n timesRepeat: [ A := A + banditA value ].
n timesRepeat: [ B := B + banditB value ].
A > B
ifTrue: [ {(A + B).
banditA} ]
ifFalse: [ A < B
ifTrue: [ {(A + B).
banditB} ]
ifFalse: [ {(A + B).
{banditA.
banditB} atRandom} ] ] ].
multiRun := [ :nTests :size |
| testResults sum |
sum := 0.0.
testResults := testBandits value: nTests.
2 * nTests negated + size
timesRepeat: [ sum := sum + (testResults at: 2) value ].
sum ].
results := (1 to: 500)
collect: [ :n |
{(2 * n).
((1 to: 1000) collect: [ :each | multiRun value: n value: 1000 ])
average} ].
Transcript
clear;
show: 'Number of tests;Return';
cr.
results
do: [ :each |
Transcript
show: (each at: 1);
show: ';';
show: (each at: 2);
cr ].
^ results sorted: [ :first :second | (first at: 2) > (second at: 2) ]
After some digging, I discovered there is a option to format source code inside the class browser, just by right-clicking source code, then choosing Source code > Format code:
But I couldn't find a way to do the same to source code inside playground, as the Source code > Format code option is not shown on right-click. If I try the keyboard shortcut Ctrl-T inside playground, it just erases whatever is selected. I could just copy code from playground into the browser, format it there, and then copy it back to playground, or could just open the debugger on the sample and then copy the nicely formated code into the playground, erasing the DoIt top line and the return symbol ^ from the expression in the last line, but that's not convenient. So I'd like to know if there is a proper way.
By the way, the code sample I used as a example is my attempt at simulating a instance of the Multi-armed bandit problem used in a psychological experiment described in the book Algorithms to Live By: The Computer Science of Human Decisions:
"Once you become familiar with them, it’s easy to see multi-armed
bandits just about everywhere we turn. It’s rare that we make an
isolated decision, where the outcome doesn’t provide us with any
information that we’ll use to make other decisions in the future. So
it’s natural to ask, as we did with optimal stopping, how well people
generally tend to solve these problems—a question that has been
extensively explored in the laboratory by psychologists and behavioral
economists. In general, it seems that people tend to over-explore—to
favor the new disproportionately over the best. In a simple
demonstration of this phenomenon, published in 1966, Amos Tversky and
Ward Edwards conducted experiments where people were shown a box with
two lights on it and told that each light would turn on a fixed (but
unknown) percentage of the time. They were then given 1,000
opportunities either to observe which light came on, or to place a bet
on the outcome without getting to observe it. (Unlike a more
traditional bandit problem setup, here one could not make a “pull”
that was both wager and observation at once; participants would not
learn whether their bets had paid off until the end.) This is pure
exploration vs. exploitation, pitting the gaining of information
squarely against the use of it. For the most part, people adopted a
sensible strategy of observing for a while, then placing bets on what
seemed like the best outcome—but they consistently spent a lot more
time observing than they should have. How much more time? In one
experiment, one light came on 60% of the time and the other 40% of the
time, a difference neither particularly blatant nor particularly
subtle. In that case, people chose to observe 505 times, on average,
placing bets the other 495 times. But the math says they should have
started to bet after just 38 observations—leaving 962 chances to cash
in."
I'd like to see if I could arrive at this figure of 38 as a optimal number, so I wrote this simulation. Arrived pretty close, this plot shows the results of one run:
This particular run resulted in a maximum at 34, quite close to 38. There is some variation between runs, as the curve gets a bit noisy in the top, but the maximum is consistently less than ten positions away of 38.
I have programmed a langton's ant and it work nice.
Now I want to run 2 ant simultaneously.I have a run function how make the computation and ant's movement and it's a infinite run loop.
How can I run 2 of this loop at once ?
I have try to look on Thread but i'm not sure that it's the best for my case.
This is some example of my code :
Run function :
let run(f,tab2 : t_fourmi*int array array) =
f.xx := !(f.x);
f.yy := !(f.y);
let d = ref 0
and z = ref 0
and o = ref 0
(* 1 = de bas, 2 = de droite, 3 = de haut, 4 = de gauche *)
in
if tab2.(!(f.x)/5).(!(f.y)/5) = 0
then move_right(f,1,tab2);
if !(f.xx) + 5 = !(f.x)
then d := 4
else if !(f.xx) - 5 = !(f.x)
then d := 2
else if !(f.yy) + 5 = !(f.y)
then d := 1
else if !(f.yy) - 5 = !(f.y)
then d := 3;
while true
do
(*
print_string "step : ";
print_int !o;
print_newline(); *)
o := !o + 1;
f.xx := !(f.x);
f.yy := !(f.y);
z := tab2.(!(f.x)/5).(!(f.y)/5);
if !z = 0
then move_right(f,!d,tab2)
else if !z = 1
then move_left(f,!d,tab2)
else if !z = 2
then move_right(f,!d,tab2)
else if !z = 3
then move_right(f,!d,tab2);
if !(f.xx) + 5 = !(f.x)
then d := 4
else if !(f.xx) - 5 = !(f.x)
then d := 2
else if !(f.yy) + 5 = !(f.y)
then d := 1
else if !(f.yy) - 5 = !(f.y)
then d := 3;
done;
;;
Example of move function :
let move_left(f,d,tab2 : t_fourmi*int*int array array) = (* d = direction d'ou la fourmi viens *)
(* 1 = de bas, 2 = de droite, 3 = de haut, 4 = de gauche *)
f.xx := !(f.x);
f.yy := !(f.y);
if d = 1
then f.x := !(f.x) - 5
else if d = 2
then f.y := !(f.y) - 5
else if d = 3
then f.x := !(f.x) + 5
else if d = 4
then f.y := !(f.y) + 5;
if !(f.x) >= 995
then f.x := 5
else if !(f.x) <= 5
then f.x := 995;
if !(f.y) >= 995
then f.y := 5
else if !(f.y) <= 5
then f.y := 995;
create_fourmi(f);
let n = tab2.(!(f.xx)/5).(!(f.yy)/5) in
drawinv(!(f.xx),!(f.yy),n,tab2);
;;
If you need more function, ask me.
Thanks
If I understand your code correctly (it's unfortunately not very readable), it could be outlined as essentially:
let init params =
...
let step state =
...
let move thing state =
...
let run params thing =
let state = ref (init params) in
while true do
let state := step state in
move thing state
done
where I've factored init, step and move out into separate function, which should be pretty straight-forward to do. And by doing so we can replace the run function with a run_two function that can run two instances virtually at the same time, though not entirely in parallel. They won't run independently, but in synchrony, iteration by iteration:
let run_two params1 thing1 params2 thing2 =
let state1 = ref (init params1) in
let state2 = ref (init params2) in
while true do
state1 := step !state1;
state2 := step !state2;
move !state1;
move !state2;
done
This doesn't use any threads or other complicated concurrency primitives. It's just ordinary code organized in a way that allows composition. It also allows the init and step function to be completely pure, which makes them easy to test and reason about. You could even make the move functions pure, if you factor out the drawing.
You can use threads, though it will open a pandora box for you. You have to synchronize your ants, since probably you want them to move in the same world.
Running two ants in different threads
First of all, you have to represent each ant process as an ever-looping function of type ant -> unit, where ant is the type that describes ant's initial position, moving parameters, and so on (if you don't need this, then just use unit instead. So suppose we have a function val run : ant -> unit. Next, we need to make sure, that we do not write to the same board at the same time from different threads, so we need to create a mutex, using Mutex.create, we then need to update our run function and do Mutex.lock before updating our board, and Mutex.unlock after. Finally, we should ensure that no ants will starve for the board, and that once an ant finishes it moves it yields the control to another ant, we could do this using Thread.delay if we want our simulation to be smooth (i.e., if we want to artificially slow it down to human-observable speed). Otherwise, we can just use Thread.yield. (Note, normally threads are preempted (forced to yield) by the system, but this is done in special yield points. When we do system programming there are usually lots of yield points, but this is not our case, so we have to implement this cooperation explicitly). Finally, our updated run function is ready to be run in a thread, with Thread.createrun ant. This function will return to our main thread of execution, so we can run a second ant and so on. Once all ants start running we have to call Thread.join to wait for all of them. Ideally, this function should never return.
I hope, that the above outline provided enough information for you, and you can enjoy the coding yourself. Feel free to ask questions int the comment section if anything is unclear. Probably, the first question would be how to compile it. It is (there are simpler ways, of course, but the most basic is, assuming that your program is in the ant.ml):
ocamlopt -thread unix.cmxa threads.cmxa ant.ml -o ant
Running two ants in co-routines
While the above will work, it seems too complicated and too system-dependent for such a simple simulation task. Why do we need to use system threads for that? We actually don't, we can be clever and implement co-routines using plain OCaml and continuation-passing style. Don't worry, a continuation is just a function. And a continuation-passing style is when we are calling another function at the end of the other function. In this approach, we will not have the run function that runs infinitely, instead, we will have a step function that advances an ant one step forward at each invocation. For the demonstration purposes, let's simplify our step function so that each ant just greets another, e.g.,
let step other yield =
print_endline ("Hello, " ^ other);
yield ()
That simple. We do our step, and then call the yield function (that is that fancy continuation) to yield the control to the next ant. Now let's tie it together in a simple infinite loop, e.g.,
let rec loop () =
step "Joe" ## fun () ->
step "Doe" ## fun () ->
loop ()
let () = loop ()
Let's make it clear. step "Joe" ## fun () -> <continue> is the same as step "Joe" (fun () -> <continue>), and this (fun () -> <continue>) is the yield function that is passed to the step function that greets Joe. Once Joe is greeted the step function calls us again and we evaluate the <continue>, which is, in our case step "Doe" ## fun () -> loop (), i.e., we pass the fun () -> loop () function as the yield argument to the step function that greets Doe, so once Doe is greeted, we call loop () ... and now we're at the begining of the loop.
In our case, we were passing a value of type unit in our continuations, but we can also pass an arbitrary value, e.g., a value that will represent the state of our simulation (the board with ant positions). This will enable a functional implementation of your simulation if you want to try it.
I'm importing a very complex .xls file that often combines multiple cells together in the variable names. After importing it into Stata, only the first cell has a variable name, and the other 3 are blank. Is it possible to write a loop to rename all the variables (which come in sets of 4)?
For instance, the variables go: Russia, B, C, D but I would like them to be named Russia_A, Russia_B, Russia_C, Russia_D. Is there a way to do this with a loop or command within Stata?
It's impossible to have blank variable names in Stata, as your own example attests. On the information given your variable names come in fours, so that you could loop. One basic technique is just to cycle over 1, 2, 3, 4 and act accordingly. This example works. If it's not what you want, a minimal reproducible example is essential showing why this is different from what you want.
clear
input Russia B C D Germany E F G France H I J
42 42 42 42 42 42 42 42 42 42 42 42
end
tokenize "A B C D"
local i = 0
foreach v of var * {
local ++i
if `i' == 1 local stub "`v'"
rename `v' `stub'_``i''
if `i' == 4 local i = 0
}
ds
Russia_A Russia_C Germany_A Germany_C France_A France_C
Russia_B Russia_D Germany_B Germany_D France_B France_D
tokenize is possibly the least familiar command here, so see its help if needed.
All that said, it's unlikely that this is a useful data structure. See help reshape.
Here's another way to do it. We set up a counter running over all the variables. This perhaps is more of a finger exercise in macro manipulation.
clear
input Russia B C D Germany E F G France H I J
42 42 42 42 42 42 42 42 42 42 42 42
end
tokenize "A B C D"
forval j = 1/4 {
local sub`j' "``j''"
}
unab all : *
tokenize "`all'"
local J : word count `all'
forval j = 1/`J' {
local k = mod(`j', 4)
if `k' == 0 local k = 4
if `k' == 1 local stub "``j''"
rename ``j'' `stub'`sub`k''
}
ds
I want to ask you if Haskell and C++ compilers can optimize function calls the same way.
Please look at following codes. In the following example Haskell is significantly faster than C++.
I have heard that Haskell can compile to LLVM and can be optimized by the LLVM passes. Additionally I have heard that Haskell has some heavy optimizations under the hood.
But the following examples should be able to work with the same performance.
I want to ask:
Why my sample benchmark in C++ is slower than the on in Haskell?
is it possible to further optimize the codes?
(I'm using LLVM-3.2 and GHC-7.6).
C++ code:
#include <cstdio>
#include <cstdlib>
int b(const int x){
return x+5;
}
int c(const int x){
return b(x)+1;
}
int d(const int x){
return b(x)-1;
}
int a(const int x){
return c(x) + d(x);
}
int main(int argc, char* argv[]){
printf("Starting...\n");
long int iternum = atol(argv[1]);
long long int out = 0;
for(long int i=1; i<=iternum;i++){
out += a(iternum-i);
}
printf("%lld\n",out);
printf("Done.\n");
}
compiled with clang++ -O3 main.cpp
haskell code:
module Main where
import qualified Data.Vector as V
import System.Environment
b :: Int -> Int
b x = x + 5
c x = b x + 1
d x = b x - 1
a x = c x + d x
main = do
putStrLn "Starting..."
args <- getArgs
let iternum = read (head args) :: Int in do
putStrLn $ show $ V.foldl' (+) 0 $ V.map (\i -> a (iternum-i))
$ V.enumFromTo 1 iternum
putStrLn "Done."
compiled with ghc -O3 --make -fforce-recomp -fllvm ghc-test.hs
speed results:
Running testcase for program 'cpp/a.out'
-------------------
cpp/a.out 100000000 0.0% avg time: 105.05 ms
cpp/a.out 200000000 11.11% avg time: 207.49 ms
cpp/a.out 300000000 22.22% avg time: 309.22 ms
cpp/a.out 400000000 33.33% avg time: 411.7 ms
cpp/a.out 500000000 44.44% avg time: 514.07 ms
cpp/a.out 600000000 55.56% avg time: 616.7 ms
cpp/a.out 700000000 66.67% avg time: 718.69 ms
cpp/a.out 800000000 77.78% avg time: 821.32 ms
cpp/a.out 900000000 88.89% avg time: 923.18 ms
cpp/a.out 1000000000 100.0% avg time: 1025.43 ms
Running testcase for program 'hs/main'
-------------------
hs/main 100000000 0.0% avg time: 70.97 ms (diff: 34.08)
hs/main 200000000 11.11% avg time: 138.95 ms (diff: 68.54)
hs/main 300000000 22.22% avg time: 206.3 ms (diff: 102.92)
hs/main 400000000 33.33% avg time: 274.31 ms (diff: 137.39)
hs/main 500000000 44.44% avg time: 342.34 ms (diff: 171.73)
hs/main 600000000 55.56% avg time: 410.65 ms (diff: 206.05)
hs/main 700000000 66.67% avg time: 478.25 ms (diff: 240.44)
hs/main 800000000 77.78% avg time: 546.39 ms (diff: 274.93)
hs/main 900000000 88.89% avg time: 614.12 ms (diff: 309.06)
hs/main 1000000000 100.0% avg time: 682.32 ms (diff: 343.11)
EDIT
Of course we cannot compare speed of languages, but the speed of implementiations.
But I'm curious if Ghc and C++ compilers can optimize function calls the same way
I've edited the question with new benchmark and codes based on your help :)
If your goal is to get this running as quickly as your C++ compiler, then you
would want to use a data structure that the compiler can have its way with.
module Main where
import qualified Data.Vector as V
b :: Int -> Int
b x = x + 5
c x = b x + 1
d x = b x - 1
a x = c x + d x
main = do
putStrLn "Starting..."
putStrLn $ show $ V.foldl' (+) 0 $ V.map a $ V.enumFromTo 1 100000000
putStrLn "Done."
GHC is able to completely eliminate the loop and just inserts a constant into
the resulting assembly. On my computer, this now has a runtime of < 0.002s, when
using the same optimization flags as you originally specified.
As a follow up based on the comments by #Yuras, the core produced by the
vector based solution and the stream-fusion solution are functionally
identical.
Vector
main_$s$wfoldlM'_loop [Occ=LoopBreaker]
:: Int# -> Int# -> Int#
main_$s$wfoldlM'_loop =
\ (sc_s2hW :: Int#) (sc1_s2hX :: Int#) ->
case <=# sc1_s2hX 100000000 of _ {
False -> sc_s2hW;
True ->
main_$s$wfoldlM'_loop
(+#
sc_s2hW
(+#
(+# (+# sc1_s2hX 5) 1)
(-# (+# sc1_s2hX 5) 1)))
(+# sc1_s2hX 1)
}
stream-fusion
$wloop_foldl [Occ=LoopBreaker]
:: Int# -> Int# -> Int#
$wloop_foldl =
\ (ww_s1Rm :: Int#) (ww1_s1Rs :: Int#) ->
case ># ww1_s1Rs 100000000 of _ {
False ->
$wloop_foldl
(+#
ww_s1Rm
(+#
(+# (+# ww1_s1Rs 5) 1)
(-# (+# ww1_s1Rs 5) 1)))
(+# ww1_s1Rs 1);
True -> ww_s1Rm
}
The only real difference is the choice of comparison operation for the
termination condition. Both versions compile to tight tail recursive loops
that can be easily optimized by LLVM.
ghc doesn't fuse lists (avoiding success at all costs?)
Here is version that uses stream-fusion package:
module Main where
import Prelude hiding (map, foldl)
import Data.List.Stream
import Data.Stream (enumFromToInt, unstream)
import Text.Printf
import Control.Exception
import System.CPUTime
b :: Int -> Int
b x = x + 5
c x = b x + 1
d x = b x - 1
a x = c x + d x
main = do
putStrLn "Starting..."
putStrLn $ show $ foldl (+) 0 $ map (\z -> a z) $ unstream $ enumFromToInt 1 100000000
putStrLn "Done."
I don't have llvm installed to compare with your results, but it is 10x faster then your version (compiled without llvm).
I think vector fusion should perform even faster.
As others have pointed out, you're not comparing equivalent algorithms. As Yuras pointed out GHC doesn't fuse lists. Your Haskell version will actually allocate that entire list, it will be done lazily one cell at a time, but it will be done. Below is a version that's algorithmically closer to your C version. On my system it runs in the same time as the C version.
{-# LANGUAGE BangPatterns #-}
module Main where
import Text.Printf
import Control.Exception
import System.CPUTime
import Data.List
a,b,c :: Int -> Int
b x = x + 5
c x = b x + 1
d x = b x - 1
a !x = c x + d x
-- Don't allocate a list, iterate and increment as the C version does.
applyTo !acc !n
| n > 100000000 = acc
| otherwise = applyTo (acc + a n) (n + 1)
main = do
putStrLn "Starting..."
print $ applyTo 0 1
putStrLn "Done."
Comparing it with time:
ghc -O3 bench.hs -fllvm -fforce-recomp -o bench-hs && time ./bench-hs
[1 of 1] Compiling Main ( bench.hs, bench.o )
Linking bench-hs ...
Starting...
10000001100000000
Done.
./bench-hs 0.00s user 0.00s system 0% cpu 0.003 total
Compared to C:
clang++ -O3 bench.cpp -o bench && time ./bench
Starting...
10000001100000000
Done.
./bench 0.00s user 0.00s system 0% cpu 0.004 total