Repository: pytorch
Issue: Building from source results in no member named 'cerr' in namespace 'std'
Labels: module: build,triaged

## 🐛 Bug

Building torch results in 

```
torch/csrc/distributed/c10d/ProcessGroupMPI.cpp:131:10: error: no member named 'cerr' in namespace 'std'
```

## To Reproduce

Steps to reproduce the behavior:

1. `export USE_CUDA=0`
2. `export USE_MKL_DNN=0`
3. `export BUILD_TEST=0`
4. `python ./setup.py bdist_wheel`

Commit: https://github.com/pytorch/pytorch/commit/c78ab28441f5616899d363d57317f4de29147e5c
System: Ubuntu 20.04, using `libstdc++-11-dev`

<!-- If you have a code sample, error messages, stack traces, please provide it here as well -->

## Expected behavior

```
[4851/5217] Building CXX object caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp.o
FAILED: caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp.o 
/usr/bin/c++ -DADD_BREAKPAD_SIGNAL_HANDLER -DCPUINFO_SUPPORTED_PLATFORM=1 -DFMT_HEADER_ONLY=1 -DFXDIV_USE_INLINE_ASSEMBLY=0 -DHAVE_MALLOC_USABLE_SIZE=1 -DHAVE_MMAP=1 -DHAVE_SHM_OPEN=1 -DHAVE_SHM_UNLINK=1 -DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -DNNP_CONVOLUTION_ONLY=0 -DNNP_INFERENCE_ONLY=0 -DONNXIFI_ENABLE_EXT=1 -DONNX_ML=1 -DONNX_NAMESPACE=onnx_torch -DUSE_C10D_GLOO -DUSE_C10D_MPI -DUSE_DISTRIBUTED -DUSE_EXTERNAL_MZCRC -DUSE_RPC -DUSE_TENSORPIPE -D_FILE_OFFSET_BITS=64 -Dtorch_cpu_EXPORTS -I<torch root>/build/aten/src -I<torch root>/aten/src -I<torch root>/build -I<torch root> -I<torch root>/build/caffe2/contrib/aten -I<torch root>/third_party/onnx -I<torch root>/build/third_party/onnx -I<torch root>/third_party/foxi -I<torch root>/build/third_party/foxi -I<torch root>/torch/csrc/api -I<torch root>/torch/csrc/api/include -I<torch root>/caffe2/aten/src/TH -I<torch root>/build/caffe2/aten/src/TH -I<torch root>/build/caffe2/aten/src -I<torch root>/caffe2/../third_party -I<torch root>/caffe2/../third_party/breakpad/src -I<torch root>/build/caffe2/../aten/src -I<torch root>/build/caffe2/../aten/src/ATen -I<torch root>/torch/csrc -I<torch root>/third_party/miniz-2.0.8 -I<torch root>/third_party/kineto/libkineto/include -I<torch root>/third_party/kineto/libkineto/src -I<torch root>/torch/csrc/distributed -I<torch root>/aten/src/TH -I<torch root>/aten/../third_party/catch/single_include -I<torch root>/aten/src/ATen/.. -I<torch root>/build/caffe2/aten/src/ATen -I<torch root>/caffe2/core/nomnigraph/include -I<torch root>/third_party/FXdiv/include -I<torch root>/c10/.. -I<torch root>/third_party/pthreadpool/include -I<torch root>/third_party/cpuinfo/include -I<torch root>/third_party/QNNPACK/include -I<torch root>/aten/src/ATen/native/quantized/cpu/qnnpack/include -I<torch root>/aten/src/ATen/native/quantized/cpu/qnnpack/src -I<torch root>/third_party/cpuinfo/deps/clog/include -I<torch root>/third_party/NNPACK/include -I<torch root>/third_party/fbgemm/include -I<torch root>/third_party/fbgemm -I<torch root>/third_party/fbgemm/third_party/asmjit/src -I<torch root>/third_party/FP16/include -I<torch root>/third_party/tensorpipe -I<torch root>/build/third_party/tensorpipe -I<torch root>/third_party/tensorpipe/third_party/libnop/include -I<torch root>/third_party/fmt/include -isystem <torch root>/build/third_party/gloo -isystem <torch root>/cmake/../third_party/gloo -isystem <torch root>/third_party/protobuf/src -isystem <torch root>/third_party/gemmlowp -isystem <torch root>/third_party/neon2sse -isystem <torch root>/third_party/XNNPACK/include -isystem <torch root>/third_party -isystem <torch root>/cmake/../third_party/eigen -isystem /usr/include/python3.9 -isystem /usr/local/lib/python3.9/dist-packages/numpy/core/include -isystem <torch root>/cmake/../third_party/pybind11/include -isystem /usr/include/x86_64-linux-gnu/mpich -isystem <torch root>/build/include -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp=libomp -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -Wno-invalid-partial-specialization -Wno-typedef-redefinition -Wno-unknown-warning-option -Wno-unused-private-field -Wno-inconsistent-missing-override -Wno-aligned-allocation-unavailable -Wno-c++14-extensions -Wno-constexpr-not-const -Wno-missing-braces -Qunused-arguments -fcolor-diagnostics -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Werror=cast-function-type -DHAVE_AVX512_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3 -DNDEBUG -DNDEBUG -fPIC -DCAFFE2_USE_GLOO -DHAVE_GCC_GET_CPUID -DUSE_AVX -DUSE_AVX2 -DTH_HAVE_THREAD -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-write-strings -Wno-unknown-pragmas -Wno-missing-braces -Wno-maybe-uninitialized -fvisibility=hidden -O2 -fopenmp=libomp -DCAFFE2_BUILD_MAIN_LIB -pthread -DASMJIT_STATIC -std=gnu++14 -Wno-deprecated-declarations -MD -MT caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp.o -MF caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp.o.d -o caffe2/CMakeFiles/torch_cpu.dir/__/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp.o -c '<torch root>/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp'
In file included from <torch root>/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp:1:
In file included from <torch root>/torch/csrc/distributed/c10d/ProcessGroupMPI.hpp:16:
In file included from <torch root>/torch/csrc/distributed/c10d/ProcessGroup.hpp:14:
<torch root>/torch/csrc/distributed/c10d/Utils.hpp:425:28: warning: comparison of integers of different signs: 'std::vector::size_type' (aka 'unsigned long') and 'int' [-Wsign-compare]
        split_sizes.size() == group_size,
        ~~~~~~~~~~~~~~~~~~ ^  ~~~~~~~~~~
<torch root>/c10/util/Exception.h:441:31: note: expanded from macro 'TORCH_CHECK'
  if (C10_UNLIKELY_OR_CONST(!(cond))) {            \
                              ^~~~
<torch root>/c10/util/Exception.h:261:47: note: expanded from macro 'C10_UNLIKELY_OR_CONST'
#define C10_UNLIKELY_OR_CONST(e) C10_UNLIKELY(e)
                                              ^
<torch root>/c10/macros/Macros.h:197:64: note: expanded from macro 'C10_UNLIKELY'
#define C10_UNLIKELY(expr) (__builtin_expect(static_cast<bool>(expr), 0))
                                                               ^~~~
<torch root>/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp:131:10: error: no member named 'cerr' in namespace 'std'
    std::cerr
```


## Environment

 - PyTorch Version (e.g., 1.0): N/A, building from commit https://github.com/pytorch/pytorch/commit/c78ab28441f5616899d363d57317f4de29147e5c
 - OS (e.g., Linux): Ubuntu 20.04
 - How you installed PyTorch (`conda`, `pip`, source): source
 - Build command you used (if compiling from source): 
 
 ```
export USE_CUDA=0
export USE_MKL_DNN=0
export BUILD_TEST=0
python ./setup.py bdist_wheel
 ```
 - Python version: 3.9.5
 - CUDA/cuDNN version: N/A
 - GPU models and configuration: N/A
 - Any other relevant information: we are building with `libstdc++-11-dev`
 
 Output of `collect_env.py`:
 
Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.2 LTS (x86_64)
GCC version: (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0
Clang version: Could not collect
CMake version: version 3.21.1
Libc version: glibc-2.31

Python version: 3.9.5 (default, May 19 2021, 11:32:47)  [GCC 9.3.0] (64-bit runtime)
Python platform: Linux-5.4.0-1047-azure-x86_64-with-glibc2.31
Is CUDA available: N/A
CUDA runtime version: Could not collect
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] numpy==1.21.2
[conda] Could not collect
 

## Additional context

Adding `#include <iostream>` to `<torch root>/torch/csrc/distributed/c10d/ProcessGroupMPI.cpp` is sufficient and verified on a local machine.


cc @malfet @seemethere