Cypress CSC-1200T Betriebsanweisung Seite 54

  • Herunterladen
  • Zu meinen Handbüchern hinzufügen
  • Drucken
  • Seite
    / 124
  • Inhaltsverzeichnis
  • LESEZEICHEN
  • Bewertet. / 5. Basierend auf Kundenbewertungen
Seitenansicht 53
54 Cray T3E User’s Guide
6.3 Calling Fortran from C
Sometimes you need to call Fortran routines from C programs. In the
following, we calculate a matrix product using the routine SGEMM from
the Libsci library:
#include <stdio.h>
#include <fortran.h>
#define DGEMM SGEMM
#define l 450
#define m 500
#define n 550
main()
{
double a[n][l], b[l][m], ct[m][n];
int ll, mm, nn, i, j, k;
double alpha = 1.0;
double beta = 0.0;
void DGEMM();
char *transposed = "t";
_fcd ftran;
/* Initialize */
for(i=0;i<n;i++)
for(j=0;j<l;j++)
a[i][j] = i-j+2;
for(i=0;i<l;i++)
for(j=0;j<m;j++)
b[i][j] = 1/(double)(i+2*j+2);
ftran = _cptofcd(transposed, strlen(transposed));
ll=l;mm=m;nn=n;
DGEMM(ftran, ftran, &nn, &mm, &ll, &alpha, a, &ll,
b, &mm, &beta, ct, &nn);
printf("%.6f\n", ct[10][10]);
exit(0);
}
Note that on the T3E, the SGEMM routine performs the calculation using
64-bit real numbers, corresponding to the double type in C. Before mak-
ing the Libsci call, we need to convert the C strings into Fortran strings.
This is done with the function _cptofcd. We also use the type _fcd
defined in the header file fortran.h.
Seitenansicht 53
1 2 ... 49 50 51 52 53 54 55 56 57 58 59 ... 123 124

Kommentare zu diesen Handbüchern

Keine Kommentare