Skip to content

Commit

Permalink
Merge pull request #1 from michaelbynum/hsl_interface
Browse files Browse the repository at this point in the history
working on cmake for pynumero hsl
  • Loading branch information
Robbybp committed May 6, 2020
2 parents 96615c1 + 966cee1 commit 0b78c7e
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 157 deletions.
21 changes: 18 additions & 3 deletions pyomo/contrib/pynumero/README.md
Expand Up @@ -14,7 +14,7 @@ PyNumero libraries

PyNumero relies on C/C++ extensions for expensive computing operations.

If you installed Pyomo using Anaconda (from conda-forge), then you can
If you installed Pyomo using conda (from conda-forge), then you can
obtain precompiled versions of the redistributable interfaces
(pynumero_ASL) using conda. Through Pyomo 5.6.9 these libraries are
available by installing the `pynumero_libraries` package from
Expand All @@ -27,7 +27,20 @@ interfaces, you can build the extensions locally one of three ways:
1. By running the `build.py` Python script in this directory. This
script will automatically drive the `cmake` build harness to compile the
libraries and install them into your local Pyomo configuration
directory.
directory. Cmake options may be specified in the command. For example,

python build.py -DBUILD_ASL=ON

If you have compiled Ipopt, and you would like to link against the
libraries built with Ipopt, you can. For example,

python build.py -DBUILD_ASL=ON -DBUILD_MA27=ON -DIPOPT_DIR=<path_to_ipopt_build>/lib/

If you do so, you will likely need to update an environment variable
for the path to shared libraries. For example, on Linux,

export LD_LIBRARY_PATH=<path_to_ipopt_build>/lib/

2. By running `pyomo build-extensions`. This will build all registered
Pyomo binary extensions, including PyNumero (using the `build.py` script
from option 1).
Expand All @@ -48,4 +61,6 @@ Prerequisites
this library)

2. `pynumero_MA27`:
- *TODO*
- cmake
- a C/C++ compiler
- MA27 library
Expand Up @@ -10,7 +10,9 @@
import sys
import os
import ctypes
import numpy as np
from pyomo.contrib.pynumero.dependencies import numpy as np, numpy_available
if not numpy_available:
raise unittest.SkipTest('pynumero MA27 tests require numpy')
import numpy.ctypeslib as npct
import pyutilib.th as unittest
from pyomo.contrib.pynumero.extensions.ma27_interface import *
Expand Down
Expand Up @@ -10,7 +10,9 @@
import sys
import os
import ctypes
import numpy as np
from pyomo.contrib.pynumero.dependencies import numpy as np, numpy_available
if not numpy_available:
raise unittest.SkipTest('pynumero MA27 tests require numpy')
import numpy.ctypeslib as npct
import pyutilib.th as unittest
from pyomo.contrib.pynumero.extensions.ma57_interface import *
Expand Down
9 changes: 5 additions & 4 deletions pyomo/contrib/pynumero/src/CMakeLists.txt
Expand Up @@ -139,9 +139,11 @@ IF( BUILD_ASL )
ENDIF()
ENDIF()

#
# build hsl interfaces
#
set(PYNUMERO_MA27_SOURCES
"ma27Interface.cpp"
"ma27Interface.hpp"
"ma27Interface.c"
)

IF( BUILD_MA27 )
Expand All @@ -153,8 +155,7 @@ IF( BUILD_MA27 )
ENDIF()

set(PYNUMERO_MA57_SOURCES
"ma57Interface.cpp"
"ma57Interface.hpp"
"ma57Interface.c"
)

IF( BUILD_MA57 )
Expand Down
54 changes: 0 additions & 54 deletions pyomo/contrib/pynumero/src/hsl_interface/Makefile

This file was deleted.

32 changes: 0 additions & 32 deletions pyomo/contrib/pynumero/src/hsl_interface/Makefile.in

This file was deleted.

Expand Up @@ -204,39 +204,3 @@ void free_memory(struct MA27_struct* ma27) {
}
free(ma27);
}

int main() {

struct MA27_struct* ma27 = new_MA27_struct();

printf("ICNTL[1-1]: %i\n", get_icntl(ma27, 0));
printf("ICNTL[2-1]: %i\n", get_icntl(ma27, 1));
printf("ICNTL[3-1]: %i\n", get_icntl(ma27, 2));
printf("ICNTL[4-1]: %i\n", get_icntl(ma27, 3));

// Set print level
set_icntl(ma27, 2, 2);
printf("ICNTL[3-1]: %i\n", get_icntl(ma27, 2));

int N = 5, NZ = 7;
int IRN[7] = { 1, 1, 2, 2, 3, 3, 5 };
int ICN[7] = { 1, 2, 3, 5, 3, 4, 5 };
double* A = malloc(NZ*sizeof(double));
if (A == NULL) { abort_bad_memory(1); }
// A = { 2., 3., 4., 6., 1., 5., 1. };
A[0] = 2.;
A[1] = 3.;
A[2] = 4.;
A[3] = 6.;
A[4] = 1.;
A[5] = 5.;
A[6] = 1.;
double RHS[5] = { 8., 45., 31., 15., 17. };

do_symbolic_factorization(ma27, N, NZ, IRN, ICN);
do_numeric_factorization(ma27, N, NZ, IRN, ICN, A);
do_backsolve(ma27, N, RHS);
free_memory(ma27);
free(A);
}

Expand Up @@ -315,29 +315,3 @@ void free_memory(struct MA57_struct* ma57) {
}
free(ma57);
}

int main() {

struct MA57_struct* ma57 = new_MA57_struct();

printf("ICNTL[0]: %i\n", get_icntl(ma57, 0));
printf("ICNTL[1]: %i\n", get_icntl(ma57, 1));
printf("ICNTL[2]: %i\n", get_icntl(ma57, 2));
printf("ICNTL[3]: %i\n", get_icntl(ma57, 3));

// Set print level
set_icntl(ma57, 4, 3);
printf("ICNTL[4]: %i\n", get_icntl(ma57, 4));

int N = 5, NE = 7;
int IRN[7] = { 1, 1, 2, 2, 3, 3, 5 };
int JCN[7] = { 1, 2, 3, 5, 3, 4, 5 };
double A[7] = { 2., 3., 4., 6., 1., 5., 1. };
double RHS[5] = { 8., 45., 31., 15., 17. };

do_symbolic_factorization(ma57, N, NE, IRN, JCN);
do_numeric_factorization(ma57, N, NE, A);
do_backsolve(ma57, N, RHS);
free_memory(ma57);
}

0 comments on commit 0b78c7e

Please sign in to comment.