Skip to content
Snippets Groups Projects
Select Git revision
  • 25d2e7dcef49804c997d2e6c1e32f82d314026c9
  • master default protected
  • BioEM-1.0 protected
  • BioEM-2.1.0
  • BioEM-2.0.3
  • BioEM-2.0.2
  • BioEM-2.0.1
  • BioEM-2.0.0
  • BioEM-1.0.2
  • BioEM-1.0.1
  • BioEM-1.0.0
11 results

main.cpp

Blame
  • main.cpp 1.97 KiB
    #include <mpi.h>
    
    #define MPI_CHK(expr) \
    	if (expr != MPI_SUCCESS) \
    	{ \
    		fprintf(stderr, "Error in MPI function %s: %d\n", __FILE__, __LINE__); \
    	}
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <time.h>
    #include <fenv.h>
    
    #ifdef _WIN32
    #include <Windows.h>
    #include <WinBase.h>
    #endif
    
    #include <iostream>
    #include <algorithm>
    #include <iterator>
    #include "bioem.h"
    #include "bioem_cuda.h"
    
    #ifdef WITH_OPENMP
    #include <omp.h>
    #endif
    
    #ifdef WITH_MPI
    int mpi_rank;
    int mpi_size;
    #else
    const int mpi_rank = 0;
    const int mpi_size = 1;
    #endif
    
    #include "cmodules/timer.h"
    
    int main(int argc, char* argv[])
    {
    	// **************************************************************************************
    	// *********************************  Main BioEM code **********************************
    	// ************************************************************************************
    
    #ifdef WITH_MPI
    	MPI_CHK(MPI_Init(&argc, &argv));
    	MPI_CHK(MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank));
    	MPI_CHK(MPI_Comm_size(MPI_COMM_WORLD, &mpi_size));
    #endif
    
    #ifdef _MM_DENORMALS_ZERO_ON
    	#pragma omp parallel
    	{
    		_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); //Flush denormals to zero in all OpenMP threads
    	}
    #endif
    	HighResTimer timer;
    
    	bioem* bio;
    #ifdef WITH_CUDA
    	if (getenv("GPU") && atoi(getenv("GPU")))
    	{
    		bio = bioem_cuda_create();
    	}
    	else
    #endif
    	{
    		bio = new bioem;
    	}
    
    	// ************  Configuration and Pre-calculating necessary objects *****************
    	if (mpi_rank == 0) printf("Configuring\n");
    	if (bio->configure(argc, argv) == 0)
    	{
    
    		// *******************************  Run BioEM routine ******************************
    		if (mpi_rank == 0) printf("Running\n");
    		timer.Start();
    		bio->run();
    		timer.Stop();
    
    		// ************************************ End **********************************
    		printf ("The code ran for %f seconds (rank %d).\n", timer.GetElapsedTime(), mpi_rank);
    		bio->cleanup();
    	}
    	delete bio;
    
    #ifdef WITH_MPI
    	MPI_Finalize();
    #endif
    
    	return(0);
    }