caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Tahir H Butt <tahir@acm.jhu.edu>
To: caml-list@inria.fr
Subject: [Caml-list] memory problems
Date: 19 Aug 2003 16:11:33 -0400	[thread overview]
Message-ID: <1061323892.20426.33.camel@venere.cog.brown.edu> (raw)

Hi all,

There seems to be something going screwy in a piece of my code. The code
is used to average a matrix of values over several modifications. 

  for r=0 to k-1 do
    let matrix_r = matrix.(r) in
    let f_r = feature_vals.(r) in
    for j=0 to n-1 do
      let f_rj = f_r.(j) in
      let matrix_rj = matrix_r.(j) in
      let current_sum = f_rj.current_sum in
      let generation = f_rj.generation in
      let new_sum = current_sum +. 
        (matrix_rj *. (float_of_int (generation_counter -
generation)))
      in
      (* VARIED SECTION *)
      f_rj.generation <- generation_counter
    done
  done;

(* VARIED SECTION *) is
	(A) f_rj.current_sum <- current_sum;
or
	(B) f_rj.current_sum <- 1.0;
or
	(C) f_rj.current_sum <- new_sum;

Using both ocamlopt and ocamlc (3.06, and 3.07beta1, with and without
optimization flags), (A) and (B) keep a constant memory load through the
course of the program. (C) which is the actual value I need to set
causes the memory usage to grow each time the above function is called.

I've tried throwing in some Gc.compact() lines, without luck.

This is mildly frustrating. Is this a bug, or a mistake on my part? I
can send whoever wishes to see the rest of the code the source, but it's
probably not critical here. I tried replicating this as an isolated
case, and it didn't seem to cause problems. 

Any ideas? Has someone reported a similar bug? I tried searching the BTS
without luck.

Sorry if this might be of trivial concern, but I'm far from an expert of
the ocaml language.

Here is some Gc.stat info, before and after the code above, as well as
with Gc.compact() (all with ocaml-3.07beta1)

% Before function
minor_words: 108910518
promoted_words: 36319417
major_words: 67201780
minor_collections: 4947
major_collections: 10
heap_words: 69238784
heap_chunks: 598
top_heap_words: 69238784
live_words: 66342960
live_blocks: 11447005
free_words: 2895824
free_blocks: 89
largest_free: 61440
fragments: 0
compactions: 1
% After function
minor_words: 141302822
promoted_words: 67223235
major_words: 98105598
minor_collections: 7505
major_collections: 11
heap_words: 97255424
heap_chunks: 1054
top_heap_words: 97255424
live_words: 97246778
live_blocks: 21747585
free_words: 8646
free_blocks: 43
largest_free: 8562
fragments: 0
compactions: 1
% After function and compact
minor_words: 141303588
promoted_words: 67223235
major_words: 98106033
minor_collections: 7505
major_collections: 13
heap_words: 97255424
heap_chunks: 1054
top_heap_words: 97255424
live_words: 95698876
live_blocks: 21232921
free_words: 1556548
free_blocks: 67
largest_free: 61440
fragments: 0
compactions: 2

Thanks
	--tahir

Tahir H Butt
Brown University
Cognitive and Linguistic Sciences
PhD Student
http://www.cog.brown.edu/~tahir

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


             reply	other threads:[~2003-08-19 20:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-19 20:11 Tahir H Butt [this message]
2003-08-21 12:54 ` Xavier Leroy

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=1061323892.20426.33.camel@venere.cog.brown.edu \
    --to=tahir@acm.jhu.edu \
    --cc=caml-list@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;
as well as URLs for NNTP newsgroup(s).