Skip to content
Snippets Groups Projects
Commit e78b3e70 authored by Joachim Protze's avatar Joachim Protze
Browse files

Initial commit

parents
Branches
No related tags found
No related merge requests found
#include <mpi.h>
#include <stdio.h>
int main (int argc, char** argv)
{
int rank, size, buf[8];
MPI_Init(&argc,&argv);
MPI_Comm_rank (MPI_COMM_WORLD, &rank);
MPI_Comm_size (MPI_COMM_WORLD, &size);
MPI_Datatype type;
MPI_Type_contiguous(2, MPI_INTEGER, &type);
MPI_Recv(buf, 2, MPI_INT, size-rank-1, 123, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
MPI_Send(buf, 2, type, size-rank-1, 123, MPI_COMM_WORLD);
printf ("Hello, I am rank %d of %d.\n", rank, size);
MPI_Finalize ();
return 0;
}
/*
* Copyright (c) 2006, 2010, Oracle and/or its affiliates. All Rights Reserved.
* @(#)prime_omp.c 1.3 (Oracle) 10/03/26
* Downloaded at https://docs.oracle.com/cd/E37069_01/html/E37080/geazt.html
*/
#include <stdio.h>
#include <math.h>
#define N 1000000
int primes[N];
int pflag[N];
int is_prime(int v)
{
int i;
int bound = floor(sqrt(v)) + 1;
for (i = 2; i < bound; i++) {
/* no need to check against known composites */
if (!pflag[i])
continue;
if (v % i == 0) {
pflag[v] = 0;
return 0;
}
}
return (v > 1);
}
int main(int argn, char **argv)
{
int i;
int total = 0;
for (i = 0; i < N; i++) {
pflag[i] = 1;
}
#pragma omp parallel for schedule(dynamic)
for (i = 2; i < N; i++) {
if ( is_prime(i) ) {
// #pragma omp critical
primes[total++] = i;
}
}
printf("Number of prime numbers between 2 and %d: %d\n",
N, total);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment