Re: Compiler optimizations and other performance hacks for HiGHS

Nicholas McKibben <[email protected]> Tue, 14 Mar 2023 08:50:42 -0700
Newsgroups gmane.comp.python.scientific.user
Message-ID <CAHrOx8AtTX7F1=w3U6qn+i4YM9z0Qnk8gtaueU6qqiyOr3cZRQ@mail.gmail.com>
--===============9036230697836334330==
Content-Type: multipart/alternative; boundary="000000000000f14f8d05f6de2e85"

--000000000000f14f8d05f6de2e85
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

> For HiGHS specifically, I think the main thing is that we disable its
OpenMP support because we don't allow OpenMP usage in SciPy. But you could
probably enable it by removing the `-UOPENMP` build flag from
`optimize/_highs/meson.build`.

I believe the version of HiGHS we currently include in SciPy doesn't rely
at all on OpenMP anymore.  We may have kept that -UOPENMP for a
stray/accidental inclusion, but I don't find any non-test usage of "#pragma
omp".  HiGHS maintainers have indicated to us that parallelism isn't
currently being actively developed and doesn't give much improvement, but
that may change in the future.

> Are there any tricks, hacks, optimizations that one should be aware of to
get as much as possible out of HiGHS? I only care about LPs and stuff that
works on x86 and/or ARM64.

I suspect you are running into limitations of the Cython wrapper and
start-up costs of allocating objects for each LP that needs to be solved.
We have a more lightweight wrapper using the Python/NumPy C APIs directly
in the works:
https://github.com/mckib2/scipy/blob/high-py-c-api/scipy/optimize/_highs/py=
ext/highsmodule.cpp

If you're brave, you might try building and calling it directly.  I'd be
interested to hear if it positively impacts the metrics you care about.
It's meant to be a drop-in replacement for
scipy.optimize._highs._highs_wrapper but has not been integrated into the
linprog function proper.  It should have no dynamic allocations for HiGHS
objects (which was sometimes not possible with the Cython wrapper).

Thanks,
Nicholas

On Tue, Mar 14, 2023 at 8:30=E2=80=AFAM David Men=C3=A9ndez Hurtado <
[email protected]> wrote:

> Setting march=3Dnative on GCC usually buys you a bit of performance,
> specially if you are running on high end modern hardware.
>
> On Tue, 14 Mar 2023, 14:05 S=C3=B8ren Fuglede J=C3=B8rgensen via SciPy-Us=
er, <
> [email protected]> wrote:
>
>> I have a workflow where I'm solving a bunch of (non-integral) LPs, and
>> `scipy.optimize._highs._highs_wrapper` is the main bottleneck, and I was
>> looking for ways to squeeze out as much performance of that as I could. =
For
>> instance, I was looking around for stuff like "-O3" in the `meson.build`=
,
>> `CMakeLists.txt`, `setup.py` but didn't find anything, so I was wonderin=
g
>> if the compilation uses performance optimizations, or if it even matters=
.
>> Or, more generally:
>>
>> Are there any tricks, hacks, optimizations that one should be aware of t=
o
>> get as much as possible out of HiGHS? I only care about LPs and stuff th=
at
>> works on x86 and/or ARM64.
>>
>> Thanks!
>> _______________________________________________
>> SciPy-User mailing list -- [email protected]
>> To unsubscribe send an email to [email protected]
>> https://mail.python.org/mailman3/lists/scipy-user.python.org/
>> Member address: [email protected]
>>
> _______________________________________________
> SciPy-User mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/scipy-user.python.org/
> Member address: [email protected]
>

--000000000000f14f8d05f6de2e85
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr">&gt; For HiGHS specifically, I think the =
main thing is that we disable=20
its OpenMP support because we don&#39;t allow OpenMP usage in SciPy. But yo=
u
 could probably enable it by removing the `-UOPENMP` build flag from=20
`optimize/_highs/meson.build`.</div><div dir=3D"ltr"><br></div><div>I belie=
ve the version of HiGHS we currently include in SciPy doesn&#39;t rely at a=
ll on OpenMP anymore.=C2=A0 We may have kept that -UOPENMP for a stray/acci=
dental inclusion, but I don&#39;t find any non-test usage of &quot;#pragma =
omp&quot;.=C2=A0 HiGHS maintainers have indicated to us that parallelism is=
n&#39;t currently being actively developed and doesn&#39;t give much improv=
ement, but that may change in the future.<br></div><div><br></div><div>&gt;=
=20
Are there any tricks, hacks, optimizations that one should be aware of=20
to get as much as possible out of HiGHS? I only care about LPs and stuff
 that works on x86 and/or ARM64.</div><div><br></div><div>I suspect you are=
 running into limitations of the Cython wrapper and start-up costs of alloc=
ating objects for each LP that needs to be solved.=C2=A0 We have a more lig=
htweight wrapper using the Python/NumPy C APIs directly in the works: <a hr=
ef=3D"https://github.com/mckib2/scipy/blob/high-py-c-api/scipy/optimize/_hi=
ghs/pyext/highsmodule.cpp">https://github.com/mckib2/scipy/blob/high-py-c-a=
pi/scipy/optimize/_highs/pyext/highsmodule.cpp</a></div><div><br></div><div=
>If you&#39;re brave, you might try building and calling it directly.=C2=A0=
 I&#39;d be interested to hear if it positively impacts the metrics you car=
e about.=C2=A0 It&#39;s meant to be a drop-in replacement for scipy.optimiz=
e._highs._highs_wrapper but has not been integrated into the linprog functi=
on proper.=C2=A0 It should have no dynamic allocations for HiGHS objects (w=
hich was sometimes not possible with the Cython wrapper).<br></div><div dir=
=3D"ltr"><br></div><div>Thanks,</div><div>Nicholas<br></div><div><br></div>=
<div class=3D"gmail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, Ma=
r 14, 2023 at 8:30=E2=80=AFAM David Men=C3=A9ndez Hurtado &lt;<a href=3D"ma=
ilto:[email protected]">[email protected]</a>&gt; wrote:<br></div><=
blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l=
eft:1px solid rgb(204,204,204);padding-left:1ex"><div dir=3D"auto">Setting =
march=3Dnative on GCC usually buys you a bit of performance, specially if y=
ou are running on high end modern hardware.=C2=A0</div><br><div class=3D"gm=
ail_quote"><div dir=3D"ltr" class=3D"gmail_attr">On Tue, 14 Mar 2023, 14:05=
 S=C3=B8ren Fuglede J=C3=B8rgensen via SciPy-User, &lt;<a href=3D"mailto:sc=
[email protected]" target=3D"_blank">[email protected]</a>&gt; wrote:=
<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8=
ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I have a workfl=
ow where I&#39;m solving a bunch of (non-integral) LPs, and `scipy.optimize=
._highs._highs_wrapper` is the main bottleneck, and I was looking for ways =
to squeeze out as much performance of that as I could. For instance, I was =
looking around for stuff like &quot;-O3&quot; in the `meson.build`, `CMakeL=
ists.txt`, `setup.py` but didn&#39;t find anything, so I was wondering if t=
he compilation uses performance optimizations, or if it even matters. Or, m=
ore generally:<br>
<br>
Are there any tricks, hacks, optimizations that one should be aware of to g=
et as much as possible out of HiGHS? I only care about LPs and stuff that w=
orks on x86 and/or ARM64.<br>
<br>
Thanks!<br>
_______________________________________________<br>
SciPy-User mailing list -- <a href=3D"mailto:[email protected]" rel=3D"=
noreferrer" target=3D"_blank">[email protected]</a><br>
To unsubscribe send an email to <a href=3D"mailto:[email protected]=
rg" rel=3D"noreferrer" target=3D"_blank">[email protected]</a><br=
>
<a href=3D"https://mail.python.org/mailman3/lists/scipy-user.python.org/" r=
el=3D"noreferrer noreferrer" target=3D"_blank">https://mail.python.org/mail=
man3/lists/scipy-user.python.org/</a><br>
Member address: <a href=3D"mailto:[email protected]" rel=3D"noreferrer"=
 target=3D"_blank">[email protected]</a><br>
</blockquote></div>
_______________________________________________<br>
SciPy-User mailing list -- <a href=3D"mailto:[email protected]" target=
=3D"_blank">[email protected]</a><br>
To unsubscribe send an email to <a href=3D"mailto:[email protected]=
rg" target=3D"_blank">[email protected]</a><br>
<a href=3D"https://mail.python.org/mailman3/lists/scipy-user.python.org/" r=
el=3D"noreferrer" target=3D"_blank">https://mail.python.org/mailman3/lists/=
scipy-user.python.org/</a><br>
Member address: <a href=3D"mailto:[email protected]" target=3D"_blank"=
>[email protected]</a><br>
</blockquote></div></div>

--000000000000f14f8d05f6de2e85--

--===============9036230697836334330==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
SciPy-User mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/scipy-user.python.org/
Member address: [email protected]

--===============9036230697836334330==--