From: "John Caml" <camljohn42@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] large hash tables
Date: Thu, 21 Feb 2008 14:45:21 -0800 [thread overview]
Message-ID: <33d2b3f70802211445q7781d296ka7dd94114b8033b1@mail.gmail.com> (raw)
In-Reply-To: <1203522851.47bc4d2310d0c@webmail.in-berlin.de>
The equivalent C++ program uses 874 MB of memory in total. Each of the
1 million records is stored in a vector using 1 single-precision float
and 1 int. Indeed, my machine is AMD64 so Ocaml int's are presumably 8
bytes.
I've rewritten my Ocaml program again, this time using Bigarray. Its
memory usage is now the same as under C++, so that's good news.
However, my program is quite ugly now, and it's actually more than
twice as long as my C++ program. Any suggestions for simplifying this
program? The way I initialize the "movieMajor" Array seems especially
wonky, but I couldn't figure out a better way.
Thank you all very much.
John
----------------------------
open Bigarray;;
exception SplitError;;
exception ImpossibleError;;
type listPairs = {userList : int32 list; resList : float list};;
type baPairs = {
userBa : (int32, int32_elt, c_layout) Array1.t;
resBa : (float, float32_elt, c_layout) Array1.t};;
let loadWholeFile filename =
let infile = open_in filename in
let dummyUserBa = Array1.of_array int32 c_layout (Array.of_list []) in
let dummyResBa = Array1.of_array float32 c_layout (Array.of_list []) in
let dummyBas = {userBa = dummyUserBa; resBa = dummyResBa} in
let movieMajor = Array.make 17770 dummyBas in
let recordWholeMovie mInt curListPairs =
let userBa = Array1.of_array int32 c_layout (Array.of_list
curListPairs.userList) in
let resBa = Array1.of_array float32 c_layout (Array.of_list
curListPairs.resList) in
let movieBas = {userBa = userBa; resBa = resBa} in
movieMajor.(mInt) <- movieBas
in
let rec loadLines prevPairs prevMovie count =
let line = input_line infile in
let murList = Pcre.split line in
match murList with
| m::u::r::[] ->
let rFloat = float_of_string r
and mInt = int_of_string m
and uInt = int_of_string u in
if (count mod 1000000) = 0 then begin
Printf.printf "count: %d\n" count;
flush stdout;
end;
let newPairs =
if mInt = prevMovie then
{userList = Int32.of_int(uInt) :: prevPairs.userList; resList =
rFloat :: prevPairs.resList}
else begin
recordWholeMovie mInt prevPairs;
{userList = [Int32.of_int(uInt)]; resList = [rFloat]}
end
in
loadLines newPairs mInt (count + 1)
(* bug: last movie will not get loaded *)
| _ -> raise SplitError
in
try
let emptyPairs = {userList = []; resList = []} in
loadLines emptyPairs (-1) 0
with
End_of_file -> close_in infile;
movieMajor;;
let filename = Sys.argv.(1);;
loadWholeFile filename;;
next prev parent reply other threads:[~2008-02-21 22:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-19 23:01 John Caml
2008-02-19 23:34 ` [Caml-list] " Gabriel Kerneis
2008-02-19 23:36 ` Gerd Stolpmann
2008-02-19 23:51 ` Francois Rouaix
2008-02-20 9:37 ` Berke Durak
2008-02-20 9:56 ` Berke Durak
2008-02-20 12:48 ` Richard Jones
2008-02-20 15:54 ` Oliver Bandel
2008-02-21 22:45 ` John Caml [this message]
2008-02-22 0:33 ` Richard Jones
2008-02-24 5:39 ` John Caml
2008-02-22 14:19 ` Brian Hurt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=33d2b3f70802211445q7781d296ka7dd94114b8033b1@mail.gmail.com \
--to=camljohn42@gmail.com \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox