memtort.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. /**************************************************************************
  2. **
  3. ** Copyright (C) 1993 David E. Steward & Zbigniew Leyk, all rights reserved.
  4. **
  5. ** Meschach Library
  6. **
  7. ** This Meschach Library is provided "as is" without any express
  8. ** or implied warranty of any kind with respect to this software.
  9. ** In particular the authors shall not be liable for any direct,
  10. ** indirect, special, incidental or consequential damages arising
  11. ** in any way from use of the software.
  12. **
  13. ** Everyone is granted permission to copy, modify and redistribute this
  14. ** Meschach Library, provided:
  15. ** 1. All copies contain this copyright notice.
  16. ** 2. All modified copies shall carry a notice stating who
  17. ** made the last modification and the date of such modification.
  18. ** 3. No charge is made for this software or works derived from it.
  19. ** This clause shall not be construed as constraining other software
  20. ** distributed on the same medium as this software, nor is a
  21. ** distribution fee considered a charge.
  22. **
  23. ***************************************************************************/
  24. /*
  25. Tests for mem_info.c functions
  26. */
  27. static char rcsid[] = "$Id: $";
  28. #include <stdio.h>
  29. #include <math.h>
  30. #include "matrix2.h"
  31. #include "sparse2.h"
  32. #include "zmatrix2.h"
  33. #define errmesg(mesg) printf("Error: %s error: line %d\n",mesg,__LINE__)
  34. #define notice(mesg) printf("# Testing %s...\n",mesg)
  35. /* new types list */
  36. extern MEM_CONNECT mem_connect[MEM_CONNECT_MAX_LISTS];
  37. /* the number of a new list */
  38. #define FOO_LIST 1
  39. /* numbers of types */
  40. #define TYPE_FOO_1 1
  41. #define TYPE_FOO_2 2
  42. typedef struct {
  43. int dim;
  44. int fix_dim;
  45. Real (*a)[10];
  46. } FOO_1;
  47. typedef struct {
  48. int dim;
  49. int fix_dim;
  50. Real (*a)[2];
  51. } FOO_2;
  52. FOO_1 *foo_1_get(dim)
  53. int dim;
  54. {
  55. FOO_1 *f;
  56. if ((f = (FOO_1 *)malloc(sizeof(FOO_1))) == NULL)
  57. error(E_MEM,"foo_1_get");
  58. else if (mem_info_is_on()) {
  59. mem_bytes_list(TYPE_FOO_1,0,sizeof(FOO_1),FOO_LIST);
  60. mem_numvar_list(TYPE_FOO_1,1,FOO_LIST);
  61. }
  62. f->dim = dim;
  63. f->fix_dim = 10;
  64. if ((f->a = (Real (*)[10])malloc(dim*sizeof(Real [10]))) == NULL)
  65. error(E_MEM,"foo_1_get");
  66. else if (mem_info_is_on())
  67. mem_bytes_list(TYPE_FOO_1,0,dim*sizeof(Real [10]),FOO_LIST);
  68. return f;
  69. }
  70. FOO_2 *foo_2_get(dim)
  71. int dim;
  72. {
  73. FOO_2 *f;
  74. if ((f = (FOO_2 *)malloc(sizeof(FOO_2))) == NULL)
  75. error(E_MEM,"foo_2_get");
  76. else if (mem_info_is_on()) {
  77. mem_bytes_list(TYPE_FOO_2,0,sizeof(FOO_2),FOO_LIST);
  78. mem_numvar_list(TYPE_FOO_2,1,FOO_LIST);
  79. }
  80. f->dim = dim;
  81. f->fix_dim = 2;
  82. if ((f->a = (Real (*)[2])malloc(dim*sizeof(Real [2]))) == NULL)
  83. error(E_MEM,"foo_2_get");
  84. else if (mem_info_is_on())
  85. mem_bytes_list(TYPE_FOO_2,0,dim*sizeof(Real [2]),FOO_LIST);
  86. return f;
  87. }
  88. int foo_1_free(f)
  89. FOO_1 *f;
  90. {
  91. if ( f != NULL) {
  92. if (mem_info_is_on()) {
  93. mem_bytes_list(TYPE_FOO_1,sizeof(FOO_1)+
  94. f->dim*sizeof(Real [10]),0,FOO_LIST);
  95. mem_numvar_list(TYPE_FOO_1,-1,FOO_LIST);
  96. }
  97. free(f->a);
  98. free(f);
  99. }
  100. return 0;
  101. }
  102. int foo_2_free(f)
  103. FOO_2 *f;
  104. {
  105. if ( f != NULL) {
  106. if (mem_info_is_on()) {
  107. mem_bytes_list(TYPE_FOO_2,sizeof(FOO_2)+
  108. f->dim*sizeof(Real [2]),0,FOO_LIST);
  109. mem_numvar_list(TYPE_FOO_2,-1,FOO_LIST);
  110. }
  111. free(f->a);
  112. free(f);
  113. }
  114. return 0;
  115. }
  116. char *foo_type_name[] = {
  117. "nothing",
  118. "FOO_1",
  119. "FOO_2"
  120. };
  121. #define FOO_NUM_TYPES (sizeof(foo_type_name)/sizeof(*foo_type_name))
  122. int (*foo_free_func[FOO_NUM_TYPES])() = {
  123. NULL,
  124. foo_1_free,
  125. foo_2_free
  126. };
  127. static MEM_ARRAY foo_info_sum[FOO_NUM_TYPES];
  128. /* px_rand -- generates sort-of random permutation */
  129. PERM *px_rand(pi)
  130. PERM *pi;
  131. {
  132. int i, j, k;
  133. if ( ! pi )
  134. error(E_NULL,"px_rand");
  135. for ( i = 0; i < 3*pi->size; i++ )
  136. {
  137. j = (rand() >> 8) % pi->size;
  138. k = (rand() >> 8) % pi->size;
  139. px_transp(pi,j,k);
  140. }
  141. return pi;
  142. }
  143. #ifdef SPARSE
  144. SPMAT *gen_non_symm(m,n)
  145. int m, n;
  146. {
  147. SPMAT *A;
  148. static PERM *px = PNULL;
  149. int i, j, k, k_max;
  150. Real s1;
  151. A = sp_get(m,n,8);
  152. px = px_resize(px,n);
  153. MEM_STAT_REG(px,TYPE_PERM);
  154. for ( i = 0; i < A->m; i++ )
  155. {
  156. k_max = 1 + ((rand() >> 8) % 10);
  157. for ( k = 0; k < k_max; k++ )
  158. {
  159. j = (rand() >> 8) % A->n;
  160. s1 = rand()/((double)MAX_RAND);
  161. sp_set_val(A,i,j,s1);
  162. }
  163. }
  164. /* to make it likely that A is nonsingular, use pivot... */
  165. for ( i = 0; i < 2*A->n; i++ )
  166. {
  167. j = (rand() >> 8) % A->n;
  168. k = (rand() >> 8) % A->n;
  169. px_transp(px,j,k);
  170. }
  171. for ( i = 0; i < A->n; i++ )
  172. sp_set_val(A,i,px->pe[i],1.0);
  173. return A;
  174. }
  175. #endif
  176. void stat_test1(par)
  177. int par;
  178. {
  179. static MAT *AT = MNULL;
  180. static VEC *xt1 = VNULL, *yt1 = VNULL;
  181. static VEC *xt2 = VNULL, *yt2 = VNULL;
  182. static VEC *xt3 = VNULL, *yt3 = VNULL;
  183. static VEC *xt4 = VNULL, *yt4 = VNULL;
  184. AT = m_resize(AT,10,10);
  185. xt1 = v_resize(xt1,10);
  186. yt1 = v_resize(yt1,10);
  187. xt2 = v_resize(xt2,10);
  188. yt2 = v_resize(yt2,10);
  189. xt3 = v_resize(xt3,10);
  190. yt3 = v_resize(yt3,10);
  191. xt4 = v_resize(xt4,10);
  192. yt4 = v_resize(yt4,10);
  193. MEM_STAT_REG(AT,TYPE_MAT);
  194. #ifdef ANSI_C
  195. mem_stat_reg_vars(0,TYPE_VEC,__FILE__,__LINE__,&xt1,&xt2,&xt3,&xt4,&yt1,
  196. &yt2,&yt3,&yt4,NULL);
  197. #else
  198. #ifdef VARARGS
  199. mem_stat_reg_vars(0,TYPE_VEC,__FILE__,__LINE__,&xt1,&xt2,&xt3,&xt4,&yt1,
  200. &yt2,&yt3,&yt4,NULL);
  201. #else
  202. MEM_STAT_REG(xt1,TYPE_VEC);
  203. MEM_STAT_REG(yt1,TYPE_VEC);
  204. MEM_STAT_REG(xt2,TYPE_VEC);
  205. MEM_STAT_REG(yt2,TYPE_VEC);
  206. MEM_STAT_REG(xt3,TYPE_VEC);
  207. MEM_STAT_REG(yt3,TYPE_VEC);
  208. MEM_STAT_REG(xt4,TYPE_VEC);
  209. MEM_STAT_REG(yt4,TYPE_VEC);
  210. #endif
  211. #endif
  212. v_rand(xt1);
  213. m_rand(AT);
  214. mv_mlt(AT,xt1,yt1);
  215. }
  216. void stat_test2(par)
  217. int par;
  218. {
  219. static PERM *px = PNULL;
  220. static IVEC *ixt = IVNULL, *iyt = IVNULL;
  221. px = px_resize(px,10);
  222. ixt = iv_resize(ixt,10);
  223. iyt = iv_resize(iyt,10);
  224. MEM_STAT_REG(px,TYPE_PERM);
  225. MEM_STAT_REG(ixt,TYPE_IVEC);
  226. MEM_STAT_REG(iyt,TYPE_IVEC);
  227. px_rand(px);
  228. px_inv(px,px);
  229. }
  230. #ifdef SPARSE
  231. void stat_test3(par)
  232. int par;
  233. {
  234. static SPMAT *AT = (SPMAT *)NULL;
  235. static VEC *xt = VNULL, *yt = VNULL;
  236. static SPROW *r = (SPROW *) NULL;
  237. if (AT == (SPMAT *)NULL)
  238. AT = gen_non_symm(100,100);
  239. else
  240. AT = sp_resize(AT,100,100);
  241. xt = v_resize(xt,100);
  242. yt = v_resize(yt,100);
  243. if (r == NULL) r = sprow_get(100);
  244. MEM_STAT_REG(AT,TYPE_SPMAT);
  245. MEM_STAT_REG(xt,TYPE_VEC);
  246. MEM_STAT_REG(yt,TYPE_VEC);
  247. MEM_STAT_REG(r,TYPE_SPROW);
  248. v_rand(xt);
  249. sp_mv_mlt(AT,xt,yt);
  250. }
  251. #endif
  252. #ifdef COMPLEX
  253. void stat_test4(par)
  254. int par;
  255. {
  256. static ZMAT *AT = ZMNULL;
  257. static ZVEC *xt = ZVNULL, *yt = ZVNULL;
  258. AT = zm_resize(AT,10,10);
  259. xt = zv_resize(xt,10);
  260. yt = zv_resize(yt,10);
  261. MEM_STAT_REG(AT,TYPE_ZMAT);
  262. MEM_STAT_REG(xt,TYPE_ZVEC);
  263. MEM_STAT_REG(yt,TYPE_ZVEC);
  264. zv_rand(xt);
  265. zm_rand(AT);
  266. zmv_mlt(AT,xt,yt);
  267. }
  268. #endif
  269. void main(argc, argv)
  270. int argc;
  271. char *argv[];
  272. {
  273. VEC *x = VNULL, *y = VNULL, *z = VNULL;
  274. PERM *pi1 = PNULL, *pi2 = PNULL, *pi3 = PNULL;
  275. MAT *A = MNULL, *B = MNULL, *C = MNULL;
  276. #ifdef SPARSE
  277. SPMAT *sA, *sB;
  278. SPROW *r;
  279. #endif
  280. IVEC *ix = IVNULL, *iy = IVNULL, *iz = IVNULL;
  281. int m,n,i,j,deg,k;
  282. Real s1,s2;
  283. #ifdef COMPLEX
  284. ZVEC *zx = ZVNULL, *zy = ZVNULL, *zz = ZVNULL;
  285. ZMAT *zA = ZMNULL, *zB = ZMNULL, *zC = ZMNULL;
  286. complex ONE;
  287. #endif
  288. /* variables for testing attaching new lists of types */
  289. FOO_1 *foo_1;
  290. FOO_2 *foo_2;
  291. mem_info_on(TRUE);
  292. #if defined(ANSI_C) || defined(VARARGS)
  293. notice("vector initialize, copy & resize");
  294. n = v_get_vars(15,&x,&y,&z,(VEC **)NULL);
  295. if (n != 3) {
  296. errmesg("v_get_vars");
  297. printf(" n = %d (should be 3)\n",n);
  298. }
  299. v_rand(x);
  300. v_rand(y);
  301. z = v_copy(x,z);
  302. if ( v_norm2(v_sub(x,z,z)) >= MACHEPS )
  303. errmesg("v_get_vars");
  304. v_copy(x,y);
  305. n = v_resize_vars(10,&x,&y,&z,NULL);
  306. if ( n != 3 || v_norm2(v_sub(x,y,z)) >= MACHEPS )
  307. errmesg("VEC copy/resize");
  308. n = v_resize_vars(20,&x,&y,&z,NULL);
  309. if ( n != 3 || v_norm2(v_sub(x,y,z)) >= MACHEPS )
  310. errmesg("VEC resize");
  311. n = v_free_vars(&x,&y,&z,NULL);
  312. if (n != 3)
  313. errmesg("v_free_vars");
  314. /* IVEC */
  315. notice("int vector initialise, copy & resize");
  316. n = iv_get_vars(15,&ix,&iy,&iz,NULL);
  317. if (n != 3) {
  318. errmesg("iv_get_vars");
  319. printf(" n = %d (should be 3)\n",n);
  320. }
  321. for (i=0; i < ix->dim; i++) {
  322. ix->ive[i] = 2*i-1;
  323. iy->ive[i] = 3*i+2;
  324. }
  325. iz = iv_add(ix,iy,iz);
  326. for (i=0; i < ix->dim; i++)
  327. if ( iz->ive[i] != 5*i+1)
  328. errmesg("iv_get_vars");
  329. n = iv_resize_vars(10,&ix,&iy,&iz,NULL);
  330. if ( n != 3) errmesg("IVEC copy/resize");
  331. iv_add(ix,iy,iz);
  332. for (i=0; i < ix->dim; i++)
  333. if (iz->ive[i] != 5*i+1)
  334. errmesg("IVEC copy/resize");
  335. n = iv_resize_vars(20,&ix,&iy,&iz,NULL);
  336. if ( n != 3 ) errmesg("IVEC resize");
  337. iv_add(ix,iy,iz);
  338. for (i=0; i < 10; i++)
  339. if (iz->ive[i] != 5*i+1)
  340. errmesg("IVEC copy/resize");
  341. n = iv_free_vars(&ix,&iy,&iz,NULL);
  342. if (n != 3)
  343. errmesg("iv_free_vars");
  344. /* MAT */
  345. notice("matrix initialise, copy & resize");
  346. n = m_get_vars(10,10,&A,&B,&C,NULL);
  347. if (n != 3) {
  348. errmesg("m_get_vars");
  349. printf(" n = %d (should be 3)\n",n);
  350. }
  351. m_rand(A);
  352. m_rand(B);
  353. C = m_copy(A,C);
  354. if ( m_norm_inf(m_sub(A,C,C)) >= MACHEPS )
  355. errmesg("MAT copy");
  356. m_copy(A,B);
  357. n = m_resize_vars(5,5,&A,&B,&C,NULL);
  358. if ( n != 3 || m_norm_inf(m_sub(A,B,C)) >= MACHEPS )
  359. errmesg("MAT copy/resize");
  360. n = m_resize_vars(20,20,&A,&B,NULL);
  361. if ( m_norm_inf(m_sub(A,B,C)) >= MACHEPS )
  362. errmesg("MAT resize");
  363. k = m_free_vars(&A,&B,&C,NULL);
  364. if ( k != 3 )
  365. errmesg("MAT free");
  366. /* PERM */
  367. notice("permutation initialise, inverting & permuting vectors");
  368. n = px_get_vars(15,&pi1,&pi2,&pi3,NULL);
  369. if (n != 3) {
  370. errmesg("px_get_vars");
  371. printf(" n = %d (should be 3)\n",n);
  372. }
  373. v_get_vars(15,&x,&y,&z,NULL);
  374. px_rand(pi1);
  375. v_rand(x);
  376. px_vec(pi1,x,z);
  377. y = v_resize(y,x->dim);
  378. pxinv_vec(pi1,z,y);
  379. if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  380. errmesg("PERMute vector");
  381. pi2 = px_inv(pi1,pi2);
  382. pi3 = px_mlt(pi1,pi2,pi3);
  383. for ( i = 0; i < pi3->size; i++ )
  384. if ( pi3->pe[i] != i )
  385. errmesg("PERM inverse/multiply");
  386. px_resize_vars(20,&pi1,&pi2,&pi3,NULL);
  387. v_resize_vars(20,&x,&y,&z,NULL);
  388. px_rand(pi1);
  389. v_rand(x);
  390. px_vec(pi1,x,z);
  391. pxinv_vec(pi1,z,y);
  392. if ( v_norm2(v_sub(x,y,z)) >= MACHEPS )
  393. errmesg("PERMute vector");
  394. pi2 = px_inv(pi1,pi2);
  395. pi3 = px_mlt(pi1,pi2,pi3);
  396. for ( i = 0; i < pi3->size; i++ )
  397. if ( pi3->pe[i] != i )
  398. errmesg("PERM inverse/multiply");
  399. n = px_free_vars(&pi1,&pi2,&pi3,NULL);
  400. if ( n != 3 )
  401. errmesg("PERM px_free_vars");
  402. #ifdef SPARSE
  403. /* set up two random sparse matrices */
  404. m = 120;
  405. n = 100;
  406. deg = 5;
  407. notice("allocating sparse matrices");
  408. k = sp_get_vars(m,n,deg,&sA,&sB,NULL);
  409. if (k != 2) {
  410. errmesg("sp_get_vars");
  411. printf(" n = %d (should be 2)\n",k);
  412. }
  413. notice("setting and getting matrix entries");
  414. for ( k = 0; k < m*deg; k++ )
  415. {
  416. i = (rand() >> 8) % m;
  417. j = (rand() >> 8) % n;
  418. sp_set_val(sA,i,j,rand()/((Real)MAX_RAND));
  419. i = (rand() >> 8) % m;
  420. j = (rand() >> 8) % n;
  421. sp_set_val(sB,i,j,rand()/((Real)MAX_RAND));
  422. }
  423. for ( k = 0; k < 10; k++ )
  424. {
  425. s1 = rand()/((Real)MAX_RAND);
  426. i = (rand() >> 8) % m;
  427. j = (rand() >> 8) % n;
  428. sp_set_val(sA,i,j,s1);
  429. s2 = sp_get_val(sA,i,j);
  430. if ( fabs(s1 - s2) >= MACHEPS ) {
  431. printf(" s1 = %g, s2 = %g, |s1 - s2| = %g\n",
  432. s1,s2,fabs(s1-s2));
  433. break;
  434. }
  435. }
  436. if ( k < 10 )
  437. errmesg("sp_set_val()/sp_get_val()");
  438. /* check column access paths */
  439. notice("resizing and access paths");
  440. k = sp_resize_vars(sA->m+10,sA->n+10,&sA,&sB,NULL);
  441. if (k != 2) {
  442. errmesg("sp_get_vars");
  443. printf(" n = %d (should be 2)\n",k);
  444. }
  445. for ( k = 0 ; k < 20; k++ )
  446. {
  447. i = sA->m - 1 - ((rand() >> 8) % 10);
  448. j = sA->n - 1 - ((rand() >> 8) % 10);
  449. s1 = rand()/((Real)MAX_RAND);
  450. sp_set_val(sA,i,j,s1);
  451. if ( fabs(s1 - sp_get_val(sA,i,j)) >= MACHEPS )
  452. break;
  453. }
  454. if ( k < 20 )
  455. errmesg("sp_resize()");
  456. sp_col_access(sA);
  457. if ( ! chk_col_access(sA) )
  458. {
  459. errmesg("sp_col_access()");
  460. }
  461. sp_diag_access(sA);
  462. for ( i = 0; i < sA->m; i++ )
  463. {
  464. r = &(sA->row[i]);
  465. if ( r->diag != sprow_idx(r,i) )
  466. break;
  467. }
  468. if ( i < sA->m )
  469. {
  470. errmesg("sp_diag_access()");
  471. }
  472. k = sp_free_vars(&sA,&sB,NULL);
  473. if (k != 2)
  474. errmesg("sp_free_vars");
  475. #endif /* SPARSE */
  476. #ifdef COMPLEX
  477. /* complex stuff */
  478. ONE = zmake(1.0,0.0);
  479. printf("# ONE = "); z_output(ONE);
  480. printf("# Check: MACHEPS = %g\n",MACHEPS);
  481. /* allocate, initialise, copy and resize operations */
  482. /* ZVEC */
  483. notice("vector initialise, copy & resize");
  484. zv_get_vars(12,&zx,&zy,&zz,NULL);
  485. zv_rand(zx);
  486. zv_rand(zy);
  487. zz = zv_copy(zx,zz);
  488. if ( zv_norm2(zv_sub(zx,zz,zz)) >= MACHEPS )
  489. errmesg("ZVEC copy");
  490. zv_copy(zx,zy);
  491. zv_resize_vars(10,&zx,&zy,NULL);
  492. if ( zv_norm2(zv_sub(zx,zy,zz)) >= MACHEPS )
  493. errmesg("ZVEC copy/resize");
  494. zv_resize_vars(20,&zx,&zy,NULL);
  495. if ( zv_norm2(zv_sub(zx,zy,zz)) >= MACHEPS )
  496. errmesg("VZEC resize");
  497. zv_free_vars(&zx,&zy,&zz,NULL);
  498. /* ZMAT */
  499. notice("matrix initialise, copy & resize");
  500. zm_get_vars(8,5,&zA,&zB,&zC,NULL);
  501. zm_rand(zA);
  502. zm_rand(zB);
  503. zC = zm_copy(zA,zC);
  504. if ( zm_norm_inf(zm_sub(zA,zC,zC)) >= MACHEPS )
  505. errmesg("ZMAT copy");
  506. zm_copy(zA,zB);
  507. zm_resize_vars(3,5,&zA,&zB,&zC,NULL);
  508. if ( zm_norm_inf(zm_sub(zA,zB,zC)) >= MACHEPS )
  509. errmesg("ZMAT copy/resize");
  510. zm_resize_vars(20,20,&zA,&zB,&zC,NULL);
  511. if ( zm_norm_inf(zm_sub(zA,zB,zC)) >= MACHEPS )
  512. errmesg("ZMAT resize");
  513. zm_free_vars(&zA,&zB,&zC,NULL);
  514. #endif /* COMPLEX */
  515. #endif /* if defined(ANSI_C) || defined(VARARGS) */
  516. printf("# test of mem_info_bytes and mem_info_numvar\n");
  517. printf(" TYPE VEC: %ld bytes allocated, %d variables allocated\n",
  518. mem_info_bytes(TYPE_VEC,0),mem_info_numvar(TYPE_VEC,0));
  519. notice("static memory test");
  520. mem_info_on(TRUE);
  521. mem_stat_mark(1);
  522. for (i=0; i < 100; i++)
  523. stat_test1(i);
  524. mem_stat_free(1);
  525. mem_stat_mark(1);
  526. for (i=0; i < 100; i++) {
  527. stat_test1(i);
  528. #ifdef COMPLEX
  529. stat_test4(i);
  530. #endif
  531. }
  532. mem_stat_mark(2);
  533. for (i=0; i < 100; i++)
  534. stat_test2(i);
  535. mem_stat_mark(3);
  536. #ifdef SPARSE
  537. for (i=0; i < 100; i++)
  538. stat_test3(i);
  539. #endif
  540. mem_info();
  541. mem_dump_list(stdout,0);
  542. mem_stat_free(1);
  543. mem_stat_free(3);
  544. mem_stat_mark(4);
  545. for (i=0; i < 100; i++) {
  546. stat_test1(i);
  547. #ifdef COMPLEX
  548. stat_test4(i);
  549. #endif
  550. }
  551. mem_stat_dump(stdout,0);
  552. if (mem_stat_show_mark() != 4) {
  553. errmesg("not 4 in mem_stat_show_mark()");
  554. }
  555. mem_stat_free(2);
  556. mem_stat_free(4);
  557. if (mem_stat_show_mark() != 0) {
  558. errmesg("not 0 in mem_stat_show_mark()");
  559. }
  560. /* add new list of types */
  561. mem_attach_list(FOO_LIST,FOO_NUM_TYPES,foo_type_name,
  562. foo_free_func,foo_info_sum);
  563. if (!mem_is_list_attached(FOO_LIST))
  564. errmesg("list FOO_LIST is not attached");
  565. mem_dump_list(stdout,FOO_LIST);
  566. foo_1 = foo_1_get(6);
  567. foo_2 = foo_2_get(3);
  568. for (i=0; i < foo_1->dim; i++)
  569. for (j=0; j < foo_1->fix_dim; j++)
  570. foo_1->a[i][j] = i+j;
  571. for (i=0; i < foo_2->dim; i++)
  572. for (j=0; j < foo_2->fix_dim; j++)
  573. foo_2->a[i][j] = i+j;
  574. printf(" foo_1->a[%d][%d] = %g\n",5,9,foo_1->a[5][9]);
  575. printf(" foo_2->a[%d][%d] = %g\n",2,1,foo_2->a[2][1]);
  576. mem_stat_mark(5);
  577. mem_stat_reg_list((void **)&foo_1,TYPE_FOO_1,FOO_LIST,__FILE__,__LINE__);
  578. mem_stat_reg_list((void **)&foo_2,TYPE_FOO_2,FOO_LIST,__FILE__,__LINE__);
  579. mem_stat_dump(stdout,FOO_LIST);
  580. mem_info_file(stdout,FOO_LIST);
  581. mem_stat_free_list(5,FOO_LIST);
  582. mem_stat_dump(stdout,FOO_LIST);
  583. if ( foo_1 != NULL )
  584. errmesg(" foo_1 is not released");
  585. if ( foo_2 != NULL )
  586. errmesg(" foo_2 is not released");
  587. mem_dump_list(stdout,FOO_LIST);
  588. mem_info_file(stdout,FOO_LIST);
  589. mem_free_vars(FOO_LIST);
  590. if ( mem_is_list_attached(FOO_LIST) )
  591. errmesg("list FOO_LIST is not detached");
  592. mem_info();
  593. #if REAL == FLOAT
  594. printf("# SINGLE PRECISION was used\n");
  595. #elif REAL == DOUBLE
  596. printf("# DOUBLE PRECISION was used\n");
  597. #endif
  598. #define ANSI_OR_VAR
  599. #ifndef ANSI_C
  600. #ifndef VARARGS
  601. #undef ANSI_OR_VAR
  602. #endif
  603. #endif
  604. #ifdef ANSI_OR_VAR
  605. printf("# you should get: \n");
  606. #if (REAL == FLOAT)
  607. printf("# type VEC: 276 bytes allocated, 3 variables allocated\n");
  608. #elif (REAL == DOUBLE)
  609. printf("# type VEC: 516 bytes allocated, 3 variables allocated\n");
  610. #endif
  611. printf("# and other types are zeros\n");
  612. #endif /*#if defined(ANSI_C) || defined(VARAGS) */
  613. printf("# Finished memory torture test\n");
  614. dmalloc_shutdown();
  615. return;
  616. }