Loading ...
Sorry, an error occurred while loading the content.

jocaml

Expand Messages
  • babelfish007
    Hi, I hope it s okay to post this in ocaml beginners, even though it s a JoCaml question. I m interested in using JoCaml to hopefully speed up some programs
    Message 1 of 4 , Sep 1, 2009
    • 0 Attachment
      Hi,

      I hope it's okay to post this in "ocaml beginners," even though it's a JoCaml question. I'm interested in using JoCaml to hopefully speed up some programs by using multiple processors. As a simple test, I wrote a program that computes Fibonacci numbers in each language:

      JOCAML
      --------------
      def fib(n) =
      if n <= 1 then reply 1 to fib
      else reply fib(n-1) + fib(n-2) to fib
      ;;

      let get_fibs ti =
      let answers = ref [] in
      for iteration = 1 to ti do
      answers := fib(iteration)::!answers;
      done;
      !answers;;

      let fibs = ref [] in
      for i = 1 to 200 do
      fibs := get_fibs 30;
      done;;

      OCAML
      --------------

      let rec fib n =
      if n <= 1 then 1
      else fib (n-1) + fib (n-2);;

      let get_fibs ti =
      let answers = ref [] in
      for iteration = 1 to ti do
      answers := fib iteration::!answers;
      done;
      !answers;;

      let fibs = ref [] in
      for i = 1 to 200 do
      fibs := get_fibs 30;
      done;;

      I compiled these to native code as follows:

      ocamlopt ocaml-code.ml was named o_fibo
      jocamlopt ocaml-code.ml was named jo_fibo
      jocamlopt jocaml-code.ml was named jo_fibjo

      I used a Python script to run and time each program and got this output:

      dgclark: [/opt/msw] pylon $ python compare_jo_to_o.py
      ./jo_fibo
      ./o_fibo
      ./jo_fibjo
      Time elapsed for ./jo_fibo is 14.8446891308
      Time elapsed for ./o_fibo is 20.3937339783
      Time elapsed for ./jo_fibjo is 20.2132298946

      A few things puzzle me here:
      1) The jocaml compiler consistently generates a faster executable than the ocaml compiler when given the same ocaml code.
      2) The jocaml compiler consistently generates a slower executable from jocaml code than from ocaml code.
      3) When watching the activity of the two processors on my machine (a dual 2.0 GHz PowerPC G5, running OS X 10.5) I don't see any increased tendency to use both processors while the jo_fibjo program is running.

      My questions are:

      1) Can I really expect JoCaml to run faster than Ocaml on machines with multiple processors?
      2) Is the problem here my code? i.e., have I missed something about how to write truly concurrent code in JoCaml? (I got this fibonacci function from the JoCaml introduction online.)

      Thanks if anyone can help.

      David
    • babelfish007
      Hi, I hope it s okay to post this in ocaml beginners, even though it s a JoCaml question. I m interested in using JoCaml to hopefully speed up some programs
      Message 2 of 4 , Sep 1, 2009
      • 0 Attachment
        Hi,

        I hope it's okay to post this in "ocaml beginners," even though it's a JoCaml question. I'm interested in using JoCaml to hopefully speed up some programs by using multiple processors. As a simple test, I wrote a program that computes Fibonacci numbers in each language:

        JOCAML
        --------------
        def fib(n) =
        if n <= 1 then reply 1 to fib
        else reply fib(n-1) + fib(n-2) to fib
        ;;

        let get_fibs ti =
        let answers = ref [] in
        for iteration = 1 to ti do
        answers := fib(iteration)::!answers;
        done;
        !answers;;

        let fibs = ref [] in
        for i = 1 to 200 do
        fibs := get_fibs 30;
        done;;

        OCAML
        --------------

        let rec fib n =
        if n <= 1 then 1
        else fib (n-1) + fib (n-2);;

        let get_fibs ti =
        let answers = ref [] in
        for iteration = 1 to ti do
        answers := fib iteration::!answers;
        done;
        !answers;;

        let fibs = ref [] in
        for i = 1 to 200 do
        fibs := get_fibs 30;
        done;;

        I compiled these to native code as follows:

        ocamlopt ocaml-code.ml was named o_fibo
        jocamlopt ocaml-code.ml was named jo_fibo
        jocamlopt jocaml-code.ml was named jo_fibjo

        I used a Python script to run and time each program and got this output:

        dgclark: [/opt/msw] pylon $ python compare_jo_to_o.py
        ./jo_fibo
        ./o_fibo
        ./jo_fibjo
        Time elapsed for ./jo_fibo is 14.8446891308
        Time elapsed for ./o_fibo is 20.3937339783
        Time elapsed for ./jo_fibjo is 20.2132298946

        A few things puzzle me here:
        1) The jocaml compiler consistently generates a faster executable than the ocaml compiler when given the same ocaml code.
        2) The jocaml compiler consistently generates a slower executable from jocaml code than from ocaml code.
        3) When watching the activity of the two processors on my machine (a dual 2.0 GHz PowerPC G5, running OS X 10.5) I don't see any increased tendency to use both processors while the jo_fibjo program is running.

        My questions are:

        1) Can I really expect JoCaml to run faster than Ocaml on machines with multiple processors?
        2) Is the problem here my code? i.e., have I missed something about how to write truly concurrent code in JoCaml? (I got this fibonacci function from the JoCaml introduction online.)

        Thanks if anyone can help.

        David
      • Dario Teixeira
        Hi, ... At the present time JoCaml only uses one CPU core. JoCaml inherits much of the same components used in Ocaml, including the non-concurrent GC...
        Message 3 of 4 , Sep 1, 2009
        • 0 Attachment
          Hi,

          > 1) Can I really expect JoCaml to run faster than Ocaml on
          > machines with multiple processors?
          > 2) Is the problem here my code? i.e., have I missed
          > something about how to write truly concurrent code in
          > JoCaml? (I got this fibonacci function from the JoCaml
          > introduction online.)

          At the present time JoCaml only uses one CPU core. JoCaml inherits much
          of the same components used in Ocaml, including the non-concurrent GC...

          Cheers,
          Dario Teixeira
        • markwvh
          ... Dario s right. If you d like to use multiple cores, you ll need to run multiple OS processes. (By using the name service (Join.Ns), you may provide access
          Message 4 of 4 , Sep 3, 2009
          • 0 Attachment
            --- In ocaml_beginners@yahoogroups.com, Dario Teixeira <darioteixeira@...> wrote:
            >
            > Hi,
            >
            > > 1) Can I really expect JoCaml to run faster than Ocaml on
            > > machines with multiple processors?
            > > 2) Is the problem here my code? i.e., have I missed
            > > something about how to write truly concurrent code in
            > > JoCaml? (I got this fibonacci function from the JoCaml
            > > introduction online.)
            >
            > At the present time JoCaml only uses one CPU core. JoCaml inherits much
            > of the same components used in Ocaml, including the non-concurrent GC...

            Dario's right.

            If you'd like to use multiple cores, you'll need to run multiple OS processes. (By using the name service (Join.Ns), you may provide access to a channel in one process from other OS processes.)

            This works best for coarse-grained parallelism (i.e. non-trivial computations).
          Your message has been successfully submitted and would be delivered to recipients shortly.