GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 01-May-2007, 09:01
trainz13 trainz13 is offline
New Member
 
Join Date: May 2007
Posts: 3
trainz13 is on a distinguished road

MPI with C (Solving Linear Equation using Gauss-Seidel Iteration)


Hello

firstly this code is for those who familiar with MPI message passing routine.
this code generally is for solving linear equation system using gauss-seidel iteration method using C and MPI routines.

there some syntax error. can anyone help me identify it and tell me how to correct it

I was using visual c++ 6.0. I've already attached workspace containing the code and a manual.

i can provide you mpi tool (mpich.nt.1.2.5) needed
just email me at trainz13@yahoo.com

CPP / C++ / C Code:
/****************************************************************************
 * Gauss_Seidel2.cpp                                                        *
 *                                                                          *
 * Solves a system of linear equations using Gauss-Seidel iteration         *
 *                                                                          *
 *    code with /* is doesn't have compilation error but the solution for   *
 *    gauss-seidel iteration was wrong.                                     *
 *    sample test that i use is matrix A = 7 -2 1  2     B = 3              *
 *                                         2  8 3  1        -2              *
 *                                        -1  0 5  2         5              *
 *                                         0  2 -1 4         4              *
 *                                                                          *
 *    the solution for x should be print like this : -0.2  -0.5 0.4 1.4     *                                        
 ****************************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
#include <math.h>

#define Swap(x,y) {float* temp; temp = x; x = y; y = temp;}

#define MAX 12
/* #define tolerance 0.0001 */

float Distance(float x[], float y[], int n) {
    int i;
    float sum = 0.0;

    for (i = 0; i < n; i++) {
        sum = sum + (x[i] - y[i])*(x[i] - y[i]);
    }
    return (float)sqrt(sum);
}
// This will read the matrix 
void Read_matrix(char* prompt, float A[MAX][MAX], int n, int my_rank, int proc) 
{
    int i, j;
    float temp[MAX][MAX];
    int n_bar;
 
    n_bar = n/proc;

    // Fill dummy entries in temp with zeroes
    for (i = 0; i < n; i++)
        for (j = n; j < MAX; j++)
            temp[i][j] = 0.0;

    if (my_rank == 0) {
        printf("%s\n", prompt);
        for (i = 0; i < n; i++)
            for (j = 0; j < n; j++)
                scanf("%f",&temp[i][j]);
    }    
    //Scatter temp to A from process 0
    MPI_Scatter(temp, n_bar*MAX, MPI_FLOAT, A, n_bar*MAX, MPI_FLOAT, 0, MPI_COMM_WORLD);
}
//This will read the vector x
void Read_vector(char*  prompt, float x[], int n, int my_rank, int proc) 
{
    int   i;
    float temp[MAX];
    int   n_bar;
    
    n_bar = n/proc;

    if (my_rank == 0) 
	{
        printf("%s\n", prompt);
        for (i = 0; i < n; i++)
            scanf("%f", &temp[i]);
    }
    //Scatter temp to x from process 0
    MPI_Scatter(temp, n_bar, MPI_FLOAT, x, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);
}

