Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //filename: XBARCONF.C
- #include <windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "xbarconf.h"
- void main(void)
- {
- char buffer[81];
- BOOL Continue = TRUE;
- int NumRows, NumCols;
- int i, j, xbar;
- FILE *f_out;
- /* Open output file DATA.DAT. */
- if ((f_out = fopen("DATA.DAT", "wt")) == NULL)
- {
- puts("ERROR: Could not create data file DATA.DAT!");
- puts(" Aborting...");
- exit(1);
- }
- /* Get mesh # of rows. */
- while (Continue)
- {
- printf ("Enter the # of ROWS in the mesh: ");
- gets(buffer);
- if (sscanf(buffer, "%d", &NumRows))
- {
- if ((NumRows < 2) || (NumRows > 8))
- puts("Entry out of range: 2 <= # of ROWS <= 8\n");
- else
- Continue = FALSE;
- }
- else
- puts("\nIllegal entry!\n");
- }
- NumRows--;
- /* Get mesh # of cols. */
- Continue = TRUE;
- while (Continue)
- {
- printf ("Enter the # of COLUMNS in the mesh: ");
- gets(buffer);
- if (sscanf(buffer, "%d", &NumCols))
- {
- if ((NumCols < 2) || (NumCols > 8))
- puts("Entry out of range: 2 <= # of COLUMNS <= 8\n");
- else
- Continue = FALSE;
- }
- else
- puts("\nIllegal entry!\n");
- }
- NumCols--;
- /* Tell configuration software to reset all crossbars. */
- fputs("1 16\n", f_out);
- /* Generate crossbar configuration on the fly. */
- for (i=0; i<=NumRows; i++)
- for (j=0; j<8; j++)
- {
- xbar = 2*j + (1 - (i/4));
- /* Generate special case horizontal link for ROOT processor. */
- if ((xbar == 1) && (i == 0))
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][1], east[0]);
- /* Set horizontal links if not ROOT or column 7 and a transputer */
- /* is to be in this position. */
- else if ((j <= NumCols) && (j < 7))
- {
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][0], south[i]);
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][1], east[i]);
- }
- /* Set horizontal links if crossbar is to be in this position and */
- /* not column 7. */
- else if ((j > NumCols) && (j < 7))
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], east[i]);
- /* Set wrap-around link for column 7. */
- else /* i.e. column 7. */
- {
- /* Generate wrap-around through crossbar only. */
- if (NumCols < 7)
- {
- /* Generate special case wrap-around for row 4. */
- if (i == 3)
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], west[1]);
- /* Generate normal wrap-around for all other rows except for row 7. */
- else if (i != 7)
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], east[i+1]);
- }
- /* Generate wrap-around from transputer through crossbar. */
- else /* i.e. NumCols = 7. */
- {
- /* Generate special case wrap-around for 4th row. */
- if (i == 3)
- {
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], proc[i][0]);
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][1], west[1]);
- }
- /* Generate normal wrap-around for all other rows except row 7. */
- else
- {
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, south[i], proc[i][0]);
- /* Don't generate horizontal wrap for 8th row. */
- if (i != 7)
- fprintf(f_out,"%2d %2d %2d\n", xbar+1, proc[i][1], east[i+1]);
- }
- }
- }
- }
- /* Generate the vertical links. */
- for (i=0; i<=NumRows; i++)
- for (j=0; j<=NumCols; j++)
- {
- xbar = 2*j + (1 - (i/4));
- /* Do not use WEST-WEST connections if NumRows <= 3. */
- if (NumRows <= 3)
- {
- /* Generate vertical wrap-around for vertical links. */
- if ((i == 0) && (NumRows > 1))
- fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], proc[NumRows][3]);
- else if (i != 0)
- fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], proc[i-1][3]);
- }
- /* Use WEST-WEST connections if NumRows > 3. */
- else
- {
- /* Generate PROC-WEST connections for rows 0 and 4. */
- if ((i == 0) || (i == 4))
- {
- fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], (i == 4) ? west[0] : west[2]);
- /* Generate PROC-WEST connection if this row == NumRows. */
- if (i == NumRows)
- fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][3], west[2]);
- }
- /* Generate PROC-WEST connections for row 3. */
- else if (i == 3)
- {
- fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], proc[i-1][3]);
- fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][3], west[0]);
- }
- /* Generate normal PROC-PROC connections for all other rows. */
- else
- {
- fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][2], proc[i-1][3]);
- /* Generate PROC-WEST connection if this row == NumRows. */
- if (i == NumRows)
- fprintf(f_out, "%2d %2d %2d\n", xbar+1, proc[i][3], west[2]);
- }
- }
- }
- /* Generate special case wrap-around for proc4 in row 3 column 7. */
- if (NumRows > 3)
- fprintf(f_out, "%2d %2d %2d\n", 15, west[1], east[0]);
- /* Close data file DATA.DAT. */
- fclose(f_out);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement