#include	<stdio.h>
#include	<math.h>
#include	"bsp.h"
#define		SQRT(X)	        ((int)ceil(sqrt((double) (X))))
#define		SQRT_F(X)	((int)floor(sqrt((double) (X))))
#define         CEIL(X,Y)       ((X != 0)?(1+ (X-1)/Y):0)  
#define         FLOOR(X,Y)      (X/Y)  
#define         LEFT(x,y)       (x-(x/y)*y)

/* From cho_seq.c */
void    cholesky(double *mat, int n,int limit);


/* From collect_a_matrix.c */
void collect_alternating_columns(double *mat,double *mat1,int n);
void collect_alternating_column_submatrix(double *mat,double *mat1,
                                          int rr,int n);
/* From collect_b_matrix.c */
void collect_block_matrix(double *mat,double *mat1,int n,int pi,int pj);
void collect_blocked_matrix(double *mat,double *mat1,int n,int pi,int pj);
void collect_block_columns(double *mat,double *mat1,int n);
void collect_block_column(double *mat,double *mat1,int rr,int n);
void collect_block_column_submatrix(double *mat,double *mat1,int rr,int n);

/* From collect_c_matrix.c */
void collect_contiguous_columns(double *mat,double *mat1,int n);

/* From collect_matrix.c   */
   /* Contains subset of current functions. Split into multiple files */


/* From distribute_b_matrix.c */
void distribute_block_matrix(double *mat,double *mat1,int n,int pi,int pj);
void distribute_blocked_matrix(double *mat,double *mat1,int n,int pi,int pj);


/* From error_log.c        */
void check_if_null_file(FILE *x,char *s,char *t);
void check_if_null(void *x,char *s,char *t);
void check_if_valid(int x,int y, char *s,char *t);


/* From fill_matrix.c	   */
void fill_matrix(char *file_name,double *mat,int n);


/* From g_brd.c		   */
void bsp_M_mbroadcast(int fromp,int multi,int d,char *from,char *to,
                      int nbytes,int p_sqrt,int step,int basep);
void bsp_M_2_mbroadcast(int fromp, int multi,char *from,char *to,
                       int nbytes,int p_sqrt,int step,int basep);


/* From generate_matrix.c  */
void generate_matrix(char *file_name,int n);
void generate_internal_matrix(double **mat_r,int n);


/* From init_{abc}_matrix.c */
void init_alternating_columns(double **mat_r,int n);

void init_block(double **mat_r,int n,int pi, int pj);
void init_block_1(double **mat_r,int n);
void init_blocked(double **mat_r,int n,int pi,int pj,int option);

void init_contiguous_columns(double **mat_r,int n);


/* From init_seq_matrix.c */
void init_seq1(double **mat_r,int n);
void init_seq(double **mat_r,int n);


/* From mul_seq.c */
void transpose(double *a, double *b, int n);
void mult(double *a,double *b, double *c, int n);


/* From print_matrix.c	  */
void print_mat_file(char *file_name,double *mat,int n, char *s);
void print_mat(double *mat,int n, int debug,char *s);

void print_mat2(double *mat,int n, int m, int debug,char *s);
void print_mat3(double *mat,int n, int m, int nn, int debug,char *s);
void print_mat4(double *mat,int n, int m, int nn, int debug,char *s);
void print_columns(double *mat,int n, int debug,int limit,char *s);