void main(int argc, char* argv[]) 
{
	//Main Process
    int proc;
    int my_rank;
    float A[MAX][MAX];
    float x[MAX];
    float B[MAX];
    int n;
    //Float tolerance;
    int max_iteration;

	//Gauss-Seidel Iteration Function
/*	int i_local, i_global, j;
    int n_bar;
    int iteration_num;
    float x_temp1[MAX];
    float x_temp2[MAX];
    float* k_previous;
    float* k_current; */

    //Gauss-Seidel Iteration Function
    int iteration = 0;
    int i, j;
    float last_iteration[MAX];
    float sigma1, sigma2;
    float precesion;
    int k;
	//Displaying arrays
	//int i;
	float temp[MAX];

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &proc);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    if (my_rank == 0) 
	{
        system("cls");
	    printf("-----------------------------------------------------------------------------\n");
	    printf("Program will perform Gauss-Seidel Iteration Method to solve Linear Equation  \n");
	    printf("-----------------------------------------------------------------------------\n");        
        printf("Enter variable n and max number of iterations:  \n\n");
        scanf("%d %d", &n, &max_iteration);
    }
    //Broadcast n & maximum iteration to all other process
    MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Bcast(&max_iteration, 1, MPI_INT, 0, MPI_COMM_WORLD);

    n_bar = n/proc;

    //Fill the matrix and the vector
    Read_matrix("\nInsert the variable for the matrix A \n", A, n, my_rank, proc);
    Read_vector("\nEnter the right-hand side of B \n", B, n, my_rank, proc);

    /*// Initialize x
    MPI_Allgather(B, n_bar, MPI_FLOAT, x_temp1, n_bar, MPI_FLOAT, MPI_COMM_WORLD); */
    MPI_Allgather(B, n_bar, MPI_FLOAT, k, n_bar, MPI_FLOAT, MPI_COMM_WORLD);
    /* k_current = x_temp1;
    k_previous = x_temp2; 

    iteration_num = 0;
    do 
	{
		iteration_num++;
        
        //Interchange k_previous and k_current
        Swap(k_previous, k_current);
        for (i_local = 0; i_local < n_bar; i_local++)	//Send process to each processors
		{
			i_global = i_local + my_rank*n_bar;

			x[i_local] = B[i_local];
            
			for (j = 0; j < i_global; j++)
                x[i_local] = x[i_local] - A[i_local][j]*k_previous[j]+1;
            
			for (j = 0; j > i_global; j++)
                x[i_local] = x[i_local] - A[i_local][j]*k_previous[j];
			for (j = i_global+1; j < n; j++)
                x[i_local] = x[i_local] - A[i_local][j]*k_previous[j];
            
			x[i_local] = x[i_local] / A[i_local][i_global];
			
			if(iteration_num==1)
				x[i_local] = 0;   */
				
          
    //calculate requested precision and maximum iterations
    precision = pow(10.0, -(float)k);
    max_iterations = (int)pow(10.0, (float)k);

    // initialize last_iteration matrix to zero
    for (i=0; i<MAX; i++)
        last_iteration[i] = 0.0;

    //calculate iterations
    do
    {
        //calculate the next iteration
        for (i=0; i<MAX; i++)
        {
            //compute Sigma(j:j<i)(a(i,j) * x(j)(n))
            sigma1 = 0.0;
            for (j=0; j<i; j++)
                sigma1 += A[i][j] * x[j];

            //compute Sigma(j:j>i)(a(i,j) * x(j)(n-1))
            sigma2 = 0.0;
            for (j=i+1; j<MAX; j++)
                sigma2 += A[i][j] * last_iteration[j];

            //compute the value of this iteration
            x[i] = (B[i] - sigma1 - sigma2) / A[i][i];
        }


        //figure out if we're done yet 
        done = TRUE;
        for (i=0; i<MAX; i++)
            done &= fabs(x[i] - last_iteration[i]) < (precesion * fabs(x[i]));

        //if any entry is greater than ELEMENT_MAX, an overflow has occurred,so abort
        for (i=0; i<MAX; i++)
            if ((x[i] >= ELEMENT_MAX) || (x[i] <= -ELEMENT_MAX))
                return 0;

        //increment the iteration count 
        iteration++;

        //if iteration count exceeds maximum number of iterations, abort
        if (iteration > max_iterations)
            return 0;

        //copy the current iteration to the last iteration vector
        (void)memcpy(last_iteration, x, sizeof(float) * MAX);
    } while (!done);

    /* we were successful */
    return iteration;
        }
      /*  //Gather all x to k_current
        MPI_Allgather(x, n_bar, MPI_FLOAT, k_current, n_bar, MPI_FLOAT, MPI_COMM_WORLD);
        //Gather x to and store in temp
		MPI_Gather(x, n_bar, MPI_FLOAT, temp, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);
		if(my_rank==0) */
    MPI_Allgather(x, n_bar, MPI_FLOAT, k, n_bar, MPI_FLOAT, MPI_COMM_WORLD);
    MPI_Gather(x, n_bar, MPI_FLOAT, temp, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);
    if(my_rank==0)
		{
			printf("\n%d) ",iteration_num);
			for (i = 0; i < n; i++)
				printf("\t%4.5f ", temp[i]);
			printf("\n");
		}

    } /*while ((iteration_num < max_iteration) && (Distance(k_current,k_previous,n) >= tolerance));

    if (Distance(k_current,k_previous,n) < tolerance) */
    while ((iteration_num < max_iteration) && (Distance(k,n) >= precesion));

    if (Distance(k,n) < precesion)
	{
        MPI_Gather(x, n_bar, MPI_FLOAT, temp, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);

		if (my_rank == 0) 
		{   
			printf("\nThe solution for Gauss-Seidel Iteration Method is\n"); //Display Solution
			for (i = 0; i < n; i++)
				printf("%4.1f ", temp[i]);
			printf("\n");
		}
    }

    else
        if (my_rank == 0) 
            printf("Failed to converge in %d iterations\n", max_iteration); 

    MPI_Finalize(); //End Process
}


error:

Compiling...
Gauss_Seidel.cpp
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(104) : warning C4091: '' : ignored on left of 'float' when no variable is declared
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(104) : error C2143: syntax error : missing ';' before 'constant'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(127) : error C2065: 'n_bar' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(167) : error C2106: '=' : left operand must be l-value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(168) : error C2065: 'max_iterations' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(196) : error C2065: 'done' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(196) : error C2065: 'TRUE' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(202) : error C2065: 'ELEMENT_MAX' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(203) : error C2562: 'main' : 'void' function returning a value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(78) : see declaration of 'main'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(210) : error C2562: 'main' : 'void' function returning a value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(78) : see declaration of 'main'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(213) : error C2065: 'memcpy' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(217) : error C2562: 'main' : 'void' function returning a value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(78) : see declaration of 'main'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(224) : error C2065: 'x' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(224) : error C2065: 'k' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(224) : error C2501: 'MPI_Allgather' : missing storage-class or type specifiers
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(224) : error C2373: 'MPI_Allgather' : redefinition; different type modifiers
c:\program files\mpich\sdk\include\mpi.h(378) : see declaration of 'MPI_Allgather'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(224) : error C2078: too many initializers
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(225) : error C2065: 'temp' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(225) : error C2501: 'MPI_Gather' : missing storage-class or type specifiers
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(225) : error C2373: 'MPI_Gather' : redefinition; different type modifiers
c:\program files\mpich\sdk\include\mpi.h(374) : see declaration of 'MPI_Gather'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(225) : error C2078: too many initializers
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(226) : error C2143: syntax error : missing ';' before 'if'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(227) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(227) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(234) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(234) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(234) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(239) : error C2143: syntax error : missing ';' before 'if'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(240) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(240) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(252) : error C2143: syntax error : missing ';' before 'else'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(257) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(257) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(257) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.

Gauss_Seidel.obj - 33 error(s), 1 warning(s)
Attached Files
File Type: zip Gauss_Seidel2.zip (916 Bytes, 59 views)
  #2  
Old 01-May-2007, 09:54
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: MPI with C (Solving Linear Equation using Gauss-Seidel Iteration)


Quote:
Originally Posted by trainz13
there some syntax error. can anyone help me identify it and tell me how to correct it
Since you didn't share with us the wording of the syntax error (how the heck are we supposed to know?), it is going to be up to you to find it.

That's OK; it's probably the best plan anyhow. My point is that you have a better chance of getting a helpful response with fewer iterations if you give us all of the information right away. Why make us ask for more?

I'm guessing that, for one thing, you have made mistakes in commenting out blocks of code. (For example, commenting out the beginning brace '{' of a block but not commenting out the closing brace '}' or some such thing.)

Here's a suggestion: Make a copy of the code as you have shown it. Then with your text editor, delete all of the comments and compile the copy. If you can't see where the problem is, then:

1. Post the code that you are compiling.

2. Tell us what compiler you are using. Sometimes it makes a difference to people who want to help.

3. Paste the exact error messages into your post so that we can see what you are seeing. Don't edit the messages; don't paraphrase; show us the exact message (line number and all).

For what it is worth:
A little technique that I use to comment out blocks of code instead of /* */:
CPP / C++ / C Code:
#if 0
.
.
.
/* stuff to be commented out */
.
.
.
#endif
That allows blocks with embedded /* */ comments to be commented out (The C standard doesn't allow nesting of /* */.) The point being that, if you already have some /* */ comments you can comment them out without having to make other changes that might lead to mistakes.


Regards,

Dave
Footnote:

Quote:
Originally Posted by trainz13
email me at...
It's an open forum. Free advice freely given. (It may or may not be worth the price).

I get USD400 an hour for one-on-one consulting. Minimum 40 hours plus expenses. Travel extra. (It may or may not be worth the price.)

---davekw7x
(Just kidding.)
  #3  
Old 01-May-2007, 11:32
trainz13 trainz13 is offline
New Member
 
Join Date: May 2007
Posts: 3
trainz13 is on a distinguished road

Re: MPI with C (Solving Linear Equation using Gauss-Seidel Iteration)


Quote:
Originally Posted by trainz13
Hello

firstly this code is for those who familiar with MPI message passing routine.
this code generally is for solving linear equation system using gauss-seidel iteration method using C and MPI routines.

there some syntax error. can anyone help me identify it and tell me how to correct it

I was using visual c++ 6.0. I've already attached workspace containing the code and a manual.

i can provide you mpi tool (mpich.nt.1.2.5) needed
just email me at trainz13@yahoo.com

I've removed unnecessary code.the workspace only worked with Microsoft Visual C++

CPP / C++ / C Code:
/****************************************************************************
 * Gauss_Seidel2.cpp                                                        *
 *                                                                          *
 * Solves a system of linear equations using Gauss-Seidel iteration         *
 *                                                                          *
 *  
 *	  sample test that i use is matrix A = 7 -2 1  2     B = 3              *
 *                                         2  8 3  1        -2              *
 *                                        -1  0 5  2         5              *
 *                                         0  2 -1 4         4              *
 *                                                                          *
 *    the solution for x should be print like this : -0.2  -0.5 0.4 1.4     *                                        
 ****************************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
#include <math.h>

#define Swap(x,y) {float* temp; temp = x; x = y; y = temp;}

#define MAX 12
/* #define tolerance 0.0001 */

float Distance(float x[], float y[], int n) {
    int i;
    float sum = 0.0;

    for (i = 0; i < n; i++) {
        sum = sum + (x[i] - y[i])*(x[i] - y[i]);
    }
    return (float)sqrt(sum);
}
// This will read the matrix 
void Read_matrix(char* prompt, float A[MAX][MAX], int n, int my_rank, int proc) 
{
    int i, j;
    float temp[MAX][MAX];
    int n_bar;
 
    n_bar = n/proc;

    // Fill dummy entries in temp with zeroes
    for (i = 0; i < n; i++)
        for (j = n; j < MAX; j++)
            temp[i][j] = 0.0;

    if (my_rank == 0) {
        printf("%s\n", prompt);
        for (i = 0; i < n; i++)
            for (j = 0; j < n; j++)
                scanf("%f",&temp[i][j]);
    }    
    //Scatter temp to A from process 0
    MPI_Scatter(temp, n_bar*MAX, MPI_FLOAT, A, n_bar*MAX, MPI_FLOAT, 0, MPI_COMM_WORLD);
}
//This will read the vector x
void Read_vector(char*  prompt, float x[], int n, int my_rank, int proc) 
{
    int   i;
    float temp[MAX];
    int   n_bar;
    
    n_bar = n/proc;

    if (my_rank == 0) 
	{
        printf("%s\n", prompt);
        for (i = 0; i < n; i++)
            scanf("%f", &temp[i]);
    }
    //Scatter temp to x from process 0
    MPI_Scatter(temp, n_bar, MPI_FLOAT, x, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);
}

void main(int argc, char* argv[]) 
{
	//Main Process
    int proc;
    int my_rank;
    float A[MAX][MAX];
    float x[MAX];
    float B[MAX];
    int n;
    //Float tolerance;
    int max_iteration;

	//Gauss-Seidel Iteration Function
    int iteration = 0;
    int i, j;
    float last_iteration[MAX];
    float sigma1, sigma2;
    float precesion;
    int k;
	
	//Displaying arrays
	int i;
	float temp[MAX];

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &proc);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    if (my_rank == 0) 
	{
        system("cls");
	    printf("-----------------------------------------------------------------------------\n");
	    printf("Program will perform Gauss-Seidel Iteration Method to solve Linear Equation  \n");
	    printf("-----------------------------------------------------------------------------\n");        
        printf("Enter variable n and max number of iterations:  \n\n");
        scanf("%d %d", &n, &max_iteration);
    }
    //Broadcast n & maximum iteration to all other process
    MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Bcast(&max_iteration, 1, MPI_INT, 0, MPI_COMM_WORLD);

    n_bar = n/proc;

    //Fill the matrix and the vector
    Read_matrix("\nInsert the variable for the matrix A \n", A, n, my_rank, proc);
    Read_vector("\nEnter the right-hand side of B \n", B, n, my_rank, proc);

    // Initialize x
    
    MPI_Allgather(B, n_bar, MPI_FLOAT, k, n_bar, MPI_FLOAT, MPI_COMM_WORLD);
   
				
    //Calculate requested precision and maximum iterations
    precesion = pow(10.0, -(float)k);
    max_iterations = (int)pow(10.0, (float)k);

    // Initialize last_iteration matrix to zero
    for (i=0; i<MAX; i++)
        last_iteration[i] = 0.0;

    //Calculate iterations
    do
    {
        //Calculate the next iteration
        for (i=0; i<MAX; i++)
        {
            //Compute Sigma(j:j<i)(A(i,j) * x(j)(n))
            sigma1 = 0.0;
            for (j=0; j<i; j++)
                sigma1 += A[i][j] * x[j];

            //Compute Sigma(j:j>i)(A(i,j) * x(j)(n-1))
            sigma2 = 0.0;
            for (j=i+1; j<MAX; j++)
                sigma2 += A[i][j] * last_iteration[j];

            //Compute the value of this iteration
            x[i] = (B[i] - sigma1 - sigma2) / A[i][i];
        }


        //Figure out if we're done yet 
        done = TRUE;
        for (i=0; i<MAX; i++)
            done &= fabs(x[i] - last_iteration[i]) < (precesion * fabs(x[i]));

        //if any entry is greater than ELEMENT_MAX, an overflow has occurred,so abort
        for (i=0; i<MAX; i++)
            if ((x[i] >= ELEMENT_MAX) || (x[i] <= -ELEMENT_MAX))
                return 0;

        //Increment the iteration count 
        iteration++;

        //If iteration count exceeds maximum number of iterations, abort
        if (iteration > max_iterations)
            return 0;

        //Copy the current iteration to the last iteration vector
        (void)memcpy(last_iteration, x, sizeof(float) * MAX);
    } while (!done);

    /* we were successful */
    return iteration;
        }
      
    MPI_Allgather(x, n_bar, MPI_FLOAT, k, n_bar, MPI_FLOAT, MPI_COMM_WORLD);
    MPI_Gather(x, n_bar, MPI_FLOAT, temp, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);
    if(my_rank==0)
		{
			printf("\n%d) ",iteration_num);
			for (i = 0; i < n; i++)
				printf("\t%4.5f ", temp[i]);
			printf("\n");
		}

    } 
    while ((iteration_num < max_iteration) && (Distance(k,n) >= precesion));

    if (Distance(k,n) < precesion)
	{
        MPI_Gather(x, n_bar, MPI_FLOAT, temp, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);

		if (my_rank == 0) 
		{   
			printf("\nThe solution for Gauss-Seidel Iteration Method is\n"); //Display Solution
			for (i = 0; i < n; i++)
				printf("%4.1f ", temp[i]);
			printf("\n");
		}
    }

    else
        if (my_rank == 0) 
            printf("Failed to converge in %d iterations\n", max_iteration); 

    MPI_Finalize(); //End Process
}


Error:

--------------------Configuration: ASSIGN2 - Win32 Debug--------------------
Compiling...
Gauss_Seidel.cpp
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(98) : error C2086: 'i' : redefinition
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(118) : error C2065: 'n_bar' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(130) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(131) : error C2065: 'max_iterations' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(159) : error C2065: 'done' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(159) : error C2065: 'TRUE' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(165) : error C2065: 'ELEMENT_MAX' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(166) : error C2562: 'main' : 'void' function returning a value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(77) : see declaration of 'main'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(173) : error C2562: 'main' : 'void' function returning a value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(77) : see declaration of 'main'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(176) : error C2065: 'memcpy' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(180) : error C2562: 'main' : 'void' function returning a value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(77) : see declaration of 'main'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(183) : error C2065: 'x' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(183) : error C2065: 'k' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(183) : error C2501: 'MPI_Allgather' : missing storage-class or type specifiers
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(183) : error C2373: 'MPI_Allgather' : redefinition; different type modifiers
c:\program files\mpich\sdk\include\mpi.h(378) : see declaration of 'MPI_Allgather'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(183) : error C2078: too many initializers
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(184) : error C2065: 'temp' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(184) : error C2501: 'MPI_Gather' : missing storage-class or type specifiers
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(184) : error C2373: 'MPI_Gather' : redefinition; different type modifiers
c:\program files\mpich\sdk\include\mpi.h(374) : see declaration of 'MPI_Gather'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(184) : error C2078: too many initializers
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(185) : error C2143: syntax error : missing ';' before 'if'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(186) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(186) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(193) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(193) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(193) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(196) : error C2143: syntax error : missing ';' before 'if'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(197) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(197) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(209) : error C2143: syntax error : missing ';' before 'else'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(214) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(214) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(214) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.

Gauss_Seidel.obj - 32 error(s), 1 warning(s)
  #4  
Old 01-May-2007, 12:18
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: MPI with C (Solving Linear Equation using Gauss-Seidel Iteration)


Quote:
Originally Posted by trainz13
I've removed unnecessary code.the workspace only worked with Microsoft Visual C++

[color="Red"]--------------------Configuration: ASSIGN2 - Win32 Debug--------------------
Compiling...
Gauss_Seidel.cpp
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(98) : error C2086: 'i' : redefinition

How could I have, somehow, posted my remark about your not sharing the messages without seeing them? Sorry. Sometimes I just don't pay attention. (Or is it possible that the software on the board no longer puts the comment about "Last edited..." when people subsequently change things, the way it used to? Maybe it's just me.)

OK: Let's start fresh.



Look at the messages, then look at the code. Sometimes compiler messages are not very clear (especially when you haven't seen them a million times before), but just looking can (sometimes) lead to enlightenment.

And, by the way, sometimes they are quite clear.

Look at the first message:
Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(98) : error C2086: 'i' : redefinition
line 98 is in your main function, right?
CPP / C++ / C Code:
	int i;
Now, look back at line 91 (still in main()):
CPP / C++ / C Code:
    int i, j;
Now look at the message again.

Next message:
Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(118) : error C2065: 'n_bar' : undeclared identifier

Line 118 is in main():
CPP / C++ / C Code:
    n_bar = n/proc;

Is there a variable named n_bar that is declared anywhere in the program such a way as it is visible in main()?

Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(130) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
The standard library function pow() returns a double. You are using a float. (That's why it is a warning, not an error.) If you are happy with floats, then ignore this. A little comment by me: Why use floats anywhere? Why not just use doubles? I realize that sometimes there might be a reason, but, more often not, (or, more precisely: there is not necessarily a good reason).

Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(131) : error C2065: 'max_iterations' : undeclared identifier

Based on my previous comment about n_bar, what would you think that this means? Ditto for any similar messages.

Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(166) : error C2562: 'main' : 'void' function returning a value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(77) : see declaration of 'main'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(173) : error C2562: 'main' : 'void' function returning a value
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(77) : see declaration of 'main'

This line number 166 is in your main() function, and you have declared main() on line number 77:
CPP / C++ / C Code:
void main()
This is not standard usage (according to international C Standard language definition), but Microsoft and other C compilers accept that declaration. However, if you declare it as void, then it is an error to try to return a value. I am not sure how the messages could have been worded more clearly.

My advice: change the declaration to
CPP / C++ / C Code:
int main()

Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(176) : error C2065: 'memcpy' : undeclared identifier
The standard library function memcpy() is prototyped in <string.h> so you should include that header. Since you are compiling this as a C++ program, all functions must be declared before they are used. It's not strictly required in C programs, but is strongly recommended to guarantee correct operation.

Other errors are mostly concerning the mpi stuff, and you should be able to dig them out once you get used to the idea of looking at the messages and looking at the code.


While you are in the neighborhood of line 183, looking at numerous not-so-clear messages, look at the code just before and just after:

CPP / C++ / C Code:
    } while (!done);

    /* we were successful */
    return iteration;
        }
      
    MPI_Allgather(x, n_bar, MPI_FLOAT, k, n_bar, MPI_FLOAT, MPI_COMM_WORLD);
    MPI_Gather(x, n_bar, MPI_FLOAT, temp, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);

