Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Compiling shared (dll) library (Daniel Fischer)
2. Re: Compiling shared (dll) library (Alexander.Vladislav.Popov )
3. Re: Diagnosing : Large memory usage + low CPU (Hugo Ferreira)
----------------------------------------------------------------------
Message: 1
Date: Mon, 5 Dec 2011 13:14:20 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Compiling shared (dll) library
To: [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain; charset="utf-8"
On Monday 05 December 2011, 11:39:06, Alexander.Vladislav.Popov wrote:
> Hi, Haskellers.
>
> I'm trying to compile following program (where Regex.Genex is a package
> what I need to produce all possible expresions by the given pattern and
> `adder' is just FFI sample):
>
> -- genexlib.hs
> {-# LANGUAGE BangPatterns, ForeignFunctionInterface #-}
>
> module GenexLib where
>
> import Regex.Genex
> import System.IO
> import System.Environment
>
> adder :: Int -> Int -> IO Int -- gratuitous use of IO
> adder x y = return (x+y)
> foreign export stdcall adder :: Int -> Int -> IO Int
> -- genexlib.hs end
>
> // start.c
> #include <Rts.h>
>
> void HsStart()
> {
> int argc = 1;
> char* argv[] = {"ghcDll", NULL}; // argv must end with NULL
>
> // Initialize Haskell runtime
> char** args = argv;
> hs_init(&argc, &args);
> }
>
> void HsEnd()
> {
> hs_exit();
> }
> // start.c end
>
> I'm using ghc
>
> >ghc --version
>
> The Glorious Glasgow Haskell Compilation System, version 7.0.2
>
> compiling:
> >ghc -c genexlib.hs
> >ghc -c start.c
> >ghc -shared -o genexlib.dll genexlib.o genexlib_stub.o start.o
Why the separate compilation? Can't you compile them in one go?
>
> genexlib.o:fake:(.text+0xd1): undefined reference to
> `__stginit_regexzmgenexzm0zi3zi2_RegexziGenex_'
> Creating library file: genexlib.dll.a
> collect2: ld returned 1 exit status
>
> and get undefined reference.
>
> But If I try to compile the executable from similar code:
>
> >ghc --make genexlib.hs -O2
By the way, --make is the default mode from ghc-7.0 on, so you don't need
it here.
> Where is my mistake? What am I doing wrong?
> In first case, when compiling shared dll, I tried to link libraries what
> I've found in `cabal' directory (like `libHSregex-genex-0.3.2.a') to
> work around errors but all in vain.
The fundamental thing is that in --make mode, GHC figures out the required
Haskell dependencies itself. So it sees the import and looks in which
package it's provided and links (if necessary) with that package.
But when you tell it to link a couple of .o files, it's not in --make mode,
so apart from the specified files it links in only symbols from a few
select packages (I think the wired-in packages), so then you have to tell
it which other packages it needs to link in.
$ ghc -shared -package regex-genex -o genexlib.dll genexlib.o
genexlib_stub.o start.o
should fix the undefined reference.
------------------------------
Message: 2
Date: Mon, 5 Dec 2011 18:44:25 +0600
From: "Alexander.Vladislav.Popov "
<[email protected]>
Subject: Re: [Haskell-beginners] Compiling shared (dll) library
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<calpbq9ahaelw_jargx56tun42agnw2la0n-xwmrmsed6v3o...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
>
> The fundamental thing is that in --make mode, GHC figures out the required
> Haskell dependencies itself. So it sees the import and looks in which
> package it's provided and links (if necessary) with that package.
> But when you tell it to link a couple of .o files, it's not in --make mode,
> so apart from the specified files it links in only symbols from a few
> select packages (I think the wired-in packages), so then you have to tell
> it which other packages it needs to link in.
> $ ghc -shared -package regex-genex -o genexlib.dll genexlib.o
> genexlib_stub.o start.o
> should fix the undefined reference.
Aaaaaaaaaaa!
You are the Great Magician!
> compiling:
> > >ghc -c genexlib.hs
> > >ghc -c start.c
> > >ghc -shared -o genexlib.dll genexlib.o genexlib_stub.o start.o
> Why the separate compilation? Can't you compile them in one go?
Sorry for a stupid question, how is it?
And one more question, please: how I can export genexPure :: [String] ->
[String] to achieve all preferences of lazy list? Not all array at once,
but to get someting like an iterator, what I can call to get new genex.
--
Thanks a lot,
Alexander Popov.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20111205/7a25bb3e/attachment-0001.htm>
------------------------------
Message: 3
Date: Mon, 05 Dec 2011 13:57:58 +0000
From: Hugo Ferreira <[email protected]>
Subject: Re: [Haskell-beginners] Diagnosing : Large memory usage + low
CPU
To: "Edward Z. Yang" <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"; Format="flowed"
Hello,
First and foremost thanks for the link Edward. I have read up your
stuff.
On 12/05/2011 06:29 AM, Edward Z. Yang wrote:
> Excerpts from Hugo Ferreira's message of Fri Dec 02 05:57:00 -0500 2011:
>> I have attached a profiling session (showing types).
>> I am surprised to see that the "[]" consumes so much data.
>> Where is this coming from? Need to analyse this more closely.
>
> For an -hT profile, what that actually means is your lists are using lots
> of memory.
>
Funny enough I cannot get this option to work. All the other -h options
work fine though.
>> Any idea how I can track what's generating all those "[]" ?
>> Note that the (,,) seems to be the NGramTag. data which is basically
>> used as a list (Zipper).
>
> For that, I recommend rebuilding with profiling and use the RTS flag -hc.
>
Ok, so I ran this and as follows:
time nice -n 19 ./postagger +RTS -p -hc -L50 &> tmp19.txt
hp2ps -e8in -c postagger.hp
Now I see that "rsplit_" seems to be the culprit for the initial peaks
in memory use. However I also see in the profile that this function
seems to be responsible for only a small amount of memory generated.
Why such a big discrepancy between the live heap and the profile's total
memory?
Another question is, how can I cange the code below to avoid such
a peak? I already added ! to no avail.
rsplit :: Eq a => a -> [a] -> ([a], [a])
rsplit sep l = let (ps, xs, _) = rsplit_ sep l in
(ps, xs)
rsplit_ :: Eq a => a -> [a] -> ([a], [a], Bool)
rsplit_ sep l = foldr (splitFun sep) ([], [], False) l
where splitFun _ e !a@(!px, !xs, True) = (e:px, xs, True)
splitFun sep e !a@(!px, !xs, False)
| e == sep = (px, xs, True)
| otherwise = (px, e:xs, False)
toTrainingInstance' :: String -> NGramTag
toTrainingInstance' s = let (token, tag) = rsplit '/' s in
(token, tag, "")
toTrainingCorpus s = let (token, tag) = rsplit '/' s in
(token, tag, "")
evalTaggers' _ = do
h <- IO.openFile "brown-pos-train.txt" IO.ReadMode
c <- IO.hGetContents h
let train = toTrainingInstances $ map toTrainingInstance' $ words c
....
i <- IO.openFile "brown-pos-test.txt" IO.ReadMode
d <- IO.hGetContents i
let test = Z.fromList $ map toTrainingCorpus $ words d
...
Anyone see an obvious change that needs to be made?
TIA,
Hugo F.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postagger.ps
Type: application/postscript
Size: 111290 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20111205/302bbea0/attachment.ps>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: postagger.prof
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20111205/302bbea0/attachment.asc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: postagger.hp
Type: text/x-c++hdr
Size: 256304 bytes
Desc: not available
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20111205/302bbea0/attachment.hpp>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 42, Issue 6
****************************************