Advertisement
antiquekid3

XBARCONF Source

Jan 26th, 2014
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.84 KB | None | 0 0
  1. //filename: XBARCONF.C
  2. #include <windows.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include "xbarconf.h"
  6.  
  7. void main(void)
  8. {
  9.     char buffer[81];
  10.     BOOL Continue = TRUE;
  11.     int NumRows, NumCols;
  12.     int i, j, xbar;
  13.     FILE *f_out;
  14.  
  15.     /* Open output file DATA.DAT. */
  16.     if ((f_out = fopen("DATA.DAT", "wt")) == NULL)
  17.     {
  18.     puts("ERROR: Could not create data file DATA.DAT!");
  19.     puts("       Aborting...");
  20.     exit(1);
  21.     }
  22.  
  23.     /* Get mesh # of rows. */
  24.     while (Continue)
  25.     {
  26.     printf ("Enter the # of ROWS in the mesh: ");
  27.     gets(buffer);
  28.     if (sscanf(buffer, "%d", &NumRows))
  29.     {
  30.         if ((NumRows < 2) || (NumRows > 8))
  31.         puts("Entry out of range: 2 <= # of ROWS <= 8\n");
  32.         else
  33.         Continue = FALSE;
  34.     }
  35.     else
  36.         puts("\nIllegal entry!\n");
  37.     }
  38.     NumRows--;
  39.  
  40.     /* Get mesh # of cols. */
  41.     Continue = TRUE;
  42.     while (Continue)
  43.     {
  44.     printf ("Enter the # of COLUMNS in the mesh: ");
  45.     gets(buffer);
  46.     if (sscanf(buffer, "%d", &NumCols))
  47.     {
  48.         if ((NumCols < 2) || (NumCols > 8))
  49.         puts("Entry out of range: 2 <= # of COLUMNS <= 8\n");
  50.         else
  51.         Continue = FALSE;
  52.     }
  53.     else
  54.         puts("\nIllegal entry!\n");
  55.     }
  56.     NumCols--;
  57.  
  58.     /* Tell configuration software to reset all crossbars. */
  59.     fputs("1 16\n", f_out);
  60.  
  61.     /* Generate crossbar configuration on the fly. */
  62.     for (i=0; i<=NumRows; i++)
  63.     for (j=0; j<8; j++)
  64.     {
  65.         xbar = 2*j + (1 - (i/4));
  66.  
  67.         /* Generate special case horizontal link for ROOT processor. */
  68.         if ((xbar == 1) && (i == 0))
  69.         fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][1], east[0]);
  70.  
  71.         /* Set horizontal links if not ROOT or column 7 and a transputer */
  72.         /* is to be in this position. */
  73.         else if ((j <= NumCols) && (j < 7))
  74.         {
  75.         fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][0], south[i]);
  76.         fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][1], east[i]);
  77.         }
  78.  
  79.         /* Set horizontal links if crossbar is to be in this position and */
  80.         /* not column 7. */
  81.         else if ((j > NumCols) && (j < 7))
  82.         fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], east[i]);
  83.  
  84.         /* Set wrap-around link for column 7. */
  85.         else /* i.e. column 7. */
  86.         {
  87.         /* Generate wrap-around through crossbar only. */
  88.         if (NumCols < 7)
  89.         {
  90.             /* Generate special case wrap-around for row 4. */
  91.             if (i == 3)
  92.             fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], west[1]);
  93.             /* Generate normal wrap-around for all other rows except for row 7. */
  94.             else if (i != 7)
  95.             fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], east[i+1]);
  96.         }
  97.         /* Generate wrap-around from transputer through crossbar. */
  98.         else /* i.e. NumCols = 7. */
  99.         {
  100.             /* Generate special case wrap-around for 4th row. */
  101.             if (i == 3)
  102.             {
  103.             fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], proc[i][0]);
  104.             fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][1], west[1]);
  105.             }
  106.             /* Generate normal wrap-around for all other rows except row 7. */
  107.             else
  108.             {
  109.             fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], proc[i][0]);
  110.             /* Don't generate horizontal wrap for 8th row. */
  111.             if (i != 7)
  112.                 fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][1], east[i+1]);
  113.             }
  114.         }
  115.         }
  116.     }
  117.  
  118.     /* Generate the vertical links. */
  119.     for (i=0; i<=NumRows; i++)
  120.     for (j=0; j<=NumCols; j++)
  121.     {
  122.         xbar = 2*j + (1 - (i/4));
  123.  
  124.         /* Do not use WEST-WEST connections if NumRows <= 3. */
  125.         if (NumRows <= 3)
  126.         {
  127.         /* Generate vertical wrap-around for vertical links. */
  128.         if ((i == 0) && (NumRows > 1))
  129.             fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], proc[NumRows][3]);
  130.         else if (i != 0)
  131.             fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], proc[i-1][3]);
  132.         }
  133.         /* Use WEST-WEST connections if NumRows > 3. */
  134.         else
  135.         {
  136.         /* Generate PROC-WEST connections for rows 0 and 4. */
  137.         if ((i == 0) || (i == 4))
  138.         {
  139.             fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], (i == 4) ? west[0] : west[2]);
  140.             /* Generate PROC-WEST connection if this row == NumRows. */
  141.             if (i == NumRows)
  142.             fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][3], west[2]);
  143.         }
  144.         /* Generate PROC-WEST connections for row 3. */
  145.         else if (i == 3)
  146.         {
  147.             fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], proc[i-1][3]);
  148.             fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][3], west[0]);
  149.         }
  150.         /* Generate normal PROC-PROC connections for all other rows. */
  151.         else
  152.         {
  153.             fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], proc[i-1][3]);
  154.             /* Generate PROC-WEST connection if this row == NumRows. */
  155.             if (i == NumRows)
  156.             fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][3], west[2]);
  157.         }
  158.         }
  159.     }
  160.  
  161.     /* Generate special case wrap-around for proc4 in row 3 column 7. */
  162.     if (NumRows > 3)
  163.         fprintf(f_out, "%2d %2d %2d\n", 15, west[1], east[0]);
  164.  
  165.     /* Close data file DATA.DAT. */
  166.     fclose(f_out);
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement