#include "pargrid.h"

/*+ main - the main routine for this grid program

     Input Parameters:
     argc, argv - the usual
     argv[1] - the number of points in each direction of the global grid
               do not use less than 2 points per processor
     argv[2] - the type of stencil (5 or 9)

     To Run, see tools.

     Notes: The grid program solves a linear system associated with
            a 2-D grid distributed across the processors.  The 2-D
            grid is partitioned in both dimensions amongst the
            processors.  The number of processors *must* be the
            square of an integer, e.g., 9 but not 8.

 +*/

int main(int argc, char **argv)
{
	par_grid grid;
	BSprocinfo *procinfo;
	double	dbl;

	/* Call BSinit() to initialize BlocklSolve and MPI */
    BSinit(&argc,&argv);

	/* set up the context for BlockSolve */
	procinfo = BScreate_ctx(); CHKERRN(0);
	/* tell it that this matrix has no i-nodes or cliques */
	BSctx_set_si(procinfo,TRUE); CHKERRN(0);
	/* tell it to print out some information on the reordering */
	BSctx_set_pr(procinfo,TRUE); CHKERRN(0);
	BSctx_set_scaling(procinfo,TRUE); CHKERRN(0);
	BSctx_set_num_rhs(procinfo,1); CHKERRN(0);
	BSctx_set_pre(procinfo,PRE_ICC); CHKERRN(0);
	grid.icc_storage = TRUE;
	grid.symmetric = TRUE;
	grid.ncomp = 1;
	grid.positive = FALSE;

	if(procinfo->my_id==0) {
		printf("\n");
		printf("************** Blocksolve Example Grid3 *******************\n");
	}

	/* read in grid parameters */
	if (argc < 2) {
		SETERRC(ARG_ERR,"Argument list not correct size\n");
		return -1;
	}
	dbl = procinfo->nprocs;
	grid.worker_x = (int)sqrt(dbl);
	grid.worker_y = grid.worker_x;
    grid.worker_z = 1;
	if (procinfo->my_id == 0) {
		printf("o  Number of workers (x,y): %d %d\n",
			grid.worker_x,grid.worker_y);
	}
	if (procinfo->nprocs != grid.worker_x*grid.worker_y*grid.worker_z) {
		SETERRC(ARG_ERR,"Number of processors is not correct\n");
		return -1;
	}
	sscanf(argv[1],"%d",&grid.num_x);
	grid.num_y = grid.num_x;
	grid.num_z = 1;
	grid.l_num_x = grid.num_x / grid.worker_x;
	grid.l_num_y = grid.num_y / grid.worker_y;
	grid.l_num_z = grid.num_z;

	/* local grid size and type */
	sscanf(argv[2],"%d",&grid.type);
	if (procinfo->my_id == 0) {
		printf("o  Grid type = %d point stencil\n",grid.type);
	}

	if (procinfo->my_id == 0) {
		printf("o  Discretizations (x,y): %d %d\n",
			grid.num_x,grid.num_y);
	}

	/* call the worker */
	worker(&grid,procinfo); 

	if(procinfo->my_id==0) {
		printf("************ End Blocksolve Example Grid3 *****************\n");
		printf("\n");
	}

	/* print logging if enabled */
	BSprint_log(procinfo); CHKERRN(0);

	/* free the context */
	BSfree_ctx(procinfo); CHKERRN(0);

	/* finalize BlockSolve and MPI */
	BSfinalize();

	exit(0);
}


syntax highlighted by Code2HTML, v. 0.9.1