Skip to content

Commit

Permalink
Fix row_max_abs_value() in RAJA implementation (#225)
Browse files Browse the repository at this point in the history
* fix function row_max_abs_value

* use latest spack env on ascent

* add user option to control if MDS_ex4 has empty sparse row in constraint Jacobian

* add new unit test according to MDS_ex4 with empty sparse row in constraint Jacobian

Co-authored-by: Nai-Yuan Chiang <[email protected]>
Co-authored-by: Chiang <[email protected]>
  • Loading branch information
3 people authored May 6, 2021
1 parent 3fcb788 commit c0394af
Show file tree
Hide file tree
Showing 11 changed files with 171 additions and 99 deletions.
22 changes: 13 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,18 @@ if (HIOP_WITH_MAKETEST)
add_test(NAME NlpMixedDenseSparse4_2 COMMAND ${RUNCMD} bash -c "$<TARGET_FILE:nlpMDS_ex4.exe> 400 100 1 -selfcheck \
| ${STRIP_TABLE_CMD} \
| tee ${PROJECT_BINARY_DIR}/mds4_2.out")

add_test(NAME NlpMixedDenseSparse4_3 COMMAND ${RUNCMD} "$<TARGET_FILE:nlpMDS_ex4.exe>" "400" "100" "0" "-empty_sp_row" "-selfcheck")

if(HIOP_USE_RAJA)
add_test(NAME NlpMixedDenseSparseRaja4_1 COMMAND ${RUNCMD} bash -c "$<TARGET_FILE:nlpMDS_ex4_raja.exe> 400 100 0 -selfcheck \
| ${STRIP_TABLE_CMD} \
| tee ${PROJECT_BINARY_DIR}/mds4_raja_1.out")
add_test(NAME NlpMixedDenseSparseRaja4_2 COMMAND ${RUNCMD} bash -c "$<TARGET_FILE:nlpMDS_ex4_raja.exe> 400 100 1 -selfcheck \
| ${STRIP_TABLE_CMD} \
| tee ${PROJECT_BINARY_DIR}/mds4_raja_2.out")

add_test(NAME NlpMixedDenseSparseRaja4_3 COMMAND ${RUNCMD} bash -c "$<TARGET_FILE:nlpMDS_ex4_raja.exe> 400 100 0 -empty_sp_row -selfcheck")

if(HIOP_DEEPCHECKS)
foreach(iter 1 2)
add_test(
Expand All @@ -428,14 +432,14 @@ if (HIOP_WITH_MAKETEST)
echo 'Output tables have a different number of iterations!'
exit 1
fi")
add_test(
NAME "CompareExample4_ElementWise_${iter}"
COMMAND bash -c "\
join ${PROJECT_BINARY_DIR}/mds4_${iter}.out ${PROJECT_BINARY_DIR}/mds4_raja_${iter}.out \
| ${PROJECT_SOURCE_DIR}/tests/testEx4CompareIterations.awk")
endforeach()
endif(HIOP_DEEPCHECKS)
endif()
add_test(
NAME "CompareExample4_ElementWise_${iter}"
COMMAND bash -c "\
join ${PROJECT_BINARY_DIR}/mds4_${iter}.out ${PROJECT_BINARY_DIR}/mds4_raja_${iter}.out \
| ${PROJECT_SOURCE_DIR}/tests/testEx4CompareIterations.awk")
endforeach()
endif(HIOP_DEEPCHECKS)
endif()

add_test(NAME NlpMixedDenseSparse5_1 COMMAND ${RUNCMD} "$<TARGET_FILE:nlpMDS_ex5.exe>" "400" "100" "-selfcheck")

Expand Down
26 changes: 11 additions & 15 deletions scripts/ascentVariables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,24 @@ if [ ! -v BUILDDIR ]; then
echo BUILDDIR is not set! Your paths may be misconfigured.
fi

export MY_CLUSTER=ascent
export PROJ_DIR=/gpfs/wolf/proj-shared/csc359
source $PROJ_DIR/src/spack/share/spack/setup-env.sh
module purge
module load cuda/11
module use /gpfs/wolf/proj-shared/csc359/ascent/Modulefiles/Core
module load cuda/10.2.89
module use $PROJ_DIR/$MY_CLUSTER/Modulefiles/Core
module load exasgd-base
module load gcc-ext/7.4.0
module load spectrum-mpi-ext
module load openblas
module use /gpfs/wolf/proj-shared/csc359/ascent/spack-modulefiles/
module load magma-2.5.4-gcc-7.4.0-vjotnd3
module load metis
module load mpfr
module load suitesparse
module load cmake/3.18.2
module load raja
module load umpire
module load valgrind/3.14.0
export MY_RAJA_DIR=$RAJA_ROOT
export MY_UMPIRE_DIR=$UMPIRE_ROOT
export MY_METIS_DIR=$OLCF_METIS_ROOT
export MY_HIOP_MAGMA_DIR=$MAGMA_ROOT
export MY_UMFPACK_DIR=$SUITESPARSE_ROOT

ls $PROJ_DIR/src/spack/var/spack/environments/*

spack env activate exago-v1-0-0-hiop-v0-4-1

export MY_NVCC_ARCH="sm_70"
export EXTRA_CMAKE_ARGS="$EXTRA_CMAKE_ARGS -DHIOP_NVCC_ARCH=$MY_NVCC_ARCH"

if [[ ! -f $BUILDDIR/nvblas.conf ]]; then
cat > $BUILDDIR/nvblas.conf <<EOD
Expand Down
8 changes: 6 additions & 2 deletions src/Drivers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@ target_link_libraries(nlpMDS_ex4.exe hiop)

if(HIOP_USE_RAJA)
if(HIOP_USE_GPU)
set_source_files_properties(nlpMDSForm_raja_ex4.cpp nlpMDS_ex4_raja_driver.cpp PROPERTIES LANGUAGE CUDA)
set_source_files_properties(
nlpMDS_raja_ex4.cpp
nlpMDS_ex4_raja_driver.cpp
PROPERTIES LANGUAGE CUDA
)
endif()
add_executable(nlpMDS_ex4_raja.exe nlpMDS_ex4_raja_driver.cpp nlpMDSForm_raja_ex4.cpp)
add_executable(nlpMDS_ex4_raja.exe nlpMDS_ex4_raja_driver.cpp nlpMDS_raja_ex4.cpp)
target_link_libraries(nlpMDS_ex4_raja.exe hiop)
endif()

Expand Down
2 changes: 1 addition & 1 deletion src/Drivers/hpc_multisolves.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "nlpMDSForm_ex4.hpp"
#include "nlpMDS_ex4.hpp"
#include "hiopNlpFormulation.hpp"
#include "hiopAlgFilterIPM.hpp"

Expand Down
127 changes: 75 additions & 52 deletions src/Drivers/nlpMDSForm_ex4.hpp → src/Drivers/nlpMDS_ex4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
#include <cmath>

/* Problem test for the linear algebra of Mixed Dense-Sparse NLPs
* if 'empty_sp_row' is set to true:
* min sum 0.5 {x_i*(x_{i}-1) : i=1,...,ns} + 0.5 y'*Qd*y + 0.5 s^T s
* s.t. x+s + Md y = 0, i=1,...,ns
* [-2 ] [ x_1 + e^T s] [e^T] [ 2 ]
* [-inf] <= [ ] + [e^T] y <= [ 2 ]
* [-2 ] [ x_3 ] [e^T] [inf]
* x <= 3
* s>=0
* -4 <=y_1 <=4, the rest of y are free
* otherwise:
* min sum 0.5 {x_i*(x_{i}-1) : i=1,...,ns} + 0.5 y'*Qd*y + 0.5 s^T s
* s.t. x+s + Md y = 0, i=1,...,ns
* [-2 ] [ x_1 + e^T s] [e^T] [ 2 ]
Expand All @@ -43,21 +53,20 @@
class Ex4 : public hiop::hiopInterfaceMDS
{
public:
Ex4(int ns_)
: Ex4(ns_, ns_)
Ex4(int ns_, bool empty_sp_row = false)
: Ex4(ns_, ns_, empty_sp_row)
{
}

Ex4(int ns_, int nd_)
: ns(ns_), sol_x_(NULL), sol_zl_(NULL), sol_zu_(NULL), sol_lambda_(NULL)
Ex4(int ns_, int nd_, bool empty_sp_row = false)
: ns(ns_), sol_x_(NULL), sol_zl_(NULL), sol_zu_(NULL), sol_lambda_(NULL), empty_sp_row_(empty_sp_row)
{
if(ns<0) {
ns = 0;
} else {
if(4*(ns/4) != ns) {
ns = 4*((4+ns)/4);
printf("[warning] number (%d) of sparse vars is not a multiple ->was altered to %d\n",
ns_, ns);
ns = 4*((4+ns)/4);
printf("[warning] number (%d) of sparse vars is not a multiple ->was altered to %d\n", ns_, ns);
}
}

Expand Down Expand Up @@ -154,7 +163,11 @@ class Ex4 : public hiop::hiopInterfaceMDS
nx_sparse = 2*ns;
nx_dense = nd;
nnz_sparse_Jace = 2*ns;
nnz_sparse_Jaci = (ns==0 || !haveIneq) ? 0 : 3+ns;
if(empty_sp_row_) {
nnz_sparse_Jaci = (ns==0 || !haveIneq) ? 0 : 2+ns;
} else {
nnz_sparse_Jaci = (ns==0 || !haveIneq) ? 0 : 3+ns;
}
nnz_sparse_Hess_Lagr_SS = 2*ns;
nnz_sparse_Hess_Lagr_SD = 0.;
return true;
Expand Down Expand Up @@ -196,25 +209,28 @@ class Ex4 : public hiop::hiopInterfaceMDS
for(int irow=0; irow<num_cons; irow++) {
const int con_idx = (int) idx_cons[irow];
if(con_idx<ns) {
//equalities: x+s - Md y = 0
cons[con_idx] = x[con_idx] + s[con_idx];
isEq=true;
//equalities: x+s - Md y = 0
cons[con_idx] = x[con_idx] + s[con_idx];
isEq=true;
} else if(haveIneq) {
assert(con_idx<ns+3);
//inequality
const int conineq_idx=con_idx-ns;
if(conineq_idx==0) {
cons[conineq_idx] = x[0];
for(int i=0; i<ns; i++) cons[conineq_idx] += s[i];
for(int i=0; i<nd; i++) cons[conineq_idx] += y[i];

} else if(conineq_idx==1) {
cons[conineq_idx] = x[1];
for(int i=0; i<nd; i++) cons[conineq_idx] += y[i];
} else if(conineq_idx==2) {
cons[conineq_idx] = x[2];
for(int i=0; i<nd; i++) cons[conineq_idx] += y[i];
} else { assert(false); }
assert(con_idx<ns+3);
//inequality
const int conineq_idx=con_idx-ns;
if(conineq_idx==0) {
cons[conineq_idx] = x[0];
for(int i=0; i<ns; i++) cons[conineq_idx] += s[i];
for(int i=0; i<nd; i++) cons[conineq_idx] += y[i];
} else if(conineq_idx==1) {
if(empty_sp_row_) {
cons[conineq_idx] = 0.0;
} else {
cons[conineq_idx] = x[1];
}
for(int i=0; i<nd; i++) cons[conineq_idx] += y[i];
} else if(conineq_idx==2) {
cons[conineq_idx] = x[2];
for(int i=0; i<nd; i++) cons[conineq_idx] += y[i];
} else { assert(false); }
}
}
if(isEq) {
Expand Down Expand Up @@ -284,7 +300,7 @@ class Ex4 : public hiop::hiopInterfaceMDS
nnzit++;
}
} else {
if( (con_idx-ns==1 || con_idx-ns==2) && ns>0 ) {
if(((con_idx-ns==1 && !empty_sp_row_) || con_idx-ns==2) && ns>0) {
//w.r.t x_2 or x_3
iJacS[nnzit] = con_idx-ns;
jJacS[nnzit] = con_idx-ns;
Expand Down Expand Up @@ -322,7 +338,7 @@ class Ex4 : public hiop::hiopInterfaceMDS
nnzit++;
}
} else {
if( (con_idx-ns==1 || con_idx-ns==2) && ns>0) {
if(((con_idx-ns==1 && !empty_sp_row_) || con_idx-ns==2) && ns>0) {
//w.r.t x_2 or x_3
MJacS[nnzit] = 1.;
nnzit++;
Expand Down Expand Up @@ -470,18 +486,21 @@ class Ex4 : public hiop::hiopInterfaceMDS
double* sol_zl_;
double* sol_zu_;
double* sol_lambda_;

/* indicate if problem has empty row in constraint Jacobian */
bool empty_sp_row_;
};

class Ex4OneCallCons : public Ex4
{
public:
Ex4OneCallCons(int ns_in)
: Ex4(ns_in)
Ex4OneCallCons(int ns_in, bool empty_sp_row = false)
: Ex4(ns_in, empty_sp_row)
{
}

Ex4OneCallCons(int ns_in, int nd_in)
: Ex4(ns_in, nd_in)
Ex4OneCallCons(int ns_in, int nd_in, bool empty_sp_row = false)
: Ex4(ns_in, nd_in, empty_sp_row)
{
}

Expand All @@ -506,23 +525,27 @@ class Ex4OneCallCons : public Ex4

for(int con_idx=0; con_idx<m; ++con_idx) {
if(con_idx<ns) {
//equalities
cons[con_idx] = x[con_idx]+s[con_idx];
//equalities
cons[con_idx] = x[con_idx]+s[con_idx];
} else if(haveIneq) {
//inequalties
assert(con_idx<ns+3);
if(con_idx==ns) {
cons[con_idx] = x[0];
for(int i=0; i<ns; i++) cons[con_idx] += s[i];
for(int i=0; i<nd; i++) cons[con_idx] += y[i];

} else if(con_idx==ns+1) {
cons[con_idx] = x[1];
for(int i=0; i<nd; i++) cons[con_idx] += y[i];
} else if(con_idx==ns+2) {
cons[con_idx] = x[2];
for(int i=0; i<nd; i++) cons[con_idx] += y[i];
} else { assert(false); }
//inequalties
assert(con_idx<ns+3);
if(con_idx==ns) {
cons[con_idx] = x[0];
for(int i=0; i<ns; i++) cons[con_idx] += s[i];
for(int i=0; i<nd; i++) cons[con_idx] += y[i];

} else if(con_idx==ns+1) {
if(empty_sp_row_) {
cons[con_idx] = 0.0;
} else {
cons[con_idx] = x[1];
}
for(int i=0; i<nd; i++) cons[con_idx] += y[i];
} else if(con_idx==ns+2) {
cons[con_idx] = x[2];
for(int i=0; i<nd; i++) cons[con_idx] += y[i];
} else { assert(false); }
}
}

Expand Down Expand Up @@ -583,12 +606,12 @@ class Ex4OneCallCons : public Ex4
nnzit++;
}
} else {
if(con_idx-ns==1 || con_idx-ns==2) {
if( (con_idx-ns==1 && !empty_sp_row_) || con_idx-ns==2 ) {
//w.r.t x_2 or x_3
iJacS[nnzit] = con_idx;
jJacS[nnzit] = con_idx-ns;
nnzit++;
} else { assert(false); }
}
}
}
}
Expand Down Expand Up @@ -622,11 +645,11 @@ class Ex4OneCallCons : public Ex4
nnzit++;
}
} else {
if(con_idx-ns==1 || con_idx-ns==2) {
if( (con_idx-ns==1 && !empty_sp_row_) || con_idx-ns==2 ) {
//w.r.t x_2 or x_3
MJacS[nnzit] = 1.;
nnzit++;
} else { assert(false); }
}
}
}
}
Expand Down
Loading

0 comments on commit c0394af

Please sign in to comment.