Re: Excessive copies of set elements in GMPL

Domingo Alvarez Duarte <[email protected]> Thu, 16 Jul 2020 22:25:57 +0200
Newsgroups gmane.comp.gnu.glpk
Message-ID <[email protected]>
Hello Andrew !

Thank you for reply !

I'm aware of it and that's why I've added an assert in "add_tuple" and 
so far it was not triggered running several models including "osemosys" 
where the output file "SelectedResults.csv" are identical.

Do you have any tests or know someone that has then and can share then ? 
(Preferable in a public repository.)

=====

MEMBER *add_tuple
(     MPL *mpl,
       ELEMSET *set,           /* modified */
       TUPLE *tuple            /* destroyed */
)
{     MEMBER *memb;
       xassert(set != NULL);
       xassert(set->type == A_NONE);
       xassert(set->dim == tuple_dimen(mpl, tuple));
       xassert(set->refcount == 1); /////XXXXXXXX!!!!! if try to insert 
to a copy refcount > 1
       memb = add_member(mpl, set, tuple);
       memb->value.none = NULL;
       return memb;
}

=====

===== #glp 4.65 distribution

/usr/bin/time ./glpsol --check -m osemosys.mod -d atlantis.dat

Model has been successfully generated
--- Problem Characteristics ---
Number of rows               =   232144
Number of columns            =   226799
Number of non-zeros (matrix) =   562936
Number of non-zeros (objrow) =       27
3.25user 0.08system 0:03.33elapsed 100%CPU (0avgtext+0avgdata 
309540maxresident)k

=====

===== #glp 4.65 with my changes

#CFLAGS="-g -O3 -DWITH_SPLAYTREE -DNDEBUG -flto" ./configure

/usr/bin/time ./glpsol --check -m osemosys.mod -d atlantis.dat

--- Problem Characteristics ---
Number of rows               =   232144
Number of columns            =   226799
Number of non-zeros (matrix) =   562936
Number of non-zeros (objrow) =       27
1.82user 0.08system 0:01.90elapsed 100%CPU (0avgtext+0avgdata 
267216maxresident)k

=====

Cheers !

On 16/7/20 22:01, Andrew Makhorin wrote:
>> After doing some experimentation I think I found an easy way to
>> eliminate unnecessary set copies here is a commit on
>> https://github.com/mingodad/GLPK/commit/6f3da6ab31ca8d710f706f60635e5
>> b17cf2ded40,
>> also see bellow, glpsol now uses 1/3 of the memory and is slight
>> faster:
> Please note that in the MathProg translator there are two ways used to
> pass array objects: by reference, when no copy is created, and by
> value, when a copy is created. In the latter case it is assumed that
> the routine may change the object passed (directly or indirectly), so
> I'm not sure that your approach based on using reference counts will
> work correctly in a general case.