@PROBLEM sparse_direct_solve
@INCLUDE <math.h>
@FUNCTION netsolve_sparse_direct_solve
@DASHI $(MPI_INCLUDE_DIR)
@DASHI $(NETSOLVE_ROOT)/src/SampleNumericalSoftware/SparseSolvers/sparse
@DASHI $(NETSOLVE_ROOT)/src/SampleNumericalSoftware/SparseSolvers/sparse/aux
@DASHI $(NETSOLVE_ROOT)/src/SampleNumericalSoftware/SparseSolvers/sparse/driver
@INCLUDE "mpi.h"
@INCLUDE "direct.h"
@INCLUDE "ma28/netsolve_ma28.h"
@INCLUDE "superlu/netsolve_superlu.h"
@INCLUDE "parallel_auxs.h"
@INCLUDE "matrix_auxs.h"
@INCLUDE "matrix_distr_auxs.h"
@LIB -lm
@LIB -L$(NETSOLVE_ROOT)/lib/$(NETSOLVE_ARCH)
@LIB -lnetsolve_ma28
@LIB -lnetsolve_superlu_serial
@LIB -lnetsolve_aux
@LIB -lnetsolve_direct_driver
@LIB -lnetsolve_tester
@LIB $(LIBDIR)/libma28.a
@LIB $(SUPERLU_LIB_LINK)
@LIB $(LAPACK_LIB_LINK)
@LIB $(BLAS_LIB_LINK)
@LIB -L$(MPI_DIR)/lib
@LIB -lmpich

@FUNCTION netsolve_sparse_direct_solve
@LANGUAGE C
@MAJOR ROW
@PATH /SuperLU-MA28/
@COMPLEXITY 3,2
@DESCRIPTION
netsolve direct solve using ma28 and superlu

@INPUT 5
@OBJECT STRING package
MA28 or SUPERLU
@OBJECT SPARSEMATRIX D sm
the sparse matrix
@OBJECT VECTOR D rhs_vector
the right-hand-side vector
@OBJECT SCALAR D pivot
pivot value
@OBJECT SCALAR I permutation
permutation

@OUTPUT 1
@OBJECT VECTOR D sol_vector
solution vector

@CALLINGSEQUENCE
@ARG I0
@ARG mI1, nI1, mI2
@ARG fI1
@ARG I1
@ARG iI1
@ARG pI1
@ARG I2
@ARG I3
@ARG I4
@ARG O0

@CODE
extern int netsolve_sparse_direct_solve();
extern int ma28_params();
extern int superlu_params();

MPI_Comm comm;
int ierr;
int package;
int Argc = 1;
char **Args;
int local_size;
int first;
int mytid, ntids;
direct_info_block info=0;

  Args = (char**)calloc(1,sizeof(char*));
  Args[0] = strdup("dummy");
  if(strcmp(@I0@,"MA28") == 0){
    package = 4;
    ierr = ma28_params(&info,*@I3@);
  }
  else if(strcmp(@I0@,"SUPERLU") == 0){
    package = 3;
    ierr = superlu_params(&info,*@I4@);
  }
  else
     return NS_PROT_BAD_VALUES;

  if(@pI1@[0] == 1)
    ierr = crs_mat_tobase0(@I1@, @iI1@, @pI1@, *@mI1@);

  first = 0;
  local_size = (*@mI1@ > 1) ? *@mI1@ : 1;
  @O0@ = (double*)malloc(local_size*sizeof(double));

  /* debug */
   /*printf("package: %d\\n", package);
   printf("local size: %d\\n", local_size);
  printf("values:\\n");
  for(i=0;i<*@fI1@;i++)
   printf("%lf   ",@I1@[i]);
  printf("\\n");
  printf("indices:\n\n");
  for(i=0;i<*@fI1@;i++)
   printf("%d   ", @iI1@[i]);
  printf("\\n");
  printf("ptrs:\\n");
  for(i=0;i<*@mI1@+1;i++)
    printf("%d   ", @pI1@[i]);
  printf("\\n");
  printf("rhs:\\n");
  for(i=0;i<*@mI1@;i++)
    printf("%lf   ", @I2@[i]);
  printf("\\n");
    printf("rtol: %lf\\n", *@I3@);
    printf("maxit:%d\\n", *@I4@); */
  /* debug */

   MPI_Init(&Argc,&Args);
   comm = MPI_COMM_WORLD;
   MPI_Comm_size(comm,&ntids);
   MPI_Comm_rank(comm,&mytid);

   /* debug */
   /*printf("ntids:%d mytid:%d\\n", ntids, mytid); */
   /* debug */

  ierr = netsolve_sparse_direct_solve
        (package,Argc,Args,comm, first,local_size,0,
         @I1@, @iI1@, @pI1@,  info, @I2@, @O0@);
  *@mO0@ = local_size;

  /*printf("results:\\n");
  for(i=0;i<*@mI1@;i++)
    printf("%lf   ",@O0@[i]);
  printf("\\n"); */

    MPI_Finalize();



@END_CODE
