<commit_before><?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="viewDocbook.css"?>
<chapter id="Calcium">
    <title>The Calcium Skeleton Framework</title>
    <sect1>
        <title>Introduction</title>
        <sect2>
            <title>About Calcium</title>
            <para>
                Calcium is part of the ProActive Grid Middleware for
                programming structured parallel and distributed
                applications. The framework provides a basic set of
                structured patterns (skeletons) that can be nested to
                represents more complex patterns. Skeletons are
                considered a high level programming model because all
                the parallelisms details are hidden from the programmer.
                In Calcium, distributed programming is achieved by using
                ProActive deployment framework and active object model.
            </para>
            <para>
                The Calcium implementation can be found in the following
                package of the ProActive Middleware distribution:
            </para>
            <programlisting lang="java"><![CDATA[package org.objectweb.proactive.extensions.calcium;]]></programlisting>
        </sect2>
        <sect2>
            <title>The Big Picture</title>
            <para>
                The following steps must be performed for programming
                with the framework.
            </para>
            <orderedlist>
                <listitem>
                    <para>Define the skeleton structure.</para>
                </listitem>
                <listitem>
                    <para>
                        Implement the missing classes of the structure
                        (the muscle codes).
                    </para>
                </listitem>
                <listitem>
                    <para>Create a new Calcium instance.</para>
                </listitem>
                <listitem>
                    <para>
                        Provide a inputs of the problems to be solved by
                        the framework.
                    </para>
                </listitem>
                <listitem>
                    <para>Collect the results.</para>
                </listitem>
                <listitem>
                    <para>View the performance statistics.</para>
                </listitem>
            </orderedlist>
            <para>
                Problems inputed into the framework are treated as
                tasks. The tasks are interpreted by the remote skeleton
                interpreters as shown in the following Figure:
            </para>
            <figure>
                <title>Task Flow in Calcium</title>
                <mediaobject>
                    <imageobject>
                        <imagedata fileref="images/CalciumTaskFlow.png" />
                    </imageobject>
                </mediaobject>
            </figure>
            <para>
                All the generation, distribution of tasks and their
                resource is completely hidden from the programmer. In
                fact, the task concept is never used when programming in
                Calcium.
            </para>
            <indexterm></indexterm>
        </sect2>
    </sect1>
    <sect1>
        <title>Quick Example</title>
        <para>
            In this example we implement a skeleton program that finds
            prime numbers between an interval using a brute force
            (naive) approach.
        </para>
        <sect2>
            <title>Define the skeleton structure</title>
            <para>
                The approach consists of dividing the original search
                space into several smaller search spaces, and computing
                each sub search space in parallel. Therefore, the most
                suitable pattern corresponds to Divide and Conquer.
            </para>
            <programlisting lang="java"><![CDATA[//DaC(<Divide>,<Condition>,<Skeleton>,<Conquer>)
Skeleton<Interval, Primes> root = new DaC<Interval, Primes>(
    new IntervalDivide(),
    new IntervalDivideCondition(),
    new SearchInterval(),
    new JoinPrimes()
);]]></programlisting>
        </sect2>
        <sect2>
            <title>Implementing the Muscle Functions</title>
            <para>
                We will call the problem an
                <emphasis role="bold">Interval</emphasis>
                and we will represent it using the following class.
            </para>
            <programlisting lang="java"><![CDATA[class Interval implements Serializable {
    public int min,max;
    public int solvableSize;

    /**
     * Creates a new interval to search for primes.
     * @param min  Beginning of interval
     * @param max  End of interval
     * @param solvableSize Acceptable size of search interval
     */
    public Interval(int min, int max, int solvableSize) {
        this.min = min;
        this.max = max;
        this.solvableSize = solvableSize;
    }
}]]></programlisting>
            <para>
                The primes that are found will be stored in a
                <emphasis role="bold">Primes</emphasis>
                class.
            </para>
            <programlisting lang="java"><![CDATA[public class Primes implements Serializable {

    public Vector<Integer> list;

    public Primes(){
        primes=new Vector<Integer>();
    }
}]]></programlisting>
            <sect3>
                <title>Divide</title>
                <para>
                    The divition of an
                    <emphasis role="bold">Interval</emphasis>
                    into smaller intervals is handled by an
                    <emphasis role="bold">IntervalDivide</emphasis>
                    class:
                </para>
                <programlisting lang="java"><![CDATA[public class IntervalDivide implements Divide<Interval, Interval>{
    
    public Vector<Interval> divide(SkeletonSystem system, Interval param) {
        
        Interval ttUp = new Interval(1+param.min+(param.max-param.min)/2,param.max,param.solvableSize);

        Interval ttDown = new Interval(param.min,param.min+(param.max-param.min)/2, param.solvableSize);
        
        Vector<Challenge> v = new Vector<Challenge>();
        v.add(ttUp);
        v.add(ttDown);
        
        return v;
    }
}]]></programlisting>
                >
            </sect3>
            <sect3>
                <title>Condition</title>
                <para>
                    The class
                    <emphasis role="bold">
                        IntervalDivideCondition
                    </emphasis>
                    is used to determine if an
                    <emphasis role="bold">Interval</emphasis>
                    must be subdivided or not.
                </para>
                <programlisting lang="java"><![CDATA[public class IntervalDivideCondition implements Condition<Interval>{
    
    public boolean evalCondition(SkeletonSystem system, Interval params) {
        
        return params.max-params.min > params.solvableSize;
    }
}]]></programlisting>
            </sect3>
            <sect3>
                <title>Skeleton</title>
                <para><commit_msg>Minor typo<commit_after><?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="viewDocbook.css"?>
<chapter id="Calcium">
    <title>The Calcium Skeleton Framework</title>
    <sect1>
        <title>Introduction</title>
        <sect2>
            <title>About Calcium</title>
            <para>
                Calcium is part of the ProActive Grid Middleware for
                programming structured parallel and distributed
                applications. The framework provides a basic set of
                structured patterns (skeletons) that can be nested to
                represents more complex patterns. Skeletons are
                considered a high level programming model because all
                the parallelisms details are hidden from the programmer.
                In Calcium, distributed programming is achieved by using
                ProActive deployment framework and active object model.
            </para>
            <para>
                The Calcium implementation can be found in the following
                package of the ProActive Middleware distribution:
            </para>
            <programlisting lang="java"><![CDATA[package org.objectweb.proactive.extensions.calcium;]]></programlisting>
        </sect2>
        <sect2>
            <title>The Big Picture</title>
            <para>
                The following steps must be performed for programming
                with the framework.
            </para>
            <orderedlist>
                <listitem>
                    <para>Define the skeleton structure.</para>
                </listitem>
                <listitem>
                    <para>
                        Implement the missing classes of the structure
                        (the muscle codes).
                    </para>
                </listitem>
                <listitem>
                    <para>Create a new Calcium instance.</para>
                </listitem>
                <listitem>
                    <para>
                        Provide a inputs of the problems to be solved by
                        the framework.
                    </para>
                </listitem>
                <listitem>
                    <para>Collect the results.</para>
                </listitem>
                <listitem>
                    <para>View the performance statistics.</para>
                </listitem>
            </orderedlist>
            <para>
                Problems inputed into the framework are treated as
                tasks. The tasks are interpreted by the remote skeleton
                interpreters as shown in the following Figure:
            </para>
            <figure>
                <title>Task Flow in Calcium</title>
                <mediaobject>
                    <imageobject>
                        <imagedata fileref="images/CalciumTaskFlow.png" />
                    </imageobject>
                </mediaobject>
            </figure>
            <para>
                All the generation, distribution of tasks and their
                resource is completely hidden from the programmer. In
                fact, the task concept is never used when programming in
                Calcium.
            </para>
            <indexterm></indexterm>
        </sect2>
    </sect1>
    <sect1>
        <title>Quick Example</title>
        <para>
            In this example we implement a skeleton program that finds
            prime numbers between an interval using a brute force
            (naive) approach.
        </para>
        <sect2>
            <title>Define the skeleton structure</title>
            <para>
                The approach consists of dividing the original search
                space into several smaller search spaces, and computing
                each sub search space in parallel. Therefore, the most
                suitable pattern corresponds to Divide and Conquer.
            </para>
            <programlisting lang="java"><![CDATA[//DaC(<Divide>,<Condition>,<Skeleton>,<Conquer>)
Skeleton<Interval, Primes> root = new DaC<Interval, Primes>(
    new IntervalDivide(),
    new IntervalDivideCondition(),
    new SearchInterval(),
    new JoinPrimes()
);]]></programlisting>
        </sect2>
        <sect2>
            <title>Implementing the Muscle Functions</title>
            <para>
                We will call the problem an
                <emphasis role="bold">Interval</emphasis>
                and we will represent it using the following class.
            </para>
            <programlisting lang="java"><![CDATA[class Interval implements Serializable {
    public int min,max;
    public int solvableSize;

    /**
     * Creates a new interval to search for primes.
     * @param min  Beginning of interval
     * @param max  End of interval
     * @param solvableSize Acceptable size of search interval
     */
    public Interval(int min, int max, int solvableSize) {
        this.min = min;
        this.max = max;
        this.solvableSize = solvableSize;
    }
}]]></programlisting>
            <para>
                The primes that are found will be stored in a
                <emphasis role="bold">Primes</emphasis>
                class.
            </para>
            <programlisting lang="java"><![CDATA[public class Primes implements Serializable {

    public Vector<Integer> list;

    public Primes(){
        primes=new Vector<Integer>();
    }
}]]></programlisting>
            <sect3>
                <title>Divide</title>
                <para>
                    The divition of an
                    <emphasis role="bold">Interval</emphasis>
                    into smaller intervals is handled by an
                    <emphasis role="bold">IntervalDivide</emphasis>
                    class:
                </para>
                <programlisting lang="java"><![CDATA[public class IntervalDivide implements Divide<Interval, Interval>{
    
    public Vector<Interval> divide(SkeletonSystem system, Interval param) {
        
        Interval ttUp = new Interval(1+param.min+(param.max-param.min)/2,param.max,param.solvableSize);

        Interval ttDown = new Interval(param.min,param.min+(param.max-param.min)/2, param.solvableSize);
        
        Vector<Challenge> v = new Vector<Challenge>();
        v.add(ttUp);
        v.add(ttDown);
        
        return v;
    }
}]]></programlisting>
                
            </sect3>
            <sect3>
                <title>Condition</title>
                <para>
                    The class
                    <emphasis role="bold">
                        IntervalDivideCondition
                    </emphasis>
                    is used to determine if an
                    <emphasis role="bold">Interval</emphasis>
                    must be subdivided or not.
                </para>
                <programlisting lang="java"><![CDATA[public class IntervalDivideCondition implements Condition<Interval>{
    
    public boolean evalCondition(SkeletonSystem system, Interval params) {
        
        return params.max-params.min > params.solvableSize;
    }
}]]></programlisting>
            </sect3>
            <sect3>
                <title>Skeleton</title>
                <para>
{'fraction_non_alphanumeric': 0.08401920438957476, 'fraction_numerical': 0.002880658436213992, 'mean_word_length': 1.5053264604810996, 'pattern_counts': {'":': 0, '<': 285, '<?xml version=': 2, '>': 288, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6394579', 'n_tokens_mistral': 3623, 'n_tokens_neox': 3277, 'n_words': 1062}