Unverified Commit ee95c8b2 authored by Stefan K's avatar Stefan K Committed by GitHub
Browse files

prefix AMG input files (#632)

parent 5c925e8f
......@@ -39,6 +39,7 @@
* Your parameters to the reserved user space param(170) - param(200)
* Set lelr in SIZE for a restart using muliple files (check value in hdr)
* Use planar_avg() instead of planar_average_z etc.
* Rename AMG input files (example: amg_Aff.dat -> ethier.amgAff.dat)
## Known Bugs
......
......@@ -84,8 +84,8 @@ c
character*132 reafle,fldfle,dmpfle,hisfle,schfle,orefle,nrefle
common /cfiles/ reafle,fldfle,dmpfle,hisfle,schfle,orefle,nrefle
character*132 session,path,re2fle,parfle
common /cfile2/ session,path,re2fle,parfle
character*132 session,path,re2fle,parfle,amgfile
common /cfile2/ session,path,re2fle,parfle,amgfile
integer cr_re2,fh_re2
common /handles_re2/ cr_re2,fh_re2
......
......@@ -97,6 +97,7 @@ c-----------------------------------------------------------------------
ifneknekc = .false.
session = session_mult(0)
path = path_mult(0)
amgfile = session
return
endif
......@@ -128,6 +129,8 @@ c Assign key for splitting into multiple groups
$ nsessions)
endif
amgfile = session
return
end
c---------------------------------------------------------------------
......
......@@ -28,7 +28,8 @@ void crs_xxt_free(struct crs_data *data);
struct crs_data *crs_amg_setup(
uint n, const ulong *id,
uint nz, const uint *Ai, const uint *Aj, const double *A,
uint null_space, const struct comm *comm);
uint null_space, const struct comm *comm,
const char *datafname, uint *ierr);
void crs_amg_solve(double *x, struct crs_data *data, double *b);
void crs_amg_stats(struct crs_data *data);
void crs_amg_free(struct crs_data *data);
......
......@@ -439,15 +439,15 @@ static void read_data(
struct crs_data *const data,
struct array *ids, struct array mats[3],
struct crystal *const cr,
const ulong *uid, const uint uid_n);
const ulong *uid, const uint uid_n, const char *datafname);
static void read_data_mpiio(
struct crs_data *const data,
struct array *ids, struct array mats[3],
struct crystal *const cr,
const ulong *uid, const uint uid_n);
const ulong *uid, const uint uid_n, const char *datafname);
static void amg_setup_aux(struct crs_data *data, uint n, const ulong *id)
static void amg_setup_aux(struct crs_data *data, uint n, const ulong *id, const char *datafname)
{
struct crystal cr;
struct array uid; uint *id_perm;
......@@ -463,9 +463,9 @@ static void amg_setup_aux(struct crs_data *data, uint n, const ulong *id)
sarray_permute(uint ,data->umap,uid.n, cr.data.ptr, &max_e);
#ifdef USEMPIIO
read_data_mpiio(data, &ids, mat, &cr, uid.ptr,uid.n);
read_data_mpiio(data, &ids, mat, &cr, uid.ptr,uid.n, datafname);
#else
read_data(data, &ids, mat, &cr, uid.ptr,uid.n);
read_data(data, &ids, mat, &cr, uid.ptr,uid.n, datafname);
#endif
/* we should have data for every uid;
......@@ -525,12 +525,12 @@ static void amg_setup_aux(struct crs_data *data, uint n, const ulong *id)
static void amg_dump(
uint n, const ulong *id,
uint nz, const uint *Ai, const uint *Aj, const double *A,
struct crs_data *data);
struct crs_data *data, const char *datafname);
struct crs_data *crs_setup(
uint n, const ulong *id,
uint nz, const uint *Ai, const uint *Aj, const double *A,
uint null_space, const struct comm *comm)
uint null_space, const struct comm *comm, const char *datafname, uint *ierr)
{
struct crs_data *data = tmalloc(struct crs_data,1);
struct stat info;
......@@ -538,31 +538,40 @@ struct crs_data *crs_setup(
comm_dup(&data->comm,comm);
dump = 0;
if(data->comm.id==0) {
dump = 0;
if(stat("amg.dat" ,&info)!=0) dump++;
if(stat("amg_W.dat" ,&info)!=0) dump++;
if(stat("amg_AfP.dat",&info)!=0) dump++;
if(stat("amg_Aff.dat",&info)!=0) dump++;
char str1[132];
char str2[132];
char str3[132];
char str4[132];
sprintf(str1,"%s.amg.dat",datafname);
sprintf(str2,"%s.amg_W.dat",datafname);
sprintf(str3,"%s.amg_AfP.dat",datafname);
sprintf(str4,"%s.amg_Aff.dat",datafname);
if(stat(str1,&info)!=0) dump++;
if(stat(str2,&info)!=0) dump++;
if(stat(str3,&info)!=0) dump++;
if(stat(str4,&info)!=0) dump++;
if(dump!=0) printf("AMG files not found, dumping data ...\n"), fflush(stdout);
}
comm_bcast(&data->comm,&dump,sizeof(int),0);
comm_bcast(&data->comm,&dump,sizeof(int),0);
data->gs_top = gs_setup((const slong*)id,n, &data->comm, 1,
dump?gs_crystal_router:gs_auto, !dump);
if(dump) {
amg_dump(n,id,nz,Ai,Aj,A,data);
amg_dump(n,id,nz,Ai,Aj,A,data,datafname);
gs_free(data->gs_top);
if(data->comm.id==0) printf("AMG dump successful\n"), fflush(stdout);
comm_barrier(&data->comm);
comm_free(&data->comm);
free(data);
die(0);
*ierr=1;
} else {
data->null_space = null_space;
amg_setup_aux(data, n,id);
amg_setup_aux(data, n,id, datafname);
*ierr=0;
}
return data;
}
......@@ -752,7 +761,7 @@ static void read_data(
struct crs_data *const data,
struct array *ids, struct array mat[3],
struct crystal *const cr,
const ulong *uid, const uint uid_n)
const ulong *uid, const uint uid_n, const char *datafname)
{
int code;
struct find_id_data fid;
......@@ -769,17 +778,25 @@ static void read_data(
find_id_setup(&fid, uid,uid_n, cr);
code=0;
if(pid==0) {
f = dopen("amg.dat",'r',&code);
fm[0] = dopen("amg_W.dat",'r',&code);
fm[1] = dopen("amg_AfP.dat",'r',&code);
fm[2] = dopen("amg_Aff.dat",'r',&code);
if(code==0) {
array_init(double, &read_buffer, 6*AMG_BLOCK_ROWS);
row_lens = tmalloc(uint, 5*AMG_BLOCK_ROWS);
id_proc = row_lens + 3*AMG_BLOCK_ROWS;
id_perm = id_proc + AMG_BLOCK_ROWS;
array_reserve(struct id_data, &id_buffer, AMG_BLOCK_ROWS);
}
char str1[132];
char str2[132];
char str3[132];
char str4[132];
sprintf(str1,"%s.amg.dat",datafname);
sprintf(str2,"%s.amg_W.dat",datafname);
sprintf(str3,"%s.amg_AfP.dat",datafname);
sprintf(str4,"%s.amg_Aff.dat",datafname);
f = dopen(str1,'r',&code);
fm[0] = dopen(str2,'r',&code);
fm[1] = dopen(str3,'r',&code);
fm[2] = dopen(str4,'r',&code);
if(code==0) {
array_init(double, &read_buffer, 6*AMG_BLOCK_ROWS);
row_lens = tmalloc(uint, 5*AMG_BLOCK_ROWS);
id_proc = row_lens + 3*AMG_BLOCK_ROWS;
id_perm = id_proc + AMG_BLOCK_ROWS;
array_reserve(struct id_data, &id_buffer, AMG_BLOCK_ROWS);
}
}
comm_bcast(&data->comm,&code,sizeof(int),0);
if(code!=0) die(1);
......@@ -880,7 +897,7 @@ static void read_data(
static void read_data_mpiio(struct crs_data *const data,
struct array *ids, struct array mat[3],
struct crystal *const cr,
const ulong *uid, const uint uid_n)
const ulong *uid, const uint uid_n, const char *datafname)
{
int code;
struct find_id_data fid;
......@@ -915,10 +932,18 @@ static void read_data_mpiio(struct crs_data *const data,
struct sfile fs = {0,0};
struct sfile fsm[3] = {{0,0},{0,0},{0,0}};
fs = dopen_mpi("amg.dat" ,'r', &data->comm, &code);
fsm[0] = dopen_mpi("amg_W.dat" ,'r', &data->comm, &code);
fsm[1] = dopen_mpi("amg_AfP.dat",'r', &data->comm, &code);
fsm[2] = dopen_mpi("amg_Aff.dat",'r', &data->comm, &code);
char str1[132];
char str2[132];
char str3[132];
char str4[132];
sprintf(str1,"%s.amg.dat",datafname);
sprintf(str2,"%s.amg_W.dat",datafname);
sprintf(str3,"%s.amg_AfP.dat",datafname);
sprintf(str4,"%s.amg_Aff.dat",datafname);
fs = dopen_mpi(str1,'r', &data->comm, &code);
fsm[0] = dopen_mpi(str2,'r', &data->comm, &code);
fsm[1] = dopen_mpi(str3,'r', &data->comm, &code);
fsm[2] = dopen_mpi(str4,'r', &data->comm, &code);
code = comm_reduce_int(&data->comm, gs_max, &code, 1);
if(code != 0)
die(1);
......@@ -1207,7 +1232,7 @@ static uint dump_matrix_setdata(
static void dump_matrix(
struct array *const mat, const ulong *const uid,
struct crystal *const cr)
struct crystal *const cr, const char *datafname)
{
const struct comm *comm = &cr->comm;
const uint pid = comm->id, np = comm->np;
......@@ -1220,9 +1245,15 @@ static void dump_matrix(
code = 0;
if(pid==0) {
fi=dopen("amgdmp_i.dat",'w',&code);
fj=dopen("amgdmp_j.dat",'w',&code);
fp=dopen("amgdmp_p.dat",'w',&code);
char str1[132];
char str2[132];
char str3[132];
sprintf(str1,"%s.amgdmp_i.dat",datafname);
sprintf(str2,"%s.amgdmp_j.dat",datafname);
sprintf(str3,"%s.amgdmp_p.dat",datafname);
fi=dopen(str1,'w',&code);
fj=dopen(str2,'w',&code);
fp=dopen(str3,'w',&code);
}
comm_bcast(comm,&code,sizeof(int),0);
if(code!=0) die(1);
......@@ -1258,7 +1289,7 @@ static void dump_matrix(
static void amg_dump(
uint n, const ulong *id,
uint nz, const uint *Ai, const uint *Aj, const double *A,
struct crs_data *data)
struct crs_data *data, const char *datafname)
{
struct crystal cr;
struct array uid; struct rid *rid_map = tmalloc(struct rid,n);
......@@ -1279,7 +1310,7 @@ static void amg_dump(
mat.n = out-(struct rnz*)mat.ptr;
free(rid_map);
dump_matrix(&mat,uid.ptr,&cr);
dump_matrix(&mat,uid.ptr,&cr,datafname);
array_free(&uid);
crystal_free(&cr);
......
......@@ -45,7 +45,8 @@ while(0)
void fcrs_setup(sint *handle, const sint *sid, const MPI_Fint *comm, const sint *np,
const sint *n, const slong id[], const sint *nz,
const sint Ai[], const sint Aj[], const double A[],
const sint *null_space, const double *param)
const sint *null_space, const double *param,
const char *datafname, uint *ierr)
{
struct comm c;
if(handle_n==handle_max)
......@@ -62,7 +63,8 @@ void fcrs_setup(sint *handle, const sint *sid, const MPI_Fint *comm, const sint
*null_space,&c); break;
case 1: handle_array[handle_n]=ccrs_amg_setup(*n,(const ulong*)id,
*nz,(const uint*)Ai,(const uint*)Aj,A,
*null_space,&c); break;
*null_space,&c,
datafname,ierr); break;
case 2: handle_array[handle_n]=ccrs_hypre_setup(*n,(const ulong*)id,
*nz,(const uint*)Ai,(const uint*)Aj,A,
*null_space,&c,param); break;
......
......@@ -113,6 +113,10 @@ c
common /scrmgx/ w1(lx1*ly1*lz1*lelv),w2(lx1*ly1*lz1*lelv)
integer*8 ngv
character*132 amgfile_c
character*1 fname1(132)
equivalence (fname1,amgfile_c)
integer nnamg
t0 = dnekclock()
......@@ -203,8 +207,20 @@ c endif
nz=ncr*ncr*nelv
isolver = param(40)
call blank(fname1,132)
lamgn = ltrunc(amgfile,len(amgfile))
call chcopy(fname1,amgfile,lamgn)
call chcopy(fname1(lamgn+1),char(0),1)
ierr = 0
call fgslib_crs_setup(xxth(ifield),isolver,nekcomm,mp,ntot,
$ se_to_gcrs,nz,ia,ja,a, null_space, crs_param)
$ se_to_gcrs,nz,ia,ja,a, null_space, crs_param,
$ amgfile_c,ierr)
ierr = iglmax(ierr,1)
if (ifneknek) ierr = iglmax_ms(ierr,1)
if (ierr.eq.1) then
call exitt
endif
t0 = dnekclock()-t0
if (nio.eq.0) then
......
......@@ -26,6 +26,13 @@ int main(int argc, char *argv[])
int coars_strat, interp_strat, ret;
setbuf(stdout, NULL);
char sname[132];
char session[132];
printf("Enter the name of mesh file:\n");
fgets(sname, sizeof sname, stdin);
ret = sscanf(sname,"%s",&session);
if (ret == -1) exit(1);
/* Coarsening strategy */
printf("Choose a coarsening method. Available options are:\n");
//printf(" - 0: CLJP,\n");
......@@ -85,24 +92,29 @@ int main(int argc, char *argv[])
printf("ERRORr: Smoother tolerance should be >0.\n");
exit(1);
}
/* Verbose level */
int print_level = 3; // Print solve info + parameters
/* Read data and convert rows and columns to integers */
printf("Reading AMG dump files... ");
int n = filesize("amgdmp_i.dat");
char str1[100],str2[100],str3[100];
sprintf(str1,"%s.amgdmp_i.dat",session);
sprintf(str2,"%s.amgdmp_j.dat",session);
sprintf(str3,"%s.amgdmp_p.dat",session);
int n = filesize(str1);
double *v = malloc( n * sizeof(double));
double *Aid = malloc((n-1) * sizeof(double));
double *Ajd = malloc((n-1) * sizeof(double));
double *Av = malloc((n-1) * sizeof(double));
readfile(v,n,"amgdmp_i.dat");
readfile(v,n,str1);
memcpy(Aid, v+1, (n-1) * sizeof (double));
readfile(v,n,"amgdmp_j.dat");
readfile(v,n,str2);
memcpy(Ajd, v+1, (n-1) * sizeof (double));
readfile(v,n,"amgdmp_p.dat");
readfile(v,n,str3);
memcpy(Av , v+1, (n-1) * sizeof (double));
printf("Done.\n");
......@@ -435,7 +447,7 @@ int main(int argc, char *argv[])
}
printf("Setup finished... Exporting data.\n");
amg_export(data);
amg_export(data,session);
/* Destroy matrix ij */
HYPRE_IJMatrixDestroy(ij_matrix);
......@@ -528,7 +540,7 @@ static void sub_mat(hypre_CSRMatrix **subA, const hypre_CSRMatrix *A,
/*
Export data from the AMG setup to correct format.
*/
static void amg_export(const struct amg_setup_data *data)
static void amg_export(const struct amg_setup_data *data,char *session)
{
int nlevels = data->nlevels;
int n = data->n[0];
......@@ -574,20 +586,25 @@ static void amg_export(const struct amg_setup_data *data)
}
/* Save matrices */
char str1[132],str2[132],str3[132],str4[132];
sprintf(str1,"%s.amg_W.dat",session);
sprintf(str2,"%s.amg_AfP.dat",session);
sprintf(str3,"%s.amg_Aff.dat",session);
sprintf(str4,"%s.amg.dat",session);
int *W_len = malloc(n * sizeof (int));
savemats(W_len, n, nlevels-1, lvl, data->idc, data->id_l2g, data->W,
"amg_W.dat");
str1);
int *AfP_len = malloc(n * sizeof (int));
savemats(AfP_len, n, nlevels-1, lvl, data->idc, data->id_l2g, data->AfP,
"amg_AfP.dat");
str2);
int *Aff_len = malloc(n * sizeof (int));
savemats(Aff_len, n, nlevels-1, lvl, data->idf, data->id_l2g, data->Af,
"amg_Aff.dat");
str3);
/* Save vector */
savevec(nlevels, data, n, lvl, W_len, AfP_len, Aff_len, dvec, "amg.dat");
savevec(nlevels, data, n, lvl, W_len, AfP_len, Aff_len, dvec,str4);
/* Free allocated memory */
free(W_len);
......
......@@ -224,7 +224,7 @@ static void ar_scal_op(double *a, const double scal, const int n,
INPUT:
- structure data
*/
static void amg_export(const struct amg_setup_data *data);
static void amg_export(const struct amg_setup_data *data,char *session);
/*
Save matrices
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment