Guest User

ddi_fortran.c

a guest
Mar 24th, 2021
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 26.58 KB | None | 0 0
  1. /* -------------------------------------------------------------------- *\
  2. * Distributed Data Interface
  3. * ==========================
  4. *
  5. * FORTRAN interface. The subroutines in this file named F77_XXXXX are
  6. * converted to the proper FORTRAN external by the F77_Extern macro and
  7. * the defines in the ddi_fortran.h header file.
  8. *
  9. * Author: Ryan M. Olson
  10. * 18 May 14 - AG - a few more GDDI functions exposed to Fortran
  11. \* -------------------------------------------------------------------- */
  12. # include "ddi_base.h"
  13. # include "ddi_arr.h"
  14. # include "ddi_fortran.h"
  15.  
  16. /* ----------------------------- *\
  17. System Specific FORTRAN fixes
  18. \* ----------------------------- */
  19. # if (defined CRAY)
  20. # define iargc_ IARGC
  21. # define getarg_ GETARG
  22. # endif
  23.  
  24. /* ----------------------------------------- *\
  25. Extern subroutines from FORTRAN libraries
  26. \* ----------------------------------------- */
  27. extern int iargc_();
  28. extern char *getarg_(int *,char *,int);
  29.  
  30.  
  31. /* ---------------------------- *\
  32. FORTRAN Wrapper for DDI_Init
  33. \* ---------------------------- */
  34. void F77_Init() {
  35. int i,j,lenmax=256,argc=iargc_();
  36. char **argv = NULL;
  37. char arg[256];
  38.  
  39. STD_DEBUG((stdout," DDI: Entering F77 DDI_Init.\n"))
  40.  
  41. /* -------------------------- *\
  42. Get command line arguments
  43. \* -------------------------- */
  44. if(argc) {
  45. argc++;
  46. argv = Malloc(argc*sizeof(char*));
  47. for(i=0; i<argc; i++) {
  48. for(j=0; j<256; j++) arg[j]=' ';
  49.  
  50. # if defined CRAY
  51. getarg_(&i,arg,&lenmax);
  52. # else
  53. getarg_(&i,arg,lenmax);
  54. # endif
  55.  
  56. for(j=0; j<256 && arg[j] != ' '; j++);
  57. arg[j] = 0;
  58. argv[i] = (char *) strdup(arg);
  59. }
  60. }
  61.  
  62. MAX_DEBUG((stdout," DDI: Calling DDI_Init.\n"))
  63.  
  64. /* -------------- *\
  65. Initialize DDI
  66. \* -------------- */
  67. DDI_Init(argc,argv);
  68.  
  69. }
  70.  
  71.  
  72. /* ---------------------------- *\
  73. FORTRAN Wrapper for DDI_PBeg
  74. \* ---------------------------- */
  75. /* this deprecated name is just mapped onto F77_Init */
  76. void F77_PBeg(int_f77 *nwdvar) {
  77. F77_Init();
  78. }
  79.  
  80.  
  81. /* -------------------------------- *\
  82. FORTRAN Wrapper for DDI_Finalize
  83. \* -------------------------------- */
  84. void F77_Finalize() {
  85. DDI_Finalize();
  86. }
  87.  
  88.  
  89. /* ---------------------------- *\
  90. FORTRAN Wrapper for DDI_PEnd
  91. \* ---------------------------- */
  92. /* this deprecated name is just mapped onto DDI_Finalize */
  93. void F77_PEnd(int_f77 *status) {
  94. if(*status == 1) Fatal_error(911);
  95. DDI_Finalize();
  96. }
  97.  
  98.  
  99. /* ----------------------------- *\
  100. FORTRAN Wrapper for DDI_NProc
  101. \* ----------------------------- */
  102. void F77_NProc(int_f77* np, int_f77* me) {
  103. int ddinp,ddime;
  104. DDI_NProc(&ddinp,&ddime);
  105. *np = (int_f77) ddinp;
  106. *me = (int_f77) ddime;
  107. }
  108.  
  109.  
  110. /* ----------------------------- *\
  111. FORTRAN Wrapper for DDI_NProc_comm
  112. \* ----------------------------- */
  113. void F77_NProc_comm(const int_f77* commid, int_f77* np, int_f77* me) {
  114. int ddinp,ddime;
  115. DDI_NProc_comm(*commid,&ddinp,&ddime);
  116. *np = (int_f77) ddinp;
  117. *me = (int_f77) ddime;
  118. }
  119.  
  120.  
  121. /* ----------------------------- *\
  122. FORTRAN Wrapper for DDI_NNode
  123. \* ----------------------------- */
  124. void F77_NNode(int_f77* np, int_f77* me) {
  125. int ddinp,ddime;
  126. DDI_NNode(&ddinp,&ddime);
  127. *np = (int_f77) ddinp;
  128. *me = (int_f77) ddime;
  129. }
  130.  
  131.  
  132. /* ---------------------------- *\
  133. FORTRAN Wrapper for DDI_Send
  134. \* ---------------------------- */
  135. void F77_Send(void *buff,int_f77 *size,int_f77 *to) {
  136. size_t isize = (size_t) *size;
  137. int ito = (int) *to;
  138. DDI_Send(buff,isize,ito);
  139. }
  140.  
  141.  
  142. /* ---------------------------- *\
  143. FORTRAN Wrapper for DDI_Recv
  144. \* ---------------------------- */
  145. void F77_Recv(void *buff,int_f77 *size,int_f77* from) {
  146. size_t isize = (size_t) *size;
  147. int ifrom = (int) *from;
  148. DDI_Recv(buff,isize,ifrom);
  149. }
  150.  
  151.  
  152. /* ------------------------------ *\
  153. FORTRAN Wrapper for DDI_Memory
  154. \* ------------------------------ */
  155. /* 1st and 3rd argument were used by DDI version 1,
  156. * and are kept for backwards compatibility.
  157. * Now, only the middle argument is needed, and should
  158. * be in units of MWords, meaning 1d+6 * 8 bytes.
  159. */
  160. void F77_Memory(int_f77 *mem_rep, int_f77 *mem_ddi, int_f77 *exetyp) {
  161. size_t size = (size_t) *mem_ddi;
  162. DDI_Memory(size);
  163. }
  164.  
  165.  
  166. /* ------------------------------ *\
  167. FORTRAN Wrapper for DDI_Output
  168. \* ------------------------------ */
  169. /*
  170. 0 means suppress output, presently limited to ddi_create messages
  171. 1 means print output
  172. */
  173. void F77_Output(int_f77 *value) {
  174. int ivalue = (int) *value;
  175. DDI_Output(ivalue);
  176. }
  177.  
  178.  
  179. /* ----------------------------- *\
  180. FORTRAN Wrapper for DDI_Level
  181. \* ----------------------------- */
  182. void F77_Level(int_f77 *implementation) {
  183. /*
  184. 0 means serial
  185. 1 means distributed memory, but no subgroups
  186. 2 means distributed memory, and subgroups (full version)
  187. */
  188. *implementation = 2;
  189. }
  190.  
  191.  
  192. /* ------------------------------ *\
  193. FORTRAN Wrapper for DDI_Create
  194. \* ------------------------------ */
  195. void F77_Create(int_f77 *idim, int_f77 *jdim, int_f77 *handle) {
  196. int ihandle;
  197. DDI_Create( (int) *idim, (int) *jdim, &ihandle );
  198. *handle = (int_f77) ihandle;
  199. }
  200.  
  201.  
  202. /* ------------------------------- *\
  203. FORTRAN Wrapper for DDI_Destroy
  204. \* ------------------------------- */
  205. void F77_Destroy(int_f77 *handle) {
  206. int ihandle = (int) *handle;
  207. DDI_Destroy(ihandle);
  208. }
  209.  
  210. /* ------------------------------- *\
  211. FORTRAN Wrapper for DDI_Comm_destroy
  212. \* ------------------------------- */
  213. void F77_Comm_destroy(int_f77 *commid) {
  214. int icommid = (int) *commid;
  215. DDI_Comm_destroy(icommid);
  216. }
  217.  
  218. /* ---------------------------- *\
  219. FORTRAN Wrapper for DDI_Zero
  220. \* ---------------------------- */
  221. /* zero out the entire array */
  222. void F77_Zero(int_f77 *handle) {
  223. int ihandle = (int) *handle;
  224. DDI_Array_zero(ihandle);
  225. }
  226.  
  227.  
  228. /* ------------------------------- *\
  229. FORTRAN Wrapper for DDI_DISTRIB
  230. \* ------------------------------- */
  231. void F77_Distrib(int_f77 *handle, int_f77 *rank,
  232. int_f77 *ilo, int_f77 *ihi,
  233. int_f77 *jlo, int_f77 *jhi) {
  234. DDI_Patch Patch;
  235. DDI_DistribP((int) *handle,(int) *rank,&Patch);
  236.  
  237. *ilo = (int_f77) Patch.ilo + 1;
  238. *ihi = (int_f77) Patch.ihi + 1;
  239. *jlo = (int_f77) Patch.jlo + 1;
  240. *jhi = (int_f77) Patch.jhi + 1;
  241. }
  242.  
  243.  
  244. /* -------------------------------- *\
  245. FORTRAN Wrapper for DDI_NDISTRIB
  246. \* -------------------------------- */
  247. void F77_NDistrib(int_f77 *handle, int_f77 *rank,
  248. int_f77 *ilo, int_f77 *ihi,
  249. int_f77 *jlo, int_f77 *jhi) {
  250. DDI_Patch Patch;
  251. DDI_NDistribP((int) *handle,(int) *rank,&Patch);
  252.  
  253. *ilo = (int_f77) Patch.ilo + 1;
  254. *ihi = (int_f77) Patch.ihi + 1;
  255. *jlo = (int_f77) Patch.jlo + 1;
  256. *jhi = (int_f77) Patch.jhi + 1;
  257. }
  258.  
  259.  
  260. /* --------------------------- *\
  261. FORTRAN Wrapper for DDI_Get
  262. \* --------------------------- */
  263. void F77_Get(int_f77 *handle, int_f77 *ilo, int_f77 *ihi,
  264. int_f77 *jlo, int_f77 *jhi, void *buff) {
  265. DDI_Patch Patch;
  266.  
  267. # if defined WINTEL
  268. Patch.oper = DDI_GET_OP;
  269. # else
  270. Patch.oper = DDI_GET;
  271. # endif
  272. Patch.handle = (int) *handle;
  273. Patch.ilo = (int) *ilo - 1;
  274. Patch.ihi = (int) *ihi - 1;
  275. Patch.jlo = (int) *jlo - 1;
  276. Patch.jhi = (int) *jhi - 1;
  277.  
  278. DDI_GetP(Patch.handle,&Patch,buff);
  279. }
  280.  
  281. /* -------------------------------- *\
  282. FORTRAN Wrapper for DDI_Get_comm
  283. \* -------------------------------- */
  284. void F77_Get_comm(int_f77 *handle, int_f77 *ilo, int_f77 *ihi,
  285. int_f77 *jlo, int_f77 *jhi,
  286. void *buff, int_f77 *commid) {
  287. DDI_Patch Patch;
  288.  
  289. # if defined WINTEL
  290. Patch.oper = DDI_GET_OP;
  291. # else
  292. Patch.oper = DDI_GET;
  293. # endif
  294. Patch.handle = (int) *handle;
  295. Patch.ilo = (int) *ilo - 1;
  296. Patch.ihi = (int) *ihi - 1;
  297. Patch.jlo = (int) *jlo - 1;
  298. Patch.jhi = (int) *jhi - 1;
  299.  
  300. DDI_GetP_comm(Patch.handle,&Patch,buff,*commid);
  301. }
  302.  
  303. /* --------------------------- *\
  304. FORTRAN Wrapper for DDI_Put
  305. \* --------------------------- */
  306. void F77_Put(int_f77 *handle, int_f77 *ilo, int_f77 *ihi,
  307. int_f77 *jlo, int_f77 *jhi, void *buff) {
  308. DDI_Patch Patch;
  309.  
  310. # if defined WINTEL
  311. Patch.oper = DDI_PUT_OP;
  312. # else
  313. Patch.oper = DDI_PUT;
  314. # endif
  315. Patch.handle = (int) *handle;
  316. Patch.ilo = (int) *ilo - 1;
  317. Patch.ihi = (int) *ihi - 1;
  318. Patch.jlo = (int) *jlo - 1;
  319. Patch.jhi = (int) *jhi - 1;
  320.  
  321. DDI_PutP(Patch.handle,&Patch,buff);
  322. }
  323.  
  324. /* -------------------------------- *\
  325. FORTRAN Wrapper for DDI_Put_comm
  326. \* -------------------------------- */
  327. void F77_Put_comm(int_f77 *handle, int_f77 *ilo, int_f77 *ihi,
  328. int_f77 *jlo, int_f77 *jhi,
  329. void *buff, int_f77 *commid) {
  330. DDI_Patch Patch;
  331.  
  332. # if defined WINTEL
  333. Patch.oper = DDI_PUT_OP;
  334. # else
  335. Patch.oper = DDI_PUT;
  336. # endif
  337. Patch.handle = (int) *handle;
  338. Patch.ilo = (int) *ilo - 1;
  339. Patch.ihi = (int) *ihi - 1;
  340. Patch.jlo = (int) *jlo - 1;
  341. Patch.jhi = (int) *jhi - 1;
  342.  
  343. DDI_PutP_comm(Patch.handle,&Patch,buff,*commid);
  344. }
  345.  
  346. /* --------------------------- *\
  347. FORTRAN Wrapper for DDI_Acc
  348. \* --------------------------- */
  349. void F77_Acc(int_f77 *handle, int_f77 *ilo, int_f77 *ihi,
  350. int_f77 *jlo, int_f77 *jhi, void *buff) {
  351. DDI_Patch Patch;
  352. double alpha = (double)1.0;
  353.  
  354. # if defined WINTEL
  355. Patch.oper = DDI_ACC_OP;
  356. # else
  357. Patch.oper = DDI_ACC;
  358. # endif
  359. Patch.handle = (int) *handle;
  360. Patch.ilo = (int) *ilo - 1;
  361. Patch.ihi = (int) *ihi - 1;
  362. Patch.jlo = (int) *jlo - 1;
  363. Patch.jhi = (int) *jhi - 1;
  364.  
  365. DDI_AccP(Patch.handle,&Patch,alpha,buff);
  366. }
  367.  
  368. /* ------------------------------------ *\
  369. FORTRAN Wrapper for DDI_Scatter_Acc
  370. \* ------------------------------------ */
  371. void F77_Scatter_Acc(int_f77 *handle, int_f77 *nelem,long *ibuff, void *buff) {
  372. DDI_Scattered Scattered;
  373. double alpha = (double)1.0;
  374. # if defined WINTEL
  375. fprintf(stdout,"%s: DDI_Scatter_Acc for WINTEL not implemented.\n",DDI_Id());
  376. Fatal_error(911);
  377. # endif
  378. Scattered.oper = DDI_ACC;
  379. Scattered.handle = (int) *handle;
  380. Scattered.nelem = (int) *nelem;
  381. Scattered.alpha = alpha;
  382. DDI_Scatter_AccS(Scattered.handle,&Scattered,alpha,ibuff,buff);
  383. }
  384.  
  385. /* --------------------------- *\
  386. FORTRAN Wrapper for DDI_GetAcc
  387. \* --------------------------- */
  388. void F77_GetAcc(int_f77 *handle, int_f77 *ilo, int_f77 *ihi,
  389. int_f77 *jlo, int_f77 *jhi, void *buff) {
  390.  
  391. DDI_GetAcc(*handle,*ilo-1,*ihi-1,*jlo-1,*jhi-1,buff);
  392. }
  393.  
  394.  
  395. /* -------------------------------- *\
  396. FORTRAN Wrapper for DDI_DLBReset
  397. \* -------------------------------- */
  398. void F77_DLBReset() {
  399. DDI_DLBReset();
  400. }
  401.  
  402.  
  403. /* ------------------------------- *\
  404. FORTRAN Wrapper for DDI_DLBNext
  405. \* ------------------------------- */
  406. void F77_DLBNext(int_f77 *counter) {
  407. size_t icounter;
  408. DDI_DLBNext(&icounter);
  409. *counter = (int_f77) icounter;
  410. }
  411.  
  412.  
  413. /* ----------------------------- *\
  414. FORTRAN Wrapper for DDI_ISend
  415. \* ----------------------------- */
  416. void F77_ISend(void *buffer, int_f77 *size, int_f77 *to, int_f77 *req) {
  417. int ireq = 0;
  418. int ito = (int) *to;
  419. size_t isize = (size_t) *size;
  420. DDI_ISend(buffer,isize,ito,&ireq);
  421. *req = (int_f77) ireq;
  422. }
  423.  
  424.  
  425. /* ----------------------------- *\
  426. FORTRAN Wrapper for DDI_IRecv
  427. \* ----------------------------- */
  428. void F77_IRecv(void *buffer, int_f77 *size, int_f77 *from, int_f77 *req) {
  429. int ireq = 0;
  430. int ifrom = (int) *from;
  431. size_t isize = (size_t) *size;
  432. DDI_IRecv(buffer,isize,ifrom,&ireq);
  433. *req = (int_f77) ireq;
  434. }
  435.  
  436.  
  437. /* ---------------------------- *\
  438. FORTRAN Wrapper for DDI_Wait
  439. \* ---------------------------- */
  440. void F77_Wait(int_f77 *req) {
  441. int ireq = (int) *req;
  442. DDI_Wait(ireq);
  443. }
  444.  
  445.  
  446. /* ----------------------------- *\
  447. FORTRAN Wrapper for DDI_BCast
  448. \* ----------------------------- */
  449. void F77_BCast(int_f77* msgtag, char *type,
  450. void *buffer, int_f77 *len, int_f77 *root) {
  451. char t = *type;
  452. size_t size;
  453.  
  454. if(t == 'i' || t == 'I') size = (*len)*sizeof(int_f77);
  455. else if(t == 'f' || t == 'F') size = (*len)*sizeof(double);
  456. else {
  457. fprintf(stdout,"%s: Unknown type passed in DDI_BCast\n",DDI_Id());
  458. Fatal_error(911);
  459. }
  460.  
  461. DDI_BCast(buffer,size,(int)*root);
  462. }
  463.  
  464.  
  465. /* ----------------------------- *\
  466. FORTRAN Wrapper for DDI_GSumI
  467. \* ----------------------------- */
  468. void F77_GSumI(int_f77 *msgtag, void *buffer, int_f77 *len) {
  469. DDI_GSum(buffer,*len,sizeof(int_f77));
  470. }
  471.  
  472.  
  473. /* ----------------------------- *\
  474. FORTRAN Wrapper for DDI_GSumF
  475. \* ----------------------------- */
  476. void F77_GSumF(int_f77 *msgtag, void *buffer, int_f77 *len) {
  477. DDI_GSum(buffer,*len,0);
  478. }
  479.  
  480.  
  481. /* ---------------------------- *\
  482. FORTRAN Wrapper for DDI_Sync
  483. \* ---------------------------- */
  484. void F77_Sync(int_f77 *msgtag) {
  485. int tag = (int) *msgtag;
  486. DDI_Sync(tag);
  487. }
  488.  
  489.  
  490. /* ----------------------------- *\
  491. FORTRAN Wrapper for DDI_Debug
  492. \* ----------------------------- */
  493. void F77_Debug(int_f77 *flag) {
  494. int value = (int) *flag;
  495. DebugOutput(value);
  496. }
  497.  
  498.  
  499. /* ------------------------------------ *\
  500. FORTRAN Wrapper for DDI_Group_Create
  501. \* ------------------------------------ */
  502. void F77_Group_create(int_f77 *ngroups, int_f77 *world,
  503. int_f77 *group, int_f77 *master) {
  504. int handle,type=0;
  505. int ngrp = (int) *ngroups;
  506. int iw,ig,im;
  507. DDI_Group_create(ngrp,&iw,&ig,&im);
  508. *world = iw;
  509. *group = ig;
  510. *master = im;
  511. }
  512.  
  513.  
  514. /* ----------------------------- *\
  515. FORTRAN Wrapper for DDI_Scope
  516. \* ----------------------------- */
  517. void F77_Scope(int_f77 *scope) {
  518. int iscope = (int) *scope;
  519. DDI_Scope(iscope);
  520. }
  521.  
  522.  
  523. /* ------------------------------ *\
  524. FORTRAN Wrapper for DDI_AScope
  525. \* ------------------------------ */
  526. void F77_AScope(int_f77 *scope) {
  527. int iscope = (int) *scope;
  528. DDI_AScope(iscope);
  529. }
  530.  
  531.  
  532. /* --------------------------------- *\
  533. FORTRAN Wrapper for DDI_GDLBReset
  534. \* --------------------------------- */
  535. void F77_GDLBReset() {
  536. DDI_GDLBReset();
  537. }
  538.  
  539.  
  540. /* -------------------------------- *\
  541. FORTRAN Wrapper for DDI_GDLBNext
  542. \* -------------------------------- */
  543. void F77_GDLBNext(int_f77 *counter) {
  544. size_t value;
  545. DDI_GDLBNext(&value);
  546. *counter = (int_f77) value;
  547. }
  548.  
  549. /* --------------------------------- *\
  550. FORTRAN Wrapper for DDI_GDLBReset_inner
  551. \* --------------------------------- */
  552. void F77_GDLBReset_inner() {
  553. DDI_GDLBReset_inner();
  554. }
  555.  
  556.  
  557. /* -------------------------------- *\
  558. FORTRAN Wrapper for DDI_GDLBNext_inner
  559. \* -------------------------------- */
  560. void F77_GDLBNext_inner(int_f77 *counter) {
  561. size_t value;
  562. DDI_GDLBNext_inner(&value);
  563. *counter = (int_f77) value;
  564. }
  565.  
  566. /* --------------------------------- *\
  567. FORTRAN Wrapper for DDI_GDLBReset_inner
  568. \* --------------------------------- */
  569. void F77_DDI_get_dsid(int_f77 *type) {
  570. int typo=*type;
  571.  
  572. DDI_get_dsid(typo);
  573. }
  574.  
  575. /* ----------------------------- *\
  576. FORTRAN Wrapper for DDI_Ngroup
  577. \* ----------------------------- */
  578. void F77_NGroup(int_f77 *ngroups, int_f77 *mygroup) {
  579. int ngr, mygr;
  580.  
  581. DDI_NGroup(&ngr,&mygr);
  582. *ngroups = (int_f77) ngr;
  583. *mygroup = (int_f77) mygr;
  584. }
  585.  
  586.  
  587. /* ------------------------------------- *\
  588. FORTRAN Wrapper for DDI_Create_custom
  589. \* ------------------------------------- */
  590. void F77_Create_custom(int_f77 *idim, int_f77 *jdim,
  591. int_f77 *jcols, int_f77 *handle) {
  592. int ihandle,i,np,me;
  593. int ijcols[MAX_PROCESSORS];
  594. DDI_NProc(&np,&me);
  595. for(i=0; i<np; i++) ijcols[i] = (int) *jcols;
  596. DDI_Create_custom( (int) *idim, (int) *jdim, ijcols, &ihandle );
  597. *handle = (int_f77) ihandle;
  598. }
  599.  
  600.  
  601. /* ------------------------------------------- *\
  602. FORTRAN Wrapper for DDI_Group_create_custom
  603. \* ------------------------------------------- */
  604. void F77_Group_create_custom(int_f77 *ngroups, int_f77 *group_size,
  605. int_f77 *world, int_f77 *group,
  606. int_f77 *master) {
  607. int i,handle,type=0;
  608. int ngrp = (int) *ngroups;
  609. int grpsize[MAX_NODES];
  610. int iw,ig,im;
  611. for (i=0;i<ngrp;i++) grpsize[i]=(int)group_size[i];
  612. DDI_Group_create_custom(ngrp,grpsize,&iw,&ig,&im);
  613. *world = iw;
  614. *group = ig;
  615. *master = im;
  616. }
  617.  
  618.  
  619. /* ----------------------------------- *\
  620. FORTRAN Wrapper for DDI_Timer_reset
  621. \* ----------------------------------- */
  622. void F77_Timer_reset() {
  623. DDI_Timer_reset();
  624. }
  625.  
  626.  
  627. /* ------------------------------------ *\
  628. FORTRAN Wrapper for DDI_Timer_output
  629. \* ------------------------------------ */
  630. void F77_Timer_output() {
  631. DDI_Timer_output();
  632. }
  633.  
  634.  
  635. /* -------------------------------------- *\
  636. FORTRAN Wrapper for DDI_ProcDLB_create
  637. \* -------------------------------------- */
  638. void F77_ProcDLB_create(int_f77 *handle) {
  639. int hnd;
  640. DDI_ProcDLB_create(&hnd);
  641. *handle = (int_f77) hnd;
  642. }
  643.  
  644.  
  645. /* --------------------------------------- *\
  646. FORTRAN Wrapper for DDI_ProcDLB_destroy
  647. \* --------------------------------------- */
  648. void F77_ProcDLB_destroy(int_f77 *handle) {
  649. int hnd = (int) *handle;
  650. DDI_ProcDLB_destroy(hnd);
  651. }
  652.  
  653.  
  654. /* ------------------------------------- *\
  655. FORTRAN Wrapper for DDI_ProcDLB_reset
  656. \* ------------------------------------- */
  657. void F77_ProcDLB_reset(int_f77 *handle) {
  658. int hnd = (int) *handle;
  659. DDI_ProcDLB_reset(hnd);
  660. }
  661.  
  662.  
  663. /* ------------------------------------ *\
  664. FORTRAN Wrapper for DDI_ProcDLB_next
  665. \* ------------------------------------ */
  666. void F77_ProcDLB_next(int_f77 *handle, int_f77 *proc, int_f77 *counter) {
  667. int hnd = (int) *handle;
  668. int cpu = (int) *proc;
  669. size_t val = 0;
  670. DDI_ProcDLB_next(hnd,cpu,&val);
  671. *counter = (int_f77) val;
  672. }
  673.  
  674.  
  675. /* --------------------------------- *\
  676. FORTRAN Wrapper for DDI_SMP_NProc
  677. \* --------------------------------- */
  678. void F77_SMP_NProc(int_f77* np, int_f77* me) {
  679. int ddinp,ddime;
  680. DDI_SMP_NProc(&ddinp,&ddime);
  681. *np = (int_f77) ddinp;
  682. *me = (int_f77) ddime;
  683. }
  684.  
  685.  
  686. /* --------------------------------- *\
  687. FORTRAN Wrapper for DDI_SMP_BCast
  688. \* --------------------------------- */
  689. void F77_SMP_sync() {
  690. DDI_Comm *comm = Comm_find(DDI_COMM_WORLD);
  691. Comm_sync_smp(comm);
  692. }
  693.  
  694.  
  695. /* --------------------------------- *\
  696. FORTRAN Wrapper for DDI_SMP_BCast
  697. \* --------------------------------- */
  698. void F77_BCast_smp(int_f77* msgtag, char *type, void *buffer,
  699. int_f77 *len, int_f77 *root) {
  700. char t = *type;
  701. size_t size;
  702.  
  703. if(t == 'i' || t == 'I') size = (*len)*sizeof(int_f77);
  704. else if(t == 'f' || t == 'F') size = (*len)*sizeof(double);
  705. else {
  706. fprintf(stdout,"%s: Unknown type passed in DDI_BCast\n",DDI_Id());
  707. Fatal_error(911);
  708. }
  709.  
  710. DDI_BCast_smp(buffer,size,*root);
  711. }
  712.  
  713.  
  714. /* --------------------------------- *\
  715. FORTRAN Wrapper for DDI_SMP_GSumI
  716. \* --------------------------------- */
  717. void F77_GSumI_smp(int_f77 *msgtag, void *buffer, int_f77 *len) {
  718. DDI_GSum_smp(buffer,(size_t)*len,sizeof(int_f77));
  719. }
  720.  
  721.  
  722. /* --------------------------------- *\
  723. FORTRAN Wrapper for DDI_SMP_GSumF
  724. \* --------------------------------- */
  725. void F77_GSumF_smp(int_f77 *msgtag, void *buffer, int_f77 *len) {
  726. DDI_GSum_smp(buffer,(size_t)*len,0);
  727. }
  728.  
  729.  
  730. /* ------------------------------------- *\
  731. FORTRAN Wrapper for DDI_Masters_gsumi
  732. \* ------------------------------------- */
  733. void F77_GSumI_node(int_f77 *msgtag, void *buffer, int_f77 *len) {
  734. DDI_GSum_node(buffer,(size_t) *len,sizeof(int_f77) /*type*/);
  735. }
  736.  
  737.  
  738. /* ------------------------------------- *\
  739. FORTRAN Wrapper for DDI_Masters_gsumf
  740. \* ------------------------------------- */
  741. void F77_GSumF_node(int_f77 *msgtag, void *buffer, int_f77 *len) {
  742. DDI_GSum_node(buffer,(size_t) *len,0 /*type*/);
  743. }
  744.  
  745.  
  746. /* ------------------------------------- *\
  747. FORTRAN Wrapper for DDI_Masters_bcast
  748. \* ------------------------------------- */
  749. void F77_BCast_node(int_f77* msgtag, char *type, void *buffer,
  750. int_f77 *len, int_f77 *root) {
  751. char t = *type;
  752. size_t size;
  753.  
  754. if(t == 'i' || t == 'I') size = (*len)*sizeof(int_f77);
  755. else if(t == 'f' || t == 'F') size = (*len)*sizeof(double);
  756. else {
  757. fprintf(stdout,"%s: Unknown type passed in DDI_BCast\n",DDI_Id());
  758. Fatal_error(911);
  759. }
  760.  
  761. DDI_BCast_node(buffer,size,(int)*root);
  762. }
  763.  
  764. /* ---------------------- *\
  765. DDI_SMP_Create wrapper
  766. \* ---------------------- */
  767. void F77_SMP_Create(int_f77 *size, int_f77 *handle) {
  768. int myhndl = 0;
  769. size_t mysize = (size_t) *size;
  770. mysize *= sizeof(double);
  771. *handle = (int_f77) SMP_create(mysize);
  772. }
  773.  
  774.  
  775. /* ----------------------- *\
  776. DDI_SMP_Destroy wrapper
  777. \* ----------------------- */
  778. void F77_SMP_Destroy(int_f77 *handle) {
  779. DDI_SMP_Destroy((int) *handle);
  780. }
  781.  
  782.  
  783. /* ---------------------- *\
  784. DDI_SMP_Offset wrapper
  785. \* ---------------------- */
  786. void F77_SMP_Offset(int_f77 *handle, void *addr, int_f77 *offset) {
  787.  
  788. unsigned INT_SIZE loc_addr_val = (unsigned INT_SIZE) addr;
  789. unsigned INT_SIZE smp_addr_val = (unsigned INT_SIZE) DDI_SMP_Array(*handle);
  790.  
  791. *offset = smp_addr_val - loc_addr_val;
  792. /*
  793. fprintf(stdout,"%s: SMP HANDLE %i = %x\n",DDI_Id(),
  794. *handle,DDI_SMP_Addr(*handle));
  795. fflush(stdout);
  796. */
  797. /*
  798. if(*offset % 8) {
  799. printf("Warning, SMP OFFSET not one WORD boundaries!!!\n");
  800. }
  801. */
  802. }
  803.  
  804.  
  805. /* --------------------- *\
  806. DDI_Addr_test wrapper
  807. \* --------------------- */
  808. void F77_Addr_test(void *addr) {
  809. fprintf(stdout,"%s: addr=%lx\n",DDI_Id(),(unsigned long)addr);
  810. fflush(stdout);
  811. }
  812.  
  813.  
  814. /* FORTRAN bindings for various array operations */
  815.  
  816. void F77_ARR_zero(int_f77 *dA, int_f77 *dAi, int_f77 *dAi2,
  817. int_f77 *dAj, int_f77 *dAj2)
  818. {
  819. DDI_ARR_zero((int)*dA, (int)*dAi - 1, (int)*dAi2 - 1,
  820. (int)*dAj - 1, (int)*dAj2 - 1);
  821. }
  822.  
  823. void F77_ARR_fill(int_f77 *dA, int_f77 *dAi, int_f77 *dAi2,
  824. int_f77 *dAj, int_f77 *dAj2, void *alpha)
  825. {
  826. DDI_ARR_fill((int)*dA, (int)*dAi - 1, (int)*dAi2 - 1,
  827. (int)*dAj - 1, (int)*dAj2 - 1, *(double*)alpha);
  828. }
  829.  
  830. void F77_ARR_scale(int_f77 *dA, int_f77 *dAi, int_f77 *dAi2,
  831. int_f77 *dAj, int_f77 *dAj2, void *alpha)
  832. {
  833. DDI_ARR_scale((int)*dA, (int)*dAi - 1, (int)*dAi2 - 1,
  834. (int)*dAj - 1, (int)*dAj2 - 1, *(double*)alpha);
  835. }
  836.  
  837. void F77_ARR_min(int_f77 *dA, int_f77 *dAi, int_f77 *dAi2,
  838. int_f77 *dAj, int_f77 *dAj2,
  839. void *alpha, int_f77 *i, int_f77 *j)
  840. {
  841. int index[2];
  842. DDI_ARR_min((int)*dA, (int)*dAi - 1, (int)*dAi2 - 1,
  843. (int)*dAj - 1, (int)*dAj2 - 1, (double*)alpha, index);
  844. *i = (int_f77)index[0] + 1;
  845. *j = (int_f77)index[1] + 1;
  846. }
  847.  
  848. void F77_ARR_max(int_f77 *dA, int_f77 *dAi, int_f77 *dAi2,
  849. int_f77 *dAj, int_f77 *dAj2,
  850. void *alpha, int_f77 *i, int_f77 *j)
  851. {
  852. int index[2];
  853. DDI_ARR_max((int)*dA, (int)*dAi - 1, (int)*dAi2 - 1,
  854. (int)*dAj - 1, (int)*dAj2 - 1, (double*)alpha, index);
  855. *i = (int_f77)index[0] + 1;
  856. *j = (int_f77)index[1] + 1;
  857. }
  858.  
  859. void F77_ARR_dot(int_f77 *dA, int_f77 *dAi, int_f77 *dAi2,
  860. int_f77 *dAj, int_f77 *dAj2,
  861. int_f77 *dB, int_f77 *dBi, int_f77 *dBi2,
  862. int_f77 *dBj, int_f77 *dBj2, void *x)
  863. {
  864. DDI_ARR_dot((int)*dA, (int)*dAi - 1, (int)*dAi2 - 1,
  865. (int)*dAj - 1, (int)*dAj2 - 1,
  866. (int)*dB, (int)*dBi - 1, (int)*dBi2 - 1,
  867. (int)*dBj - 1, (int)*dBj2 - 1, x);
  868. }
  869.  
  870. void F77_ARR_add(int_f77 *dA, int_f77 *dAi, int_f77 *dAi2,
  871. int_f77 *dAj, int_f77 *dAj2, void *alpha,
  872. int_f77 *dB, int_f77 *dBi, int_f77 *dBi2,
  873. int_f77 *dBj, int_f77 *dBj2, void *beta,
  874. int_f77 *dC, int_f77 *dCi, int_f77 *dCi2,
  875. int_f77 *dCj, int_f77 *dCj2)
  876. {
  877. DDI_ARR_add((int)*dA, (int)*dAi - 1, (int)*dAi2 - 1,
  878. (int)*dAj - 1, (int)*dAj2 - 1, *(double*)alpha,
  879. (int)*dB, (int)*dBi - 1, (int)*dBi2 - 1,
  880. (int)*dBj - 1, (int)*dBj2 - 1, *(double*)beta,
  881. (int)*dC, (int)*dCi - 1, (int)*dCi2 - 1,
  882. (int)*dCj - 1, (int)*dCj2 - 1);
  883. }
  884.  
  885. void F77_ARR_acc(int_f77 *dA, int_f77 *dAi, int_f77 *dAi2,
  886. int_f77 *dAj, int_f77 *dAj2,
  887. void *alpha, void *buf)
  888. {
  889. DDI_ARR_acc((int)*dA, (int)*dAi - 1, (int)*dAi2 - 1,
  890. (int)*dAj - 1, (int)*dAj2 - 1, *(double*)alpha, buf);
  891. }
  892.  
  893. /** @brief Prints current status of DDI internal memory pool (for debugging) */
  894. void F77_Memory_map_dbgprint()
  895. {
  896. DDI_Memory_map_dbgprint(stdout);
  897. fflush(stdout);
  898. }
  899.  
  900. /** @brief Reports available memory in doubles */
  901. void F77_Memory_avail(int_f77* size)
  902. {
  903. size_t sz;
  904. DDI_Memory_avail(&sz);
  905. *size=sz/sizeof(double);
  906. }
  907.  
Advertisement
Add Comment
Please, Sign In to add comment