Talk:cpp/chrono/duration
From cppreference.com
std::chrono::duration could not company with openmpi MPI_gather
following code will be wrong when we use more than 10 threads
#include <iostream>
#include "mpi.h"
#include "stdlib.h"
#include <thread>
#include <chrono>
#include "stdlib.h"
using namespace std;
void delay( int max_time){
srand(time(0));
int sleepnum = rand()%max_time;
std::chrono::milliseconds dura(sleepnum);
this_thread::sleep_for(dura);
}
int main(){
MPI_Init(NULL,NULL);
int size, rank;
MPI_Comm_rank(MPI_COMM_WORLD,&rank);
MPI_Comm_size(MPI_COMM_WORLD,&size);
double local_num;
double* buffer = new double[(size)*sizeof(double) ];
cout<<"pin1\n";
auto start = std::chrono::high_resolution_clock::now();
cout<<"pin2\n";
// for(int i = 0 ; i < 1000; i++)
{
cout<<"pin3\n";
//delay(1000);
MPI_Gather((void*)&local_num,1,MPI_DOUBLE,(void*)buffer,size,MPI_DOUBLE,0,MPI_COMM_WORLD);
if(rank == 0){
//delay(100);
}
cout<<"pin4\n";
//MPI_Bcast(&local_num, 1, MPI_DOUBLE, 0, MPI_COMM_WORLD);
cout<<"pin5\n";
}
auto end = std::chrono::high_resolution_clock::now();
std::chrono::duration<double, std::milli> elapsed = end-start;
std::cout << "use " << elapsed.count() << " ms\n";
//delete[] buffer;
MPI_Finalize();
}
I fixed the formatting for the above, but I don't think this belongs here - this isn't stackoverflow. MPI coding is complicated and I wouldn't be surprised if there were a bug or two in the above code.
I think it should be removed.
Hadriel (talk) 14:10, 12 December 2019 (PST)
[edit] ADL and Duration Literals
Is there a way to get argument dependent lookup to work with duration literals? If so, that would be a nice example. This would avoid the need to add a using statement just to use a literal somewhere.
e.g.
void foo(std::chrono::duration d) { } ... foo(10ms); // 10ms is understood to be a std::chrono::duration, so no using is required
68.249.219.17 15:52, 29 December 2021 (PST)
- ADL would let you find
foo
if it were defined in namespacestd
orstd::chrono
or in the classstd::chrono::duration
when given anstd::chrono::duration
argument. The opposite direction of having a function that takes an argument fromstd::chrono::duration
, that has no bearing on how the argument is interpreted when callingfoo(argument)
. Tl;dr ADL changes the function called, not the argument. --Ybab321 (talk) 04:22, 30 December 2021 (PST)