The closing brace, '}', after the return iteration; statement appears to be the end of main(). At least I think it is, and maybe the compiler thinks so, too. Carefully count to see if the braces are matched, starting with the opening brace, '{', at the start of main(). I feel that a number of the other syntax errors are the result of unmatched braces in your control blocks.


Regards,

Dave
Last edited by davekw7x : 01-May-2007 at 13:40.
  #5  
Old 01-May-2007, 13:07
LuciWiz's Avatar
LuciWiz LuciWiz is offline
Moderator
 
Join Date: Jul 2004
Location: Cluj-Napoca (Romania)
Posts: 960
LuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the roughLuciWiz is a jewel in the rough

Re: MPI with C (Solving Linear Equation using Gauss-Seidel Iteration)


Quote:
Originally Posted by davekw7x
How could I have, somehow, posted my remark about your not sharing the messages without seeing them? Sorry. Sometimes I just don't pay attention. (Or is it possible that the software on the board no longer puts the comment about "Last edited..." when people subsequently change things, the way it used to? Maybe it's just me.)

It's not you. The post was edited, and there is no "Last edited..." comment.

I know it happened to me when I edited my own post in a short period of time, without filling anything into the "Reason for editing" box. I always assumed it was because I was a mod. Perhaps not, or perhaps there was a little bug? If you feel like experiencing (you know, for science!), perhaps you could try editing one of your own posts with/without giving a reason for editing. I can't experiment since I may be on another another privilege level.

Best regards,
Lucian
__________________
Please read these Guidelines before posting on the forum

"A person who never made a mistake never tried anything new."
Einstein
  #6  
Old 01-May-2007, 13:38
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: MPI with C (Solving Linear Equation using Gauss-Seidel Iteration)


Quote:
Originally Posted by LuciWiz
It's not you. The post was edited, and there is no "Last edited..." comment.

Thanks, Lucien, for the feedback. Sometimes I miss things from posts and give snappy retorts when they aren't warranted, and I regret it later.

I had just edited my own (within a few minutes of original post) and there is no "Last edited..." on that one either. I never noticed that before. I usually revisit my posts a little later to try to catch typos, etc., (and sometimes to temper the rhetoric) but rarely change significant content. And if I do make significant changes, I usually put something like the following to try to make the editing obvious:

[edit]comment here [/edit]

And as a test I just edited something from an hour or so ago, and I see the "Last edited..." message. I just never noticed that that didn't appear with "soon-after" edits.


Regards,

Dave
  #7  
Old 01-May-2007, 19:34
trainz13 trainz13 is offline
New Member
 
Join Date: May 2007
Posts: 3
trainz13 is on a distinguished road

Re: MPI with C (Solving Linear Equation using Gauss-Seidel Iteration)


I still can't understand, i've already declared the identifier, why it's still say that the identifier is still undeclared.

i try fix the code but there still some i can't understand. i was using floating point instead of double because i wan't the output will be view as 0.00000. i want the precise solution.

i send the screen shot on how the program will be look a alike

CPP / C++ / C Code:
 /****************************************************************************
 * Gauss_Seidel2.cpp                                                        *
 *                                                                          *
 * Solves a system of linear equations using Gauss-Seidel iteration         *
 *                                                                          *
 *  
 *	  sample test that i use is matrix A = 7 -2 1  2     B = 3              *
 *                                         2  8 3  1        -2              *
 *                                        -1  0 5  2         5              *
 *                                         0  2 -1 4         4              *
 *                                                                          *
 *    the solution for x should be print like this : -0.2  -0.5 0.4 1.4     *                                        
 ****************************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include "mpi.h"
#include <math.h>
#include <string.h>

#define Swap(x,y) {float* temp; temp = x; x = y; y = temp;}

#define MAX 12
/* #define tolerance 0.0001 */

