7 return [complex(x)
for x
in a]
11 if a ==
int(a):
return `
int(a)`
15 if a == 0:
return "0i" 16 elif a == -1:
return "-i" 17 elif a == 1:
return "i" 18 else:
return fltToString(a)+
"i" 22 if re == 0
and im == 0:
return "0" 23 elif re == 0:
return imToString(im)
24 elif im == 0:
return fltToString(re)
26 im_str =
"-"+imToString(-im)
if im < 0
else "+"+imToString(im)
27 return fltToString(re)+im_str
74 two_P_L = [ id[x] - igamma5[x]/1j
for x
in range(0,4*4) ]
75 two_P_R = [ id[x] + igamma5[x]/1j
for x
in range(0,4*4) ]
85 return [x+y
for (x,y)
in zip(g1,g2)]
88 return [x-y
for (x,y)
in zip(g1,g2)]
108 def indentline(line):
return (n*
" "+line
if ( line
and line.count(
"#", 0, 1) == 0)
else line)
109 return ''.join([indentline(line)+
"\n" for line
in code.splitlines()])
112 return "{\n"+
indent(code)+
"}" 116 elif x==-1:
return "-" 117 elif x==+2:
return "+2*" 118 elif x==-2:
return "-2*" 121 return `(n/4)` +
"." + [
"x",
"y",
"z",
"w"][n%4]
124 return `(n/2)` +
"." + [
"x",
"y"][n%2]
127 def in_re(s, c):
return "i"+`s`+`c`+
"_re" 128 def in_im(s, c):
return "i"+`s`+`c`+
"_im" 129 def g_re(d, m, n):
return (
"g" if (d%2==0)
else "gT")+`m`+`n`+
"_re" 130 def g_im(d, m, n):
return (
"g" if (d%2==0)
else "gT")+`m`+`n`+
"_im" 131 def out_re(s, c):
return "o"+`s`+`c`+
"_re" 132 def out_im(s, c):
return "o"+`s`+`c`+
"_im" 133 def h1_re(h, c):
return [
"a",
"b"][h]+`c`+
"_re" 134 def h1_im(h, c):
return [
"a",
"b"][h]+`c`+
"_im" 135 def h2_re(h, c):
return [
"A",
"B"][h]+`c`+
"_re" 136 def h2_im(h, c):
return [
"A",
"B"][h]+`c`+
"_im" 137 def c_re(b, sm, cm, sn, cn):
return "c"+`(sm+2*b)`+`cm`+
"_"+`(sn+2*b)`+`cn`+
"_re" 138 def c_im(b, sm, cm, sn, cn):
return "c"+`(sm+2*b)`+`cm`+
"_"+`(sn+2*b)`+`cn`+
"_im" 139 def a_re(b, s, c):
return "a"+`(s+2*b)`+`c`+
"_re" 140 def a_im(b, s, c):
return "a"+`(s+2*b)`+`c`+
"_im" 142 def tmp_re(s, c):
return "tmp"+`s`+`c`+
"_re" 143 def tmp_im(s, c):
return "tmp"+`s`+`c`+
"_im" 148 str +=
"// input spinor\n" 149 str +=
"#ifdef SPINOR_DOUBLE\n" 150 str +=
"#define spinorFloat double\n" 157 str +=
"#define spinorFloat float\n" 163 str +=
"#endif // SPINOR_DOUBLE\n\n" 169 str =
"// gauge link\n" 170 str +=
"#ifdef GAUGE_FLOAT2\n" 186 str +=
"#endif // GAUGE_DOUBLE\n\n" 188 str +=
"// conjugated gauge link\n" 192 str +=
"#define "+
g_re(1,m,n)+
" (+"+
g_re(0,n,m)+
")\n" 193 str +=
"#define "+
g_im(1,m,n)+
" (-"+
g_im(0,n,m)+
")\n" 201 str =
"// first chiral block of inverted clover term\n" 202 str +=
"#ifdef CLOVER_DOUBLE\n" 212 for m
in range(n+1,6):
216 str +=
"#define "+
c_im(0,sm,cm,sn,cn)+
" C"+
nthFloat2(i+1)+
"\n" 228 for m
in range(n+1,6):
232 str +=
"#define "+
c_im(0,sm,cm,sn,cn)+
" C"+
nthFloat4(i+1)+
"\n" 234 str +=
"#endif // CLOVER_DOUBLE\n\n" 242 str +=
"#define "+
c_re(0,sm,cm,sn,cn)+
" (+"+
c_re(0,sn,cn,sm,cm)+
")\n" 243 str +=
"#define "+
c_im(0,sm,cm,sn,cn)+
" (-"+
c_im(0,sn,cn,sm,cm)+
")\n" 246 str +=
"// second chiral block of inverted clover term (reuses C0,...,C9)\n" 253 str +=
"#define "+
c_re(1,sm,cm,sn,cn)+
" "+
c_re(0,sm,cm,sn,cn)+
"\n" 254 if m != n: str +=
"#define "+
c_im(1,sm,cm,sn,cn)+
" "+
c_im(0,sm,cm,sn,cn)+
"\n" 261 str =
"// output spinor\n" 265 if 2*i < sharedFloats:
266 str +=
"#define "+
out_re(s,c)+
" s["+`(2*i+0)`+
"*SHARED_STRIDE]\n" 268 str +=
"VOLATILE spinorFloat "+
out_re(s,c)+
";\n" 269 if 2*i+1 < sharedFloats:
270 str +=
"#define "+
out_im(s,c)+
" s["+`(2*i+1)`+
"*SHARED_STRIDE]\n" 272 str +=
"VOLATILE spinorFloat "+
out_im(s,c)+
";\n" 279 prolog_str= (
"// *** CUDA DSLASH ***\n\n" if not dagger
else "// *** CUDA DSLASH DAGGER ***\n\n")
280 prolog_str+=
"#define DSLASH_SHARED_FLOATS_PER_THREAD "+str(sharedFloats)+
"\n\n" 282 prolog_str= (
"// *** CUDA CLOVER ***\n\n")
283 prolog_str+=
"#define CLOVER_SHARED_FLOATS_PER_THREAD "+str(sharedFloats)+
"\n\n" 285 print "Undefined prolog" 293 #if (CUDA_VERSION >= 4010) 296 #define VOLATILE volatile 301 if dslash ==
True: prolog_str+=
def_gauge()
308 #if (__COMPUTE_CAPABILITY__ >= 200) 309 #define SHARED_STRIDE 16 // to avoid bank conflicts on Fermi 311 #define SHARED_STRIDE 8 // to avoid bank conflicts on G80 and GT200 314 #if (__COMPUTE_CAPABILITY__ >= 200) 315 #define SHARED_STRIDE 32 // to avoid bank conflicts on Fermi 317 #define SHARED_STRIDE 16 // to avoid bank conflicts on G80 and GT200 325 extern __shared__ char s_data[]; 331 VOLATILE spinorFloat *s = (spinorFloat*)s_data + DSLASH_SHARED_FLOATS_PER_THREAD*SHARED_STRIDE*(threadIdx.x/SHARED_STRIDE) 332 + (threadIdx.x % SHARED_STRIDE); 337 VOLATILE spinorFloat *s = (spinorFloat*)s_data + CLOVER_SHARED_FLOATS_PER_THREAD*SHARED_STRIDE*(threadIdx.x/SHARED_STRIDE) 338 + (threadIdx.x % SHARED_STRIDE); 343 prolog_str +=
"\n#include \"read_gauge.h\"\n" 345 prolog_str +=
"#include \"read_clover.h\"\n" 346 prolog_str +=
"#include \"io_spinor.h\"\n" 349 #if (DD_PREC==2) // half precision 351 #endif // half precision 353 int sid = ((blockIdx.y*blockDim.y + threadIdx.y)*gridDim.x + blockIdx.x)*blockDim.x + threadIdx.x; 354 if (sid >= param.threads*param.dc.Ls) return; 370 dim = dimFromFaceIndex<5>(sid, param); // sid is also modified 372 const int face_volume = ((param.threadDimMapUpper[dim] - param.threadDimMapLower[dim])*param.dc.Ls >> 1); 373 const int face_num = (sid >= face_volume); // is this thread updating face 0 or 1 374 face_idx = sid - face_num*face_volume; // index into the respective face 376 // ghostOffset is scaled to include body (includes stride) and number of FloatN arrays (SPINOR_HOP) 377 // face_idx not sid since faces are spin projected and share the same volume index (modulo UP/DOWN reading) 378 //sp_idx = face_idx + param.ghostOffset[dim]; 382 coordsFromFaceIndex<5,QUDA_5D_PC,0,1>(X, sid, coord, face_idx, face_num, param); 385 coordsFromFaceIndex<5,QUDA_5D_PC,1,1>(X, sid, coord, face_idx, face_num, param); 388 coordsFromFaceIndex<5,QUDA_5D_PC,2,1>(X, sid, coord, face_idx, face_num, param); 391 coordsFromFaceIndex<5,QUDA_5D_PC,3,1>(X, sid, coord, face_idx, face_num, param); 396 for(int dir=0; dir<4; ++dir){ 397 active = active || isActive(dim,dir,+1,coord,param.commDim,param.dc.X); 402 s_parity = ( sid/param.dc.volume_4d_cb ) % 2; 404 READ_INTERMEDIATE_SPINOR(INTERTEX, param.sp_stride, sid, sid); 418 // declare G## here and use ASSN below instead of READ 420 #if (DD_PREC==0) //temporal hack 456 #include "io_spinor.h" 458 int sid = blockIdx.x*blockDim.x + threadIdx.x; 459 if (sid >= param.threads) return; 461 // read spinor from device memory 462 READ_SPINOR(SPINORTEX, param.sp_stride, sid, sid); 468 #include "read_clover.h" 469 #include "io_spinor.h" 471 int sid = blockIdx.x*blockDim.x + threadIdx.x; 472 if (sid >= param.threads) return; 474 // read spinor from device memory 475 READ_SPINOR(SPINORTEX, param.sp_stride, sid, sid); 482 def gen(dir, pack_only=False):
483 projIdx = dir
if not dagger
else dir + ( +1
if dir%2 == 0
else -1 )
486 return projectors[projIdx][4*i+j]
493 return (1, proj(i,1))
495 return (0, proj(i,0))
497 boundary = [
"coord[0]==(param.dc.X[0]-1)",
"coord[0]==0",
"coord[1]==(param.dc.X[1]-1)",
"coord[1]==0",
"coord[2]==(param.dc.X[2]-1)",
"coord[2]==0",
"coord[3]==(param.dc.X[3]-1)",
"coord[3]==0"]
498 interior = [
"coord[0]<(param.dc.X[0]-1)",
"coord[0]>0",
"coord[1]<(param.dc.X[1]-1)",
"coord[1]>0",
"coord[2]<(param.dc.X[2]-1)",
"coord[2]>0",
"coord[3]<(param.dc.X[3]-1)",
"coord[3]>0"]
499 offset = [
"+1",
"-1",
"+1",
"-1",
"+1",
"-1",
"+1",
"-1"]
500 dim = [
"X",
"Y",
"Z",
"T"]
503 sp_idx = [
"X+1",
"X-1",
"X+param.dc.X[0]",
"X-param.dc.X[0]",
"X+param.dc.X2X1",
"X-param.dc.X2X1",
"X+param.dc.X3X2X1",
"X-param.dc.X3X2X1"]
506 sp_idx_wrap = [
"X-(param.dc.X[0]-1)",
"X+(param.dc.X[0]-1)",
"X-param.dc.X2X1mX1",
"X+param.dc.X2X1mX1",
"X-param.dc.X3X2X1mX2X1",
"X+param.dc.X3X2X1mX2X1",
507 "X-param.dc.X4X3X2X1mX3X2X1",
"X+param.dc.X4X3X2X1mX3X2X1"]
510 cond +=
"if (isActive(dim," + `dir/2` +
"," + offset[dir] +
",coord,param.commDim,param.dc.X) && " + boundary[dir] +
" )\n" 515 projName =
"P"+`dir/2`+[
"-",
"+"][projIdx%2]
516 str +=
"// Projector "+projName+
"\n" 517 for l
in projStr.splitlines():
521 str +=
"faceIndexFromCoords<5,1>(face_idx,coord," + `dir/2` +
",param);\n" 522 str +=
"const int sp_idx = face_idx + param.ghostOffset[" + `dir/2` +
"][" + `1-dir%2` +
"];\n" 523 str +=
"#if (DD_PREC==2) // half precision\n" 524 str +=
" sp_norm_idx = face_idx + " 527 str +=
"param.ghostNormOffset[" + `dir/2` +
"][" + `1-dir%2` +
"];\n" 531 if domain_wall: str +=
"const int ga_idx = sid % param.dc.volume_4d_cb;\n" 532 else: str +=
"const int ga_idx = sid;\n" 534 if domain_wall: str +=
"const int ga_idx = param.dc.volume_4d_cb+(face_idx % param.dc.ghostFace[" + `dir/2` +
"]);\n" 535 else: str +=
"const int ga_idx = param.dc.volume_4d_cb+face_idx;\n" 539 row_cnt = ([0,0,0,0])
544 if re != 0
or im != 0:
546 row_cnt[0] += row_cnt[1]
547 row_cnt[2] += row_cnt[3]
550 for h
in range(0, 2):
551 for c
in range(0, 3):
552 decl_half +=
"spinorFloat "+
h1_re(h,c)+
", "+
h1_im(h,c)+
";\n";
555 load_spinor =
"// read spinor from device memory\n" 557 load_spinor +=
"READ_SPINOR_DOWN(SPINORTEX, param.sp_stride, sp_idx, sp_idx);\n" 558 elif row_cnt[2] == 0:
559 load_spinor +=
"READ_SPINOR_UP(SPINORTEX, param.sp_stride, sp_idx, sp_idx);\n" 561 load_spinor +=
"READ_SPINOR(SPINORTEX, param.sp_stride, sp_idx, sp_idx);\n" 566 load_half +=
"const int sp_stride_pad = param.dc.Ls*param.dc.ghostFace[" + `dir/2` +
"];\n" 568 load_half +=
"const int sp_stride_pad = param.dc.ghostFace[" + `dir/2` +
"];\n" 570 if dir >= 6: load_half +=
"const int t_proj_scale = TPROJSCALE;\n" 572 load_half +=
"// read half spinor from device memory\n" 576 load_half +=
"READ_SPINOR_GHOST(GHOSTSPINORTEX, sp_stride_pad, sp_idx, sp_norm_idx, "+`dir`+
");\n\n" 579 load_gauge =
"// read gauge matrix from device memory\n" 581 load_gauge +=
"if ( ! s_parity ) { ASSN_GAUGE_MATRIX(G, GAUGE"+`( dir%2)`+
"TEX, "+`dir`+
", ga_idx, param.gauge_stride); }\n" 582 load_gauge +=
"else { ASSN_GAUGE_MATRIX(G, GAUGE"+`(1-dir%2)`+
"TEX, "+`dir`+
", ga_idx, param.gauge_stride); }\n\n" 584 load_gauge +=
"READ_GAUGE_MATRIX(G, GAUGE"+`dir%2`+
"TEX, "+`dir`+
", ga_idx, param.gauge_stride);\n\n" 586 reconstruct_gauge =
"// reconstruct gauge matrix\n" 587 reconstruct_gauge +=
"RECONSTRUCT_GAUGE_MATRIX("+`dir`+
");\n\n" 589 project =
"// project spinor into half spinors\n" 590 for h
in range(0, 2):
591 for c
in range(0, 3):
594 for s
in range(0, 4):
597 if re==0
and im==0: ()
605 for s
in range(0, 4):
606 re = proj(h+2,s).real
607 im = proj(h+2,s).imag
608 if re==0
and im==0: ()
616 project +=
h1_re(h,c)+
" = "+strRe+
";\n" 617 project +=
h1_im(h,c)+
" = "+strIm+
";\n" 620 for h
in range(0, 2):
621 for c
in range(0, 3):
622 copy_half +=
h1_re(h,c)+
" = "+(
"t_proj_scale*" if (dir >= 6)
else "")+
in_re(h,c)+
"; " 623 copy_half +=
h1_im(h,c)+
" = "+(
"t_proj_scale*" if (dir >= 6)
else "")+
in_im(h,c)+
";\n" 629 prep_half +=
indent(load_half)
630 prep_half +=
indent(copy_half)
634 ident =
"// identity gauge matrix\n" 637 ident +=
"spinorFloat "+
h2_re(h,m)+
" = " +
h1_re(h,m) +
"; " 638 ident +=
"spinorFloat "+
h2_im(h,m)+
" = " +
h1_im(h,m) +
";\n" 643 mult +=
"// multiply row "+`m`+
"\n" 645 re =
"spinorFloat "+
h2_re(h,m)+
" = 0;\n" 646 im =
"spinorFloat "+
h2_im(h,m)+
" = 0;\n" 648 re +=
h2_re(h,m) +
" += " +
g_re(dir,m,c) +
" * "+
h1_re(h,c)+
";\n" 649 re +=
h2_re(h,m) +
" -= " +
g_im(dir,m,c) +
" * "+
h1_im(h,c)+
";\n" 650 im +=
h2_im(h,m) +
" += " +
g_re(dir,m,c) +
" * "+
h1_im(h,c)+
";\n" 651 im +=
h2_im(h,m) +
" += " +
g_im(dir,m,c) +
" * "+
h1_re(h,c)+
";\n" 662 reconstruct +=
out_re(h_out, m) +
" += " +
h2_re(h,m) +
";\n" 663 reconstruct +=
out_im(h_out, m) +
" += " +
h2_im(h,m) +
";\n" 669 if im == 0
and re == 0:
672 reconstruct +=
out_re(s, m) +
" " +
sign(re) +
"= " +
h2_re(h,m) +
";\n" 673 reconstruct +=
out_im(s, m) +
" " +
sign(re) +
"= " +
h2_im(h,m) +
";\n" 675 reconstruct +=
out_re(s, m) +
" " +
sign(-im) +
"= " +
h2_im(h,m) +
";\n" 676 reconstruct +=
out_im(s, m) +
" " +
sign(+im) +
"= " +
h2_re(h,m) +
";\n" 678 if ( m < 2 ): reconstruct +=
"\n" 681 str +=
"if (param.gauge_fixed && ga_idx < param.dc.X4X3X2X1hmX3X2X1h)\n" 682 str +=
block(decl_half + prep_half + ident + reconstruct)
684 str +=
block(load_gauge + decl_half + prep_half + reconstruct_gauge + mult + reconstruct)
686 str += load_gauge + decl_half + prep_half + reconstruct_gauge + mult + reconstruct
689 out = load_spinor + decl_half + project
690 out = out.replace(
"sp_idx",
"idx")
693 return cond +
block(str)+
"\n\n" 701 if z==0:
return out_re(s,c)
704 if z==0:
return in_re(s,c)
705 else:
return in_im(s,c)
719 for s
in range (0,4):
723 return block(str)+
"\n\n" 731 str +=
"spinorFloat "+
a_re(0,1,c)+
" = -"+
out_re(0,c)+
" - "+
out_re(2,c)+
";\n" 732 str +=
"spinorFloat "+
a_im(0,1,c)+
" = -"+
out_im(0,c)+
" - "+
out_im(2,c)+
";\n" 735 str +=
"spinorFloat "+
a_re(0,3,c)+
" = -"+
out_re(0,c)+
" + "+
out_re(2,c)+
";\n" 736 str +=
"spinorFloat "+
a_im(0,3,c)+
" = -"+
out_im(0,c)+
" + "+
out_im(2,c)+
";\n" 739 for s
in range (0,4):
743 return block(str)+
"\n\n" 748 str =
"READ_CLOVER(CLOVERTEX, "+`chi`+
")\n\n" 750 for s
in range (0,2):
751 for c
in range (0,3):
752 str +=
"spinorFloat "+
a_re(chi,s,c)+
" = 0; spinorFloat "+
a_im(chi,s,c)+
" = 0;\n" 755 for sm
in range (0,2):
756 for cm
in range (0,3):
757 for sn
in range (0,2):
758 for cn
in range (0,3):
759 str +=
a_re(chi,sm,cm)+
" += "+
c_re(chi,sm,cm,sn,cn)+
" * "+
out_re(2*chi+sn,cn)+
";\n" 760 if (sn != sm)
or (cn != cm):
761 str +=
a_re(chi,sm,cm)+
" -= "+
c_im(chi,sm,cm,sn,cn)+
" * "+
out_im(2*chi+sn,cn)+
";\n" 763 str +=
a_im(chi,sm,cm)+
" += "+
c_re(chi,sm,cm,sn,cn)+
" * "+
out_im(2*chi+sn,cn)+
";\n" 764 if (sn != sm)
or (cn != cm):
765 str +=
a_im(chi,sm,cm)+
" += "+
c_im(chi,sm,cm,sn,cn)+
" * "+
out_re(2*chi+sn,cn)+
";\n" 769 for s
in range (0,2):
770 for c
in range (0,3):
771 str +=
out_re(2*chi+s,c)+
" = "+
a_re(chi,s,c)+
"; " 772 str +=
out_im(2*chi+s,c)+
" = "+
a_im(chi,s,c)+
";\n" 775 return block(str)+
"\n\n" 780 if domain_wall:
return "" 782 if dslash: str +=
"#ifdef DSLASH_CLOVER\n\n" 783 str +=
"// change to chiral basis\n" 785 str +=
"// apply first chiral block\n" 787 str +=
"// apply second chiral block\n" 789 str +=
"// change back from chiral basis\n" 790 str +=
"// (note: required factor of 1/2 is included in clover term normalization)\n" 792 if dslash: str +=
"#endif // DSLASH_CLOVER\n\n" 800 str +=
"#ifdef DSLASH_XPAY\n" 802 str +=
"#ifdef SPINOR_DOUBLE\n" 803 str +=
"spinorFloat a = param.a;\n" 805 str +=
"spinorFloat a = param.a_f;\n" 808 str +=
"#ifdef SPINOR_DOUBLE\n" 824 str +=
"#endif // SPINOR_DOUBLE\n\n" 825 str +=
"#endif // DSLASH_XPAY\n" 836 str +=
"// write spinor field back to device memory\n" 837 str +=
"WRITE_SPINOR(param.sp_stride);\n\n" 839 str +=
"// undefine to prevent warning when precision is changed\n" 840 str +=
"#undef spinorFloat\n" 841 str +=
"#undef SHARED_STRIDE\n\n" 847 str +=
"#undef "+
g_re(0,m,n)+
"\n" 848 str +=
"#undef "+
g_im(0,m,n)+
"\n" 854 str +=
"#undef "+
in_re(s,c)+
"\n" 855 str +=
"#undef "+
in_im(s,c)+
"\n" 862 str +=
"#undef "+
c_re(0,s,c,s,c)+
"\n" 866 for m
in range(n+1,6):
869 str +=
"#undef "+
c_re(0,sm,cm,sn,cn)+
"\n" 870 str +=
"#undef "+
c_im(0,sm,cm,sn,cn)+
"\n" 876 if 2*i < sharedFloats:
877 str +=
"#undef "+
out_re(s,c)+
"\n" 878 if 2*i+1 < sharedFloats:
879 str +=
"#undef "+
out_im(s,c)+
"\n" 882 str +=
"#undef VOLATILE\n" 885 str +=
"#endif // MULTI_GPU\n" 892 str +=
"switch(dim) {\n" 893 for dim
in range(0,4):
894 str +=
"case "+`dim`+
":\n" 895 proj =
gen(2*dim+facenum, pack_only=
True)
897 proj +=
"// write half spinor back to device memory\n" 898 proj +=
"WRITE_HALF_SPINOR(face_volume, face_idx);\n" 905 assert (sharedFloats == 0)
908 str +=
"#include \"io_spinor.h\"\n\n" 910 str +=
"if (face_num) " 916 str +=
"// undefine to prevent warning when precision is changed\n" 917 str +=
"#undef spinorFloat\n" 918 str +=
"#undef SHARED_STRIDE\n\n" 923 str +=
"#undef "+
in_re(s,c)+
"\n" 924 str +=
"#undef "+
in_im(s,c)+
"\n" 933 for i
in range(0,8) :
945 cloverSharedFloats = 0
946 if(
len(sys.argv) > 1):
947 if (sys.argv[1] ==
'--shared'):
948 sharedFloats =
int(sys.argv[2])
949 print "Shared floats set to " + str(sharedFloats);
956 print sys.argv[0] +
": generating dw_dslash_core.h";
959 f = open(
'dslash_core/dw_fused_exterior_dslash_core.h',
'w')
963 print sys.argv[0] +
": generating dw_dslash_dagger_core.h";
966 f = open(
'dslash_core/dw_fused_exterior_dslash_dagger_core.h',
'w')
def input_spinor(s, c, z)
def gen(dir, pack_only=False)
def indent(code, n=1)
code generation ######################################################################## ...
def complexify(a)
complex numbers ######################################################################## ...
def c_im(b, sm, cm, sn, cn)
def c_re(b, sm, cm, sn, cn)