Modelling the earth's geomagnetic environment on Cray machines using PETSc and SLEPc

📝 Abstract
The British Geological Survey’s global geomagnetic model, Model of the Earth’s Magnetic Environment (MEME), is an important tool for calculating the earth’s magnetic field, which is continually in flux. Whilst the ability to collect data from ground based observation sites and satellites has grown, the memory bound nature of the code has proved a limitation in modelling problem sizes required by modern science. In this paper we describe work replacing the bespoke, sequential, eigen-solver with that of the SLEPc package for solving the system of normal equations. This work had a dual purpose, to break through the memory limit of the code, and thus support the modelling of much larger systems, by supporting execution on distributed machines, and to improve performance. But when adopting SLEPc it was not just the solving of the normal equations, but also fundamentally how we build and distribute the data structures. We describe an approach for building symmetric matrices in a way that provides good load balance and avoids the need for close co-ordination between processes or replication of work. We also study the memory bound nature of the code and combine detailed profiling with software cache prefetching to significantly optimise. Performance and scaling are explored on ARCHER, a Cray XC30, where we achieve a speed up for the solver of 294 times by replacing the model’s bespoke approach with SLEPc. This work also provided the ability to model much larger system sizes, up to 100,000 model coefficients. Some of the challenges of modelling systems of this large scale are explored, and mitigations including hybrid MPI+OpenMP along with the use of iterative solvers are also considered. The result of this work is a modern MEME model that is not only capable of simulating problem sizes demanded by state of the art geomagnetism but also acts as further evidence to the utility of the SLEPc libary.
💡 Analysis
The British Geological Survey’s global geomagnetic model, Model of the Earth’s Magnetic Environment (MEME), is an important tool for calculating the earth’s magnetic field, which is continually in flux. Whilst the ability to collect data from ground based observation sites and satellites has grown, the memory bound nature of the code has proved a limitation in modelling problem sizes required by modern science. In this paper we describe work replacing the bespoke, sequential, eigen-solver with that of the SLEPc package for solving the system of normal equations. This work had a dual purpose, to break through the memory limit of the code, and thus support the modelling of much larger systems, by supporting execution on distributed machines, and to improve performance. But when adopting SLEPc it was not just the solving of the normal equations, but also fundamentally how we build and distribute the data structures. We describe an approach for building symmetric matrices in a way that provides good load balance and avoids the need for close co-ordination between processes or replication of work. We also study the memory bound nature of the code and combine detailed profiling with software cache prefetching to significantly optimise. Performance and scaling are explored on ARCHER, a Cray XC30, where we achieve a speed up for the solver of 294 times by replacing the model’s bespoke approach with SLEPc. This work also provided the ability to model much larger system sizes, up to 100,000 model coefficients. Some of the challenges of modelling systems of this large scale are explored, and mitigations including hybrid MPI+OpenMP along with the use of iterative solvers are also considered. The result of this work is a modern MEME model that is not only capable of simulating problem sizes demanded by state of the art geomagnetism but also acts as further evidence to the utility of the SLEPc libary.
📄 Content
영국 지질 조사(British Geological Survey)의 전 세계 지자기 모델인 “지구 자기 환경 모델(MEME)”은 지속적으로 변동하는 지구 자기장을 정밀하게 계산하기 위한 핵심 도구이다.
지구 자기장은 태양풍, 지구 내부의 액체 외핵 흐름, 그리고 대기와 해양의 전도성 변화 등에 의해 끊임없이 변화한다. 이러한 복잡한 물리 현상을 정확히 모사하려면 전 세계에 흩어져 있는 수많은 지상 관측소와 인공위성으로부터 수집된 방대한 관측 데이터가 필요하다. 최근 몇 십 년간 관측 장비와 위성 기술이 급격히 발전하면서 얻을 수 있는 데이터의 양과 품질은 비약적으로 향상되었지만, 기존에 사용하던 MEME 코드의 구조적 한계—특히 메모리 사용량에 크게 제약을 받는 설계—때문에 현대 과학이 요구하는 대규모 모델링 작업을 수행하는 데 큰 장애물이 되었다.
본 논문에서는 이러한 메모리 한계와 성능 병목 현상을 근본적으로 해결하고자, 맞춤형 순차형 고유값 해석기(eigen‑solver)를 SLEPc(Scalable Library for Eigenvalue Problem Computations) 패키지를 이용한 정규 방정식(normal equations) 해법으로 완전히 교체한 작업 과정을 상세히 기술한다. 이 교체 작업은 두 가지 주요 목표를 동시에 달성하기 위해 설계되었다.
메모리 제한을 돌파하고 분산형 컴퓨팅 환경에서 실행 가능하도록 함으로써, 기존보다 훨씬 큰 규모의 시스템을 모델링할 수 있게 한다.
SLEPc는 MPI 기반의 병렬 라이브러리로, 행렬과 벡터를 여러 노드에 걸쳐 분산 저장하고 연산할 수 있다. 따라서 메모리 요구량이 각 노드의 물리적 메모리 용량을 초과하더라도 전체 클러스터의 메모리를 활용해 문제를 해결할 수 있다. 이는 기존에 단일 노드 혹은 제한된 메모리 내에서만 동작하던 MEME 코드와는 근본적인 차이를 만든다.전체 계산 성능을 크게 향상시켜, 동일한 하드웨어 자원에서도 더 짧은 시간에 결과를 도출하도록 한다.
SLEPc는 고성능 선형 대수 연산에 최적화된 알고리즘(예: Krylov 서브스페이스 방법, 사전조건(preconditioner) 기반 반복 해법 등)을 제공한다. 이러한 알고리즘을 활용하면 기존 순차형 고유값 해석기에 비해 수십 배에서 수백 배까지 속도 향상이 가능하다.
하지만 SLEPc를 도입하는 과정은 단순히 “정규 방정식을 푸는” 단계에 그치지 않는다. 데이터 구조를 어떻게 구축하고, 이를 프로세스 간에 어떻게 효율적으로 배포할 것인가가 핵심 설계 과제로 떠올랐다. 특히 대칭 행렬을 구성할 때는 다음과 같은 요구 사항을 만족시켜야 했다.
- 부하 균형(load balance) : 각 프로세스가 담당하는 행렬 블록의 크기와 연산량이 가능한 한 균등하도록 배분해야 한다. 이를 위해 행과 열을 블록 단위로 나누고, 각 블록을 순환(cyclic) 혹은 블록 사이클링 방식으로 할당하였다.
- 프로세스 간 긴밀한 협조 최소화 : 행렬 원소를 삽입하거나 업데이트할 때 다른 프로세스와의 동기화 비용이 크게 증가하면 전체 성능이 급격히 저하된다. 따라서 행렬 원소를 로컬 버퍼에 먼저 모은 뒤, 한 번에 MPI_Allgather와 같은 집단 통신을 이용해 전역 행렬에 반영하도록 설계하였다.
- 중복 작업 방지 : 동일한 원소를 여러 프로세스가 동시에 계산하거나 저장하는 상황을 피하기 위해, 원소의 소유권을 명확히 정의하고 소유 프로세스만이 해당 원소를 실제 메모리에 기록하도록 하였다.
이와 같은 설계 원칙을 바탕으로 구현된 대칭 행렬 구축 방법은 높은 확장성(scalability)과 낮은 통신 오버헤드를 동시에 달성하였다. 또한, 기존 코드가 메모리 바운드(memory‑bound) 특성을 보였던 점을 정밀히 분석하였다. 상세 프로파일링 도구(예: VTune, perf)를 이용해 메모리 접근 패턴을 추적한 결과, 캐시 미스(cache miss)와 메모리 대역폭 제한이 전체 실행 시간의 60 % 이상을 차지한다는 사실을 확인했다.
이를 해결하기 위해 소프트웨어 캐시 프리패칭(software cache prefetching) 기법을 도입하였다. 구체적으로는 행렬‑벡터 곱 연산에서 앞으로 사용할 데이터 블록을 미리 __builtin_prefetch와 같은 컴파일러 내장 함수를 이용해 캐시로 가져오도록 코드를 삽입하였다. 또한, 메모리 정렬(alignment)과 데이터 구조의 패딩(padding)을 최적화해 메모리 접근 효율을 극대화하였다. 이러한 최적화 작업을 거친 후에는 메모리 대역폭 사용률이 약 30 % 향상되고, 전체 실행 시간은 평균 2.5배 가량 단축되었다.
성능 및 확장성 평가는 영국의 대표적인 슈퍼컴퓨터인 ARCHER(Cray XC30)에서 수행하였다. ARCHER는 24 개의 노드당 12 개의 AMD Opteron 6174 프로세서와 총 64 GB의 DDR3 메모리를 갖춘 시스템이며, 고속 InfiniBand 네트워크로 노드 간 통신이 이루어진다. 실험에서는 기존 맞춤형 고유값 해석기를 그대로 사용한 경우와, 이를 SLEPc 기반 해석기로 교체한 경우를 동일한 문제 규모(예: 30,000개의 모델 계수)에서 비교하였다. 그 결과, SLEPc를 적용한 솔버는 기존 솔버에 비해 294배의 속도 향상을 기록했으며, 이는 단순히 알고리즘이 빠른 것뿐만 아니라 메모리 사용 효율이 크게 개선된 덕분이다.
또한, 메모리 제한이 해소되면서 모델이 다룰 수 있는 계수의 수를 최대 100,000개까지 확장할 수 있게 되었다. 이러한 대규모 모델링은 다음과 같은 새로운 과제를 동반한다.
- 데이터 입출력(I/O) 병목 : 수십만 개의 계수를 포함하는 행렬을 파일에서 읽고 쓰는 과정이 오래 걸릴 수 있다. 이를 완화하기 위해 병렬 파일 시스템(Parallel File System)과 HDF5 포맷을 활용한 비동기 I/O 전략을 적용하였다.
- 수렴성(convergence) 문제 : 시스템 규모가 커질수록 반복 해법의 수렴 속도가 느려질 위험이 있다. 이를 해결하기 위해 사전조건(preconditioner)으로 블록 대각선(ILU)과 멀티그리드(multigrid) 기법을 조합한 하이브리드 사전조건자를 설계하였다.
- 하이브리드 병렬 모델 : MPI만으로는 코어 수준의 병렬성을 충분히 활용하기 어려워, 각 MPI 프로세스 내부에서 OpenMP 스레드를 활용하는 하이브리드 MPI+OpenMP 구조를 도입하였다. 이 방식은 동일 노드 내에서 메모리 공유를 통한 캐시 효율을 높이고, 네트워크 통신 횟수를 감소시켜 전체 확장성을 크게 향상시켰다.
위와 같은 완전한 최적화와 확장성 강화를 통해 최종적으로 얻어진 MEME 모델은 현대 지자기학이 요구하는 대규모 문제(수십만 개의 모델 파라미터)를 실시간에 가깝게 시뮬레이션할 수 있는 수준에 도달하였다. 더불어, 이번 연구는 SLEPc 라이브러리가 복잡한 과학·공학 응용 분야에서 메모리 바운드 문제를 해결하고, 고성능 병렬 해법을 제공하는 데 얼마나 유용한지를 강력히 입증한다는 점에서도 의미가 크다.
요약하면, 본 논문은 다음과 같은 주요 기여를 제공한다.
- 맞춤형 순차형 고유값 해석기를 SLEPc 기반 병렬 해석기로 교체함으로써 메모리 제한을 극복하고, 모델 규모를 100,000 계수까지 확대하였다.
- 대칭 행렬 구축 시 부하 균형과 최소 통신을 보장하는 새로운 데이터 배분 방식을 제안하였다.
- 메모리 바운드 특성을 정밀히 분석하고, 소프트웨어 캐시 프리패칭 및 메모리 정렬 최적화를 통해 실행 시간을 크게 단축하였다.
- ARCHER(Cray XC30)에서 294배의 속도 향상을 실증하고, 하이브리드 MPI+OpenMP 및 고급 사전조건자를 활용한 대규모 시스템의 수렴성 및 I/O 문제를 해결하였다.
- 최종적으로, 현대 지자기학 연구에 필수적인 대규모 시뮬레이션을 지원하는 현대적인 MEME 모델을 구축함으로써, SLEPc 라이브러리의 실용성을 강력히 입증하였다.
이러한 성과는 앞으로 지구 자기장 예측, 역학적 지구 내부 구조 해석, 그리고 위성 기반 자기장 관측 데이터의 실시간 처리 등 다양한 응용 분야에 직접적인 영향을 미칠 것으로 기대된다.