#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
#include <veda.h>
#define CHECK(err) check(err, __FILE__, __LINE__)
#define MAX_LEN (1024*1024)
void check(VEDAresult err, const char* file, const int line) {
if(err != VEDA_SUCCESS) {
const char* name = 0;
printf("Error: %i %s @ %s (%i)\n", err, name, file, line);
assert(0);
exit(1);
}
}
int
main()
{
int myrank;
int nprocs;
int nelems = MAX_LEN;
int dev,cnt;
uint64_t rc;
uint64_t id;
MPI_Init( 0, 0 );
MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
MPI_Comm_size( MPI_COMM_WORLD, &nprocs );
printf( "myrank = %d, nprocs = %d, started\n", myrank, nprocs );
fflush( stdout );
VEDAcontext cont;
printf( "myrank = %d, nprocs = %d, context = %16p, created\n", myrank, nprocs, cont );
VEDAmodule mod;
const char* modName = "./libmpive.vso";
VEDAhmemptr vebuf;
printf( "myrank = %d, nprocs = %d, vebuf = %16p, allocated\n", myrank, nprocs, vebuf );
VEDAargs args1;
VEDAfunction func1;
const char* funcName1 = "init";
printf( "myrank = %d, nprocs = %d, rc=%d, VE offload\n", myrank, nprocs, rc );
int peer = myrank^1;
if ( peer >= nprocs ) peer = MPI_PROC_NULL;
VEDAargs args2;
VEDAfunction func2;
const char* funcName2 = "check";
printf( "myrank = %d, nprocs = %d, rc=%d, VE offload\n", myrank, nprocs, rc );
MPI_Status status;
MPI_Barrier(MPI_COMM_WORLD);
if ( myrank%2 == 0) {
MPI_Send((void *)vebuf, MAX_LEN, MPI_INT, peer, 0, MPI_COMM_WORLD);
}
else {
MPI_Recv((void *)vebuf, MAX_LEN, MPI_INT, peer, 0, MPI_COMM_WORLD, &status );
}
MPI_Barrier(MPI_COMM_WORLD);
VEDAargs args3;
printf( "myrank = %d, nprocs = %d, rc=%d, VE offload\n", myrank, nprocs, rc );
uint64_t result;
MPI_Reduce( &rc, &result, 1, MPI_LONG_LONG, MPI_SUM, 0, MPI_COMM_WORLD );
if ( myrank == 0 ) {
printf( "Result : %s\n", result ? "Failed" : "Success" );
fflush( stdout );
}
MPI_Finalize();
return 0;
}