Code Monkey home page Code Monkey logo

build-supercomputers-with-raspberry-pi-3's People

Contributors

varshashivhare avatar

Watchers

 avatar

build-supercomputers-with-raspberry-pi-3's Issues

Euler Program will not compile because of sqrt() and power(), I believe the (double) sum is culprit. Please advise.

#include <math.h> // math library
#include <stdio.h> // Standard Input / Output library

int main(int argc, char*argv[])
{
int total_iter;
int n,rank,length,numprocs,i,j,k;
double sum,sum0,rank_integral,A,B,C;
char hostname[MPI_MAX_PROCESSOR_NAME];

MPI_Init(&argc, &argv); // initiates MPI
MPI_Comm_size(MPI_COMM_WORLD, &numprocs); // acquire number of processes
MPI_Comm_rank(MPI_COMM_WORLD, &rank); // acquire current process id
MPI_Get_processor_name(hostname, &length); // acquire hostname

if (rank == 0)
{
printf("\n");
printf("#######################################################");
printf("\n\n");
printf("Master node name: %s\n", hostname);
printf("\n");
printf("Enter the number of intervals:\n");
printf("\n");
scanf("%d",&n);
printf("\n");
}

// broadcast the number of iterations "n" to all processes.
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);

// this loop increments the maximum number of iterations, thus providing
// additional work for testing computational speed of the processors
// for(total_iter = 1; total_iter < n; total_iter++)
{
sum0 = 0.0;
// for(i = rank + 1; i <= total_iter; i += numprocs)
for(i = rank + 1; i <= n; i += numprocs)
{
j = i-1;
k = (2*j+1);

  A = (double)pow(-1,j+2);
  B = 4.0/(double)((k+1)*(k+2)*(k+3));
  C = A * B;

  sum0 += C;
}

rank_integral = sum0;// Partial sum for a given rank

// collect and add the partial sum0 values from all processes
MPI_Reduce(&rank_integral, &sum, 1, MPI_DOUBLE,MPI_SUM, 0, MPI_COMM_WORLD);

} // End of for(total_iter = 1; total_iter < n; total_iter++)
// printf("Process %d on %s has the partial result of %.16f \n",rank,hostname,
// rank_integral);

if(rank == 0)
{
printf("\n\n");
printf("*** Number of processes: %d\n",numprocs);
printf("\n\n");
printf(" Calculated pi = %.30f\n", (3+sum));
printf(" M_PI = %.30f\n", M_PI);
printf(" Relative Error = %.30f\n", fabs((3+sum)-M_PI));
printf("\n");
}

// clean up, done with MPI
MPI_Finalize();

return 0;
}

Compile failure using gcc:

  1. skynetjudgementday@skynetjudgementday-desktop:~/Desktop/clusterFS2$
    mpicc Euler_mpi.c -o Euler_mpi
    /usr/bin/ld: /tmp/ccmqqFQV.o: undefined reference to symbol 'sqrt@@GLIBC_2.2.5'
    /usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status

  2. skynetjudgementday@skynetjudgementday-desktop:~/Desktop/clusterFS2$
    mpicc Euler_mpi.c -o Euler_mpi
    /usr/bin/ld: /tmp/ccQCrj44.o: undefined reference to symbol 'pow@@GLIBC_2.29'
    /usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
    collect2: error: ld returned 1 exit status

How can I fix this fault in C? Please help. Thank you.
[email protected]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.