float Distance(float x[], float y[], int n) {
    int i;
    float sum = 0.0;

    for (i = 0; i < n; i++) {
        sum = sum + (x[i] - y[i])*(x[i] - y[i]);
    }
    return (float)sqrt(sum);
}
// This will read the matrix 
void Read_matrix(char* prompt, float A[MAX][MAX], int n, int my_rank, int proc) 
{
    int i, j;
    float temp[MAX][MAX];
    int n_bar;
 
    n_bar = n/proc;

    // Fill dummy entries in temp with zeroes
    for (i = 0; i < n; i++)
        for (j = n; j < MAX; j++)
            temp[i][j] = 0.0;

    if (my_rank == 0) {
        printf("%s\n", prompt);
        for (i = 0; i < n; i++)
            for (j = 0; j < n; j++)
                scanf("%f",&temp[i][j]);
    }    
    //Scatter temp to A from process 0
    MPI_Scatter(temp, n_bar*MAX, MPI_FLOAT, A, n_bar*MAX, MPI_FLOAT, 0, MPI_COMM_WORLD);
}
//This will read the vector x
void Read_vector(char*  prompt, float x[], int n, int my_rank, int proc) 
{
    int   i;
    float temp[MAX];
    int   n_bar;
    
    n_bar = n/proc;

    if (my_rank == 0) 
	{
        printf("%s\n", prompt);
        for (i = 0; i < n; i++)
            scanf("%f", &temp[i]);
    }
    //Scatter temp to x from process 0
    MPI_Scatter(temp, n_bar, MPI_FLOAT, x, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);
}

void main(int argc, char* argv[]) 
{
	//Main Process
    int proc;
    int my_rank;
    float A[MAX][MAX];
    float x[MAX];
    float B[MAX];
    int n;
    //Float tolerance;
    int max_iteration;

	//Gauss-Seidel Iteration Function
    int iteration = 0;
    int i, j;
    float last_iteration[MAX];
    float sigma1, sigma2;
    float precesion;
    float k;
	float x_temp[MAX];
	
	//Displaying arrays
	float temp[MAX];

    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &proc);
    MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);

    if (my_rank == 0) 
	{
        system("cls");
	    printf("-----------------------------------------------------------------------------\n");
	    printf("Program will perform Gauss-Seidel Iteration Method to solve Linear Equation  \n");
	    printf("-----------------------------------------------------------------------------\n");        
        printf("Enter variable n and max number of iterations:  \n\n");
        scanf("%d %d", &n, &max_iteration);
    }
    //Broadcast n & maximum iteration to all other process
    MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
    MPI_Bcast(&max_iteration, 1, MPI_INT, 0, MPI_COMM_WORLD);

    int n_bar = n/proc;

    //Fill the matrix and the vector
    Read_matrix("\nInsert the variable for the matrix A \n", A, n, my_rank, proc);
    Read_vector("\nEnter the right-hand side of B \n", B, n, my_rank, proc);

    // Initialize x
    
    MPI_Allgather(B, n_bar, MPI_FLOAT, x_temp, n_bar, MPI_FLOAT, MPI_COMM_WORLD);
   
	k = x_temp;			
    //Calculate requested precision and maximum iterations
    precesion = pow(10.0, -(float)k);
    max_iterations = (int)pow(10.0, (float)k);

    // Initialize last_iteration matrix to zero
    for (i=0; i<MAX; i++)
        last_iteration[i] = 0.0;

    //Calculate iterations
    do
    {
        //Calculate the next iteration
        for (i=0; i<MAX; i++)
        {
            //Compute Sigma(j:j<i)(A(i,j) * x(j)(n))
            sigma1 = 0.0;
            for (j=0; j<i; j++)
                sigma1 += A[i][j] * x[j];

            //Compute Sigma(j:j>i)(A(i,j) * x(j)(n-1))
            sigma2 = 0.0;
            for (j=i+1; j<MAX; j++)
                sigma2 += A[i][j] * last_iteration[j];

            //Compute the value of this iteration
            x[i] = (B[i] - sigma1 - sigma2) / A[i][i];
        }


        //Figure out if we're done yet 
        done = TRUE;
        for (i=0; i<MAX; i++)
            done &= fabs(x[i] - last_iteration[i]) < (precesion * fabs(x[i]));

        //if any entry is greater than ELEMENT_MAX, an overflow has occurred,so abort
        for (i=0; i<MAX; i++)
            if ((x[i] >= ELEMENT_MAX) || (x[i] <= -ELEMENT_MAX))
                

        //Increment the iteration count 
        iteration++;

        //If iteration count exceeds maximum number of iterations, abort
        if (iteration > max_iterations)
            

        //Copy the current iteration to the last iteration vector
        (void)memcpy(last_iteration, x, sizeof(float) * MAX);
    } while (!done);

  
        
      
    MPI_Allgather(x, n_bar, MPI_FLOAT, x_temp, n_bar, MPI_FLOAT, MPI_COMM_WORLD);
    MPI_Gather(x, n_bar, MPI_FLOAT, temp, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);
    if(my_rank==0)
		{
			printf("\n%d) ",iteration_num);
			for (i = 0; i < n; i++)
				printf("\t%4.5f ", temp[i]);
			printf("\n");
		}

    } 
    while ((iteration_num < max_iteration) && (Distance(k,n) >= precesion));

    if (Distance(k,n) < precesion)
	{
        MPI_Gather(x, n_bar, MPI_FLOAT, temp, n_bar, MPI_FLOAT, 0, MPI_COMM_WORLD);

		if (my_rank == 0) 
		{   
			printf("\nThe solution for Gauss-Seidel Iteration Method is\n"); //Display Solution
			for (i = 0; i < n; i++)
				printf("%4.1f ", temp[i]);
			printf("\n");
		}
    }

    else
        if (my_rank == 0) 
            printf("Failed to converge in %d iterations\n", max_iteration); 

    MPI_Finalize(); //End Process
}


Error:

--------------------Configuration: ASSIGN2 - Win32 Debug--------------------
Compiling...
Gauss_Seidel.cpp
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(129) : error C2440: '=' : cannot convert from 'float [12]' to 'float'
There is no context in which this conversion is possible
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(131) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(132) : error C2065: 'max_iterations' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(160) : error C2065: 'done' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(160) : error C2065: 'TRUE' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(166) : error C2065: 'ELEMENT_MAX' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(187) : error C2065: 'iteration_num' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(194) : error C2143: syntax error : missing ';' before 'while'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(196) : error C2143: syntax error : missing ';' before 'if'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(197) : error C2143: syntax error : missing ';' before '{'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(197) : error C2447: missing function header (old-style formal list?)
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(209) : error C2143: syntax error : missing ';' before 'else'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(214) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(214) : error C2143: syntax error : missing ';' before '}'
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(214) : error C2143: syntax error : missing ';' before '}'
Error executing cl.exe.

Gauss_Seidel.obj - 14 error(s), 1 warning(s)


C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(129) : error C2440: '=' : cannot convert from 'float [12]' to 'float'
There is no context in which this conversion is possible
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(131) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data


i don't understand, how to fix this.
i can't find any missing ";" before }, where it's
Dave or anyone could you explain or at least fix the code for me
Attached Files
File Type: zip screenshot.zip (42.2 KB, 11 views)
  #8  
Old 01-May-2007, 23:38
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,791
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold

Re: MPI with C (Solving Linear Equation using Gauss-Seidel Iteration)


Quote:
Originally Posted by trainz13
i've already declared the identifier, why it's still say that the identifier is still undeclared.
It is called "scope". A variable declared inside a function is visible inside that function. A variable declared inside one function is not visible inside another function. I hate to repeat myself but:
Quote:
Originally Posted by davekw7x

Is there a variable named n_bar that is declared anywhere in the program such a way as it is visible in main()?
And now I will answer the question (but the compiler already told you): No.

Quote:
Originally Posted by trainz13
i. i was using floating point instead of double because i wan't the output will be view as 0.00000. i want the precise solution.
That means nothing to me. But I really don't care. Use whatever the heck you want to. I personally use doubles just because they are there (and I hate sifting through irrelevant "warnings" when I use the standard library math functions like pow()). The precision with which variables are represented internally has nothing to do with how many decimal places that you decide to print out (but may have something to do with the amount of error that results from rounding off the representations and the results of calculations).

Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(129) : error C2440: '=' : cannot convert from 'float [12]' to 'float'
There is no context in which this conversion is possible
Look at line 129.
CPP / C++ / C Code:
	k = x_temp;			
What is k? What is x_temp? What don't you understand about the message?
Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(131) : warning C4244: '=' : conversion from 'double' to 'float', possible loss of data
It's a warning, not an error, and I have already told you what it means. Fix it or ignore it: your choice.

Quote:
Originally Posted by trainz13
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(132) : error C2065: 'max_iterations' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(160) : error C2065: 'done' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(160) : error C2065: 'TRUE' : undeclared identifier
C:\Documents and Settings\DANTE\Desktop\Gauss_Seidel.cpp(166) : error C2065: 'ELEMENT_MAX' : undeclared identifier
.
.
.
"Undeclared identifier" means that you are using various names that the compiler doesn't know about. How could it? You haven't told it what 'max_iterations', 'done', 'TRUE', etc. are.

Quote:
Originally Posted by trainz13
.



i don't understand, how to fix this.
i can't find any missing ";" before }, where it's

I have already told you: The {} braces are unmatched. Somewhere around line 193, the compiler thinks that it has reached the end of main(). (In fact the compiler [i]has[i] reached the end of main()). Here's how to count braces:

Go to the first opening brace, '{', of a function. Count is equal to 1. Now, as you go through each line in a function, increment the count for each opening brace '{'. Decrement the count for each closing brace, '}'. If the count ever goes below zero, you have too many closing braces. If you reach what you think is the end of the function but the count is not zero after the last closing brace, then STOP. That function has unmatched braces and must be fixed before going on to the next.
Quote:
Originally Posted by trainz13
Dave or anyone could you explain
I have tried, and I will be glad to try some more. Maybe someone else can come up with other ways of looking at things, or may be able to get the points across with fewer words.
Quote:
Originally Posted by trainz13
or at least fix the code for me
Speaking only for myself (but I am unanimous in this): Not a chance

It's your program, and I have no personal stake in "fixing" it. On the other hand if you are willing to participate in your own education, there are lots of people who would like try to help.

Regards,

Dave
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 4) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
paralllel programming using MPI - linear equation using jacobi eclipt C++ Forum 0 04-May-2006 20:02
MPI - linear pipeline solution for jacobi iteration eclipt C++ Forum 0 03-May-2006 05:03

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:21.